cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r811177 - in /cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type: AegisType.java DefaultTypeMapping.java TypeMapping.java basic/BeanType.java java5/EnumType.java
Date Fri, 04 Sep 2009 00:02:43 GMT
Author: bimargulies
Date: Fri Sep  4 00:02:42 2009
New Revision: 811177

URL: http://svn.apache.org/viewvc?rev=811177&view=rev
Log:
Make the Aegis type mapping work in terms of Type instead of Class so that it can keep multiple
generics straight.

Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AegisType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AegisType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AegisType.java?rev=811177&r1=811176&r2=811177&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AegisType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AegisType.java
Fri Sep  4 00:02:42 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.aegis.type;
 
+import java.lang.reflect.Type;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -36,7 +37,7 @@
  */
 public abstract class AegisType {
 
-    protected Class typeClass;
+    protected Type typeClass;
     private QName schemaType;
     private TypeMapping typeMapping;
     private boolean abstrct = true;
@@ -99,20 +100,35 @@
     }
 
     /**
-     * @return Returns the typeClass.
+     * @return Returns the java type as a Class. If the type is not a 
+     * plain class, return null.
      */
     public Class getTypeClass() {
+        if (typeClass instanceof Class) {
+            return (Class)typeClass;
+        } else {
+            return null;
+        }
+    }
+    
+    /**
+     * @return Return the Java type.
+     */
+    public Type getType() {
         return typeClass;
     }
 
     /**
      * @param typeClass The typeClass to set.
      */
-    public void setTypeClass(Class typeClass) {
+    public void setTypeClass(Type typeClass) {
         this.typeClass = typeClass;
 
-        if (typeClass.isPrimitive()) {
-            setNillable(false);
+        if (typeClass instanceof Class) {
+            Class<?> plainClass = (Class<?>) typeClass;
+            if (plainClass.isPrimitive()) {
+                setNillable(false);
+            }
         }
     }
 
@@ -243,8 +259,13 @@
     public String toString() {
         StringBuffer sb = new StringBuffer(getClass().getName());
         sb.append("[class=");
-        Class c = getTypeClass();
-        sb.append((c == null) ? "<null>" : c.getName());
+        Type c = getTypeClass();
+        if (c instanceof Class) {
+            Class<?> plainClass = (Class<?>)c;
+            sb.append(plainClass.getName());
+        } else {
+            sb.append("<generic or null>");
+        }
         sb.append(",\nQName=");
         QName q = getSchemaType();
         sb.append((q == null) ? "<null>" : q.toString());

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java?rev=811177&r1=811176&r2=811177&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
Fri Sep  4 00:02:42 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.aegis.type;
 
+import java.lang.reflect.Type;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.URI;
@@ -73,14 +74,16 @@
 import org.apache.cxf.common.util.XMLSchemaQNames;
 
 /**
- * Contains type mappings for java/qname pairs.
+ * The implementation of the Aegis type map. It maintains a map from
+ * Java types {@link java.lang.reflect.Type} and AegisType objects,
+ * also indexed by the XML Schema QName of each type.
  */
 public class DefaultTypeMapping implements TypeMapping {
     public  static final String DEFAULT_MAPPING_URI = "urn:org.apache.cxf.aegis.types";
     private static final Logger LOG = LogUtils.getL7dLogger(DefaultTypeMapping.class);
-    private Map<Class, AegisType> class2Type;
+    private Map<Type, AegisType> class2Type;
     private Map<QName, AegisType> xml2Type;
-    private Map<Class, QName> class2xml;
+    private Map<Type, QName> class2xml;
     private TypeMapping nextTM;
     private TypeCreator typeCreator;
     private String identifierURI;
@@ -97,12 +100,12 @@
 
     public DefaultTypeMapping(String identifierURI) {
         this.identifierURI = identifierURI;
-        class2Type = Collections.synchronizedMap(new HashMap<Class, AegisType>());
-        class2xml = Collections.synchronizedMap(new HashMap<Class, QName>());
+        class2Type = Collections.synchronizedMap(new HashMap<Type, AegisType>());
+        class2xml = Collections.synchronizedMap(new HashMap<Type, QName>());
         xml2Type = Collections.synchronizedMap(new HashMap<QName, AegisType>());
     }
 
-    public boolean isRegistered(Class javaType) {
+    public boolean isRegistered(Type javaType) {
         boolean registered = class2Type.containsKey(javaType);
 
         if (!registered && nextTM != null) {
@@ -122,7 +125,7 @@
         return registered;
     }
 
-    public void register(Class javaType, QName xmlType, AegisType type) {
+    public void register(Type javaType, QName xmlType, AegisType type) {
         type.setSchemaType(xmlType);
         type.setTypeClass(javaType);
 
@@ -162,10 +165,7 @@
         }
     }
 
-    /**
-     * @see org.apache.cxf.aegis.type.TypeMapping#getType(java.lang.Class)
-     */
-    public AegisType getType(Class javaType) {
+    public AegisType getType(Type javaType) {
         AegisType type = class2Type.get(javaType);
 
         if (type == null && nextTM != null) {
@@ -175,9 +175,6 @@
         return type;
     }
 
-    /**
-     * @see org.apache.cxf.aegis.type.TypeMapping#getType(javax.xml.namespace.QName)
-     */
     public AegisType getType(QName xmlType) {
         AegisType type = xml2Type.get(xmlType);
 
@@ -188,10 +185,7 @@
         return type;
     }
 
-    /**
-     * @see org.apache.cxf.aegis.type.TypeMapping#getTypeQName(java.lang.Class)
-     */
-    public QName getTypeQName(Class clazz) {
+    public QName getTypeQName(Type clazz) {
         QName qname = class2xml.get(clazz);
 
         if (qname == null && nextTM != null) {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java?rev=811177&r1=811176&r2=811177&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
Fri Sep  4 00:02:42 2009
@@ -18,11 +18,13 @@
  */
 package org.apache.cxf.aegis.type;
 
+import java.lang.reflect.Type;
+
 import javax.xml.namespace.QName;
 
 /**
- * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
- * @since Feb 18, 2004
+ * Abstraction for the map between Java types (represented as 
+ * {@link java.lang.reflect.Type} and Aegis types.
  */
 public interface TypeMapping {
     /**
@@ -30,7 +32,7 @@
      * @param javaType the class.
      * @return <code>true</code> if there is a mapping for the type.
      */
-    boolean isRegistered(Class javaType);
+    boolean isRegistered(Type javaType);
 
     /**
      * Returns a flag indicating if this type mapping has a mapping for a particular
@@ -48,7 +50,7 @@
      * @param xmlType XML Schema type QName.
      * @param type Aegis type object.
      */
-    void register(Class javaType, QName xmlType, AegisType type);
+    void register(Type javaType, QName xmlType, AegisType type);
 
     /**
      * Register a type that self-describes the schema type and the Java class.
@@ -58,11 +60,11 @@
 
     void removeType(AegisType type);
 
-    AegisType getType(Class javaType);
+    AegisType getType(Type javaType);
 
     AegisType getType(QName xmlType);
 
-    QName getTypeQName(Class clazz);
+    QName getTypeQName(Type clazz);
 
     TypeCreator getTypeCreator();
     

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java?rev=811177&r1=811176&r2=811177&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
Fri Sep  4 00:02:42 2009
@@ -25,6 +25,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -88,8 +89,10 @@
     }
 
     private void initTypeClass() {
-        this.isInterface = typeClass.isInterface();
-        isException = Exception.class.isAssignableFrom(typeClass);
+        // throw if someone tries to set up a generic bean.
+        Class<?> plainClass = (Class<?>) typeClass;
+        this.isInterface = plainClass.isInterface();
+        isException = Exception.class.isAssignableFrom(plainClass);
     }
 
     /**
@@ -478,7 +481,7 @@
      * {@inheritDoc}
      */
     @Override
-    public void setTypeClass(Class typeClass) {
+    public void setTypeClass(Type typeClass) {
         super.setTypeClass(typeClass);
 
         initTypeClass();

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java?rev=811177&r1=811176&r2=811177&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
Fri Sep  4 00:02:42 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.aegis.type.java5;
 
+import java.lang.reflect.Type;
+
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.type.AegisType;
@@ -46,9 +48,14 @@
     }
 
     @Override
-    public void setTypeClass(Class typeClass) {
-        if (!typeClass.isEnum()) {
-            throw new DatabindingException("AegisType class must be an enum.");
+    public void setTypeClass(Type typeClass) {
+        if (!(typeClass instanceof Class)) {
+            throw new DatabindingException("Aegis cannot map generic Enums.");
+        }
+        
+        Class<?> plainClass = (Class<?>)typeClass;
+        if (!plainClass.isEnum()) {
+            throw new DatabindingException("EnumType must map an enum.");
         }
 
         super.setTypeClass(typeClass);



Mime
View raw message