cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r806602 - in /cxf/trunk/rt: databinding/aegis/src/main/java/org/apache/cxf/aegis/ databinding/aegis/src/main/java/org/apache/cxf/aegis/type/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ frontend/jaxrs/src/test/java/org/apache...
Date Fri, 21 Aug 2009 15:34:30 GMT
Author: bimargulies
Date: Fri Aug 21 15:34:27 2009
New Revision: 806602

URL: http://svn.apache.org/viewvc?rev=806602&view=rev
Log:
Merge branch 'benson' into trunk

Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
Fri Aug 21 15:34:27 2009
@@ -39,7 +39,7 @@
     }
     
     /**
-     * Write an object to the output.
+     * Write an object to the output. This method always writes xsi:type attributes.
      * @param obj The object to write.
      * @param elementName the QName of the XML Element.
      * @param optional set this for minOccurs = 0. It omits null elements.
@@ -58,7 +58,7 @@
             throw new DatabindingException(message);
         }
         
-        if (obj != null) {
+        if (obj != null && aegisType == null) {
             aegisType = TypeUtil.getWriteType(aegisContext, obj, aegisType);
         }
         
@@ -77,6 +77,10 @@
         
         ElementWriter writer = new ElementWriter(output);
         MessageWriter w2 = writer.getElementWriter(elementName);
+        if (aegisType != null && aegisType.getSchemaType() != null) {
+            // if we know the type, write it. We are standalone, and the reader needs it.
+            w2.writeXsiType(aegisType.getSchemaType());
+        }
         aegisType.writeObject(obj, w2, context);
         w2.close();
     }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
Fri Aug 21 15:34:27 2009
@@ -21,6 +21,7 @@
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
 import java.util.Collection;
 import java.util.Map;
 
@@ -90,7 +91,7 @@
         info.setDescription("field " + f.getName() + " in  " + f.getDeclaringClass());
         return info;
     }
-
+    
     public TypeClassInfo createBasicClassInfo(Class typeClass) {
         TypeClassInfo info = new TypeClassInfo();
         info.setDescription("class '" + typeClass.getName() + '\'');
@@ -393,6 +394,29 @@
         info.setDescription("field " + f.getName() + " in " + f.getDeclaringClass());
         return createTypeForClass(info);
     }
+    
+    /**
+     * Create an Aegis type from a reflected type description.
+     * This will only work for the restricted set of collection
+     * types supported by Aegis. 
+     * @param t the reflected type.
+     * @return the type
+     */
+    public Type createType(java.lang.reflect.Type t) {
+        TypeClassInfo info = new TypeClassInfo();
+        info.setGenericType(t);
+        if (t instanceof ParameterizedType) {
+            ParameterizedType pt = (ParameterizedType) t;
+            java.lang.reflect.Type rawType = pt.getRawType();
+            if (rawType instanceof Class) {
+                info.setTypeClass((Class)rawType);
+            }
+        }
+        
+        info.setDescription("reflected type " + t.toString());
+        return createTypeForClass(info);
+        
+    }
 
     public Type createType(Class clazz) {
         TypeClassInfo info = createBasicClassInfo(clazz);

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
Fri Aug 21 15:34:27 2009
@@ -42,6 +42,8 @@
     Type createType(Method m, int index);
 
     Type createType(PropertyDescriptor pd);
+    
+    Type createType(java.lang.reflect.Type type);
 
     Type createType(Field f);
 

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java Fri
Aug 21 15:34:27 2009
@@ -157,6 +157,26 @@
         return type;
     }
     
+    /**
+     * Allow writing of collections when the type of the collection object is known via
+     * an {@link java.lang.reflect.Type} object.
+     * @param globalContext the context
+     * @param value the object to write.
+     * @param reflectType the type to use in writing the object.
+     * @return
+     */
+    public static Type getWriteTypeStandalone(AegisContext globalContext, 
+                                              Object value, 
+                                              java.lang.reflect.Type reflectType) {
+        if (reflectType == null) {
+            return getWriteTypeStandalone(globalContext, value, (Type)null);
+        } else {
+            return globalContext.getTypeMapping().getTypeCreator().createType(reflectType);
+        }
+        
+        
+    }
+    
     
     public static void setAttributeAttributes(QName name, Type type, XmlSchema root) {
         String ns = type.getSchemaType().getNamespaceURI();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
Fri Aug 21 15:34:27 2009
@@ -114,6 +114,13 @@
                 }
                 context.setRootClasses(rootClasses);
                 context.initialize();
+                /* It's not enough, in the presence of generic types, to just add it as a
root.
+                    a mapping is also needed */
+                if (genericType != null) {
+                    org.apache.cxf.aegis.type.Type aegisType;
+                    aegisType = context.getTypeMapping().getTypeCreator().createType(genericType);
+                    context.getTypeMapping().register(aegisType);
+                }
                 classContexts.put(type, context);
             }
             return context;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
Fri Aug 21 15:34:27 2009
@@ -70,7 +70,9 @@
             type = obj.getClass();
         }
         AegisContext context = getAegisContext(type, genericType);
-        org.apache.cxf.aegis.type.Type aegisType = TypeUtil.getWriteTypeStandalone(context,
obj, null);
+        // we need special cases for collection types.
+        
+        org.apache.cxf.aegis.type.Type aegisType = TypeUtil.getWriteTypeStandalone(context,
obj, genericType);
         AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
         try {
             XMLStreamWriter xmlStreamWriter = createStreamWriter(type, os);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java?rev=806602&r1=806601&r2=806602&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Fri Aug 21 15:34:27 2009
@@ -43,7 +43,7 @@
             + "xmlns:ns2=\"http://www.w3.org/2001/XMLSchema-instance\" ns2:type=\"ns1:AegisTestBean\">"
             + "<ns1:boolValue>true</ns1:boolValue><ns1:strValue>hovercraft</ns1:strValue>"
             + "</ns1:AegisTestBean>";
-    
+
     @After
     public void clearCache() {
         AbstractAegisProvider.clearContexts();
@@ -91,29 +91,32 @@
         Map<AegisTestBean, String> mapFunction();
     }
     
+    
+    
     @SuppressWarnings("unchecked")
     @Test
-    @org.junit.Ignore
     public void testReadWriteComplexMap() throws Exception {
-        Map<AegisTestBean, String> map = new HashMap<AegisTestBean, String>();
+        Map<AegisTestBean, String> testMap = new HashMap<AegisTestBean, String>();
+        
+        Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
+        Method method = iwithMapClass.getMethod("mapFunction");
+        Type mapType = method.getGenericReturnType();
+
         AegisTestBean bean = new AegisTestBean();
         bean.setBoolValue(Boolean.TRUE);
         bean.setStrValue("hovercraft");
-        map.put(bean, "hovercraft");
+        testMap.put(bean, "hovercraft");
         
         MessageBodyWriter<Object> writer = new AegisElementProvider();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         
-        writer.writeTo(bean, null, null, null, null, null, os);
+        writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
         byte[] bytes = os.toByteArray();
         String xml = new String(bytes, "utf-8");
                 
         MessageBodyReader<Object> reader = new AegisElementProvider();         
         byte[] simpleBytes = xml.getBytes("utf-8");
         
-        Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
-        Method method = iwithMapClass.getMethod("mapFunction");
-        Type mapType = method.getGenericReturnType();
         
         Object beanObject = reader.readFrom((Class)Map.class, mapType, null, 
                                           null, null, new ByteArrayInputStream(simpleBytes));



Mime
View raw message