cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1408482 - in /cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type: TypeClassInfo.java java5/Java5TypeCreator.java
Date Mon, 12 Nov 2012 22:32:59 GMT
Author: dkulp
Date: Mon Nov 12 22:32:58 2012
New Revision: 1408482

URL: http://svn.apache.org/viewvc?rev=1408482&view=rev
Log:
[CXF-4605] More map things for aegis

Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeClassInfo.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeClassInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeClassInfo.java?rev=1408482&r1=1408481&r2=1408482&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeClassInfo.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeClassInfo.java
Mon Nov 12 22:32:58 2012
@@ -20,6 +20,7 @@
 package org.apache.cxf.aegis.type;
 
 import java.lang.reflect.Type;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 
@@ -53,6 +54,7 @@ import javax.xml.namespace.QName;
 public class TypeClassInfo {
     // The general reflection Type.
     private Type type;
+    private Map<String, Type> typeVars;
     private Object[] annotations;
 
     // for collection types we pull out the parameters for convenience.
@@ -110,6 +112,14 @@ public class TypeClassInfo {
     public void setType(Type type) {
         this.type = type;
     }
+    
+    public void setType(Type tp, Map<String, Type> vars) {
+        this.type = tp;
+        this.typeVars = vars;
+    }
+    public Map<String, Type> getTypeVars() {
+        return typeVars;
+    }
 
     public QName getTypeName() {
         return typeName;

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java?rev=1408482&r1=1408481&r2=1408482&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
Mon Nov 12 22:32:58 2012
@@ -22,8 +22,10 @@ import java.beans.PropertyDescriptor;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.lang.reflect.WildcardType;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -140,19 +142,30 @@ public class Java5TypeCreator extends Ab
 
     // should be called 'collection'
     protected AegisType getOrCreateGenericType(TypeClassInfo info) {
-        return getOrCreateParameterizedType(info.getType(), 0);
+        return getOrCreateParameterizedType(info, 0, false);
     }
 
     protected AegisType getOrCreateMapKeyType(TypeClassInfo info) {
-        return getOrCreateParameterizedType(info.getType(), 0);
+        return getOrCreateParameterizedType(info, 0, true);
     }
 
     protected AegisType getOrCreateMapValueType(TypeClassInfo info) {
-        return getOrCreateParameterizedType(info.getType(), 1);
+        return getOrCreateParameterizedType(info, 1, true);
     }
 
-    protected AegisType getOrCreateParameterizedType(Type generic, int index) {
-        Type paramType = getComponentType(generic, index);
+    protected AegisType getOrCreateParameterizedType(TypeClassInfo generic, int index, boolean
map) {
+        Type paramType;
+        Map<String, Type> pm = generic.getTypeVars();
+        if (map) {
+            if (pm == null) {
+                pm = new HashMap<String, Type>();
+            } else {
+                pm = new HashMap<String, Type>(pm);
+            }
+            paramType = getComponentTypeForMap(generic.getType(), pm, index == 0);
+        } else {
+            paramType = getComponentType(generic.getType(), index);
+        }
 
         if (paramType == null) {
             return createObjectType();
@@ -173,7 +186,7 @@ public class Java5TypeCreator extends Ab
         
         TypeClassInfo info = createBasicClassInfo(clazz);
         info.setDescription(clazz.toString());
-        info.setType(paramType); 
+        info.setType(paramType, paramType instanceof ParameterizedType ? pm : null); 
 
         AegisType type = createTypeForClass(info);
 
@@ -197,6 +210,58 @@ public class Java5TypeCreator extends Ab
         }
     }
 
+    protected Type getComponentTypeForMap(Type genericType, Map<String, Type> pm, boolean
key) {
+        if (pm == null) {
+            pm = new HashMap<String, Type>();
+        }
+        return findMapGenericTypes(genericType, pm, key);
+    }
+    
+    
+    private Type findMapGenericTypes(Type cls, Map<String, Type> pm, boolean key) {
+        if (cls == null) {
+            return null;
+        }
+        if (cls instanceof ParameterizedType) {
+            ParameterizedType pt = (ParameterizedType)cls;
+            Type types[] = pt.getActualTypeArguments();
+            TypeVariable<?>[] params = ((Class<?>)pt.getRawType()).getTypeParameters();
+            for (int x = 0; x < types.length; x++) {
+                Type type = types[x];
+                if (type instanceof TypeVariable) {
+                    TypeVariable<?> tv = (TypeVariable<?>)types[x];
+                    if (pm.containsKey(tv.getName())) {
+                        type = pm.get(tv.getName());
+                        types[x] = type;
+                    }
+                }
+                pm.put(params[x].getName(), type);
+            }
+            if (Map.class.equals(pt.getRawType())) {
+                return types[key ? 0 : 1];
+            }
+            return findMapGenericTypes((Class<?>)pt.getRawType(), pm, key);
+        } else if (cls instanceof Class) {
+            Class<?> c = (Class<?>)cls;
+            if (Map.class.isAssignableFrom(c)) {
+                
+                for (Type tp : c.getGenericInterfaces()) {
+                    Map<String, Type> cp = new HashMap<String, Type>(pm);
+
+                    Type types = findMapGenericTypes(tp, cp, key);
+                    if (types != null) {
+                        pm.putAll(cp);
+                        return types;
+                    }
+                }
+                if (c.getSuperclass() != null && Map.class.isAssignableFrom(c.getSuperclass()))
{
+                    return findMapGenericTypes(c.getGenericSuperclass(), pm, key);
+                }
+            } 
+        }
+        return null;
+    }    
+
     @Override
     public AegisType createDefaultType(TypeClassInfo info) {
         QName typeName = info.getTypeName();



Mime
View raw message