cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r808477 - in /cxf/branches/2.2.x-fixes: ./ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jax...
Date Thu, 27 Aug 2009 16:05:33 GMT
Author: dkulp
Date: Thu Aug 27 16:05:30 2009
New Revision: 808477

URL: http://svn.apache.org/viewvc?rev=808477&view=rev
Log:
Merged revisions 806602 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r806602 | bimargulies | 2009-08-21 11:34:27 -0400 (Fri, 21 Aug 2009) | 1 line
  
  Merge branch 'benson' into trunk
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 27 16:05:30 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
Thu Aug 27 16:05:30 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/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
Thu Aug 27 16:05:30 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/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
Thu Aug 27 16:05:30 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/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
Thu Aug 27 16:05:30 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
Thu Aug 27 16:05:30 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
Thu Aug 27 16:05:30 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java?rev=808477&r1=808476&r2=808477&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Thu Aug 27 16:05:30 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