cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r891440 - in /cxf/trunk/rt: databinding/aegis/src/main/java/org/apache/cxf/aegis/ databinding/aegis/src/main/java/org/apache/cxf/aegis/type/ databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ databinding/aegis/src/main/java/or...
Date Wed, 16 Dec 2009 21:48:49 GMT
Author: dkulp
Date: Wed Dec 16 21:48:48 2009
New Revision: 891440

URL: http://svn.apache.org/viewvc?rev=891440&view=rev
Log:
[CXF-2579] Add support for flattened collections to aegis

Added:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlFlattenedArray.java
      - copied, changed from r891393, cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/BeanWithFlatCollection.java
      - copied, changed from r891393, cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.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/basic/ArrayType.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/AnnotationReader.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayService.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Tags.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
Wed Dec 16 21:48:48 2009
@@ -87,7 +87,7 @@
                                 ArrayType arrayType, QName concreteName) throws Exception
{
         setupReaderPosition(input);
         ElementReader elReader = new ElementReader(input);
-        return arrayType.readObject(elReader, concreteName, context);
+        return arrayType.readObject(elReader, concreteName, context, true);
         
     }
 }

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=891440&r1=891439&r2=891440&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
Wed Dec 16 21:48:48 2009
@@ -257,7 +257,7 @@
         if (info.getMaxOccurs() != -1) {
             type.setMaxOccurs(info.getMaxOccurs());
         }
-
+        
         type.setFlat(info.isFlat());
 
         return type;

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
Wed Dec 16 21:48:48 2009
@@ -57,11 +57,15 @@
     public ArrayType() {
     }
     
-    public Object readObject(MessageReader reader, QName flatElementName, Context context)

+    public Object readObject(MessageReader reader, QName flatElementName,
+                             Context context, boolean asArray) 
         throws DatabindingException {
         try {
             Collection values = readCollection(reader, flatElementName, context);
-            return makeArray(getComponentType().getTypeClass(), values);
+            if (asArray) {
+                return makeArray(getComponentType().getTypeClass(), values);
+            }
+            return values;
         } catch (IllegalArgumentException e) {
             throw new DatabindingException("Illegal argument.", e);
         }
@@ -72,7 +76,7 @@
      */
     @Override
     public Object readObject(MessageReader reader, Context context) throws DatabindingException
{
-        return readObject(reader, null, context);
+        return readObject(reader, null, context, true);
     }
 
     protected Collection<Object> createCollection() {
@@ -222,6 +226,10 @@
         if (values == null) {
             return;
         }
+        if (values instanceof Collection) {
+            Collection c = (Collection)values;
+            values = c.toArray();
+        }
 
         AegisType type = getComponentType();
         if (type == null) {

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=891440&r1=891439&r2=891440&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
Wed Dec 16 21:48:48 2009
@@ -27,6 +27,7 @@
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -43,6 +44,7 @@
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAny;
@@ -164,7 +166,9 @@
                         Object writeObj;
                         if (type.isFlatArray()) {
                             ArrayType aType = (ArrayType) type;
-                            writeObj = aType.readObject(childReader, name, context);
+                            PropertyDescriptor desc = inf.getPropertyDescriptorFromMappedName(name);
+                            boolean isList =  List.class.isAssignableFrom(desc.getPropertyType());
+                            writeObj = aType.readObject(childReader, name, context, !isList);
                         } else {
                             writeObj = type.readObject(childReader, context);
                         }
@@ -272,7 +276,13 @@
                 if (getTypeClass().isInterface()) {
                     m = getWriteMethodFromImplClass(impl, desc);
                 }
-
+                if (m == null && property instanceof List) {
+                    m = desc.getReadMethod();
+                    List<Object> l = CastUtils.cast((List<?>)m.invoke(object));
+                    List<Object> p = CastUtils.cast((List<?>)property);
+                    l.addAll(p);
+                    return;
+                }
                 if (m == null) {
                     throw new DatabindingException("No write method for property " + name
+ " in "
                                                    + object.getClass());

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
Wed Dec 16 21:48:48 2009
@@ -372,4 +372,16 @@
         }
     }
 
+    public boolean isFlat(Annotation[] annotations) {
+        if (annotations != null) {
+            for (Annotation a : annotations) {
+                if (a instanceof XmlFlattenedArray) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+
 }

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=891440&r1=891439&r2=891440&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
Wed Dec 16 21:48:48 2009
@@ -121,7 +121,7 @@
         info.setType(genericType); // override basicClassInfo's of the type.
         info.setAnnotations(pd.getReadMethod().getAnnotations());
         info.setAegisTypeClass(castToAegisTypeClass(annotationReader.getType(pd.getReadMethod())));
-
+        info.setFlat(annotationReader.isFlat(pd.getReadMethod().getAnnotations()));
         return info;
     }
 

Copied: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlFlattenedArray.java
(from r891393, cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlFlattenedArray.java?p2=cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlFlattenedArray.java&p1=cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java&r1=891393&r2=891440&rev=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlFlattenedArray.java
Wed Dec 16 21:48:48 2009
@@ -16,14 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.aegis.type.array;
 
-public interface FlatArrayServiceInterface {
+package org.apache.cxf.aegis.type.java5;
 
-    String[] getStringArrayValue();
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 
-    void submitStringArray(String[] array);
-
-    void takeBeanWithFlatArray(BeanWithFlatArray bwfa);
+/**
+ * 
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface XmlFlattenedArray {
 
 }

Copied: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/BeanWithFlatCollection.java
(from r891393, cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/BeanWithFlatCollection.java?p2=cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/BeanWithFlatCollection.java&p1=cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java&r1=891393&r2=891440&rev=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/BeanWithFlatCollection.java
Wed Dec 16 21:48:48 2009
@@ -16,14 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.cxf.aegis.type.array;
 
-public interface FlatArrayServiceInterface {
+import java.util.ArrayList;
+import java.util.List;
 
-    String[] getStringArrayValue();
+import org.apache.cxf.aegis.type.java5.XmlFlattenedArray;
 
-    void submitStringArray(String[] array);
+/**
+ * Test bean for flat='true'
+ */
+public class BeanWithFlatCollection {
+    List<Integer> values = new ArrayList<Integer>();
 
-    void takeBeanWithFlatArray(BeanWithFlatArray bwfa);
+    @XmlFlattenedArray
+    public List<Integer> getValues() {
+        return values;
+    }
 
 }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayService.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayService.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayService.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayService.java
Wed Dec 16 21:48:48 2009
@@ -22,7 +22,8 @@
     
     String[] stringArrayValue;
     BeanWithFlatArray beanWithFlatArrayValue;
-
+    BeanWithFlatCollection beanWithFlatCollection;
+    
     public FlatArrayService() {
     }
     
@@ -40,4 +41,9 @@
     public void takeBeanWithFlatArray(BeanWithFlatArray bwfa) {
         beanWithFlatArrayValue = bwfa;
     }
+    
+    public BeanWithFlatCollection echoBeanWithFlatCollection(BeanWithFlatCollection c) {
+        beanWithFlatCollection = c;
+        return c;
+    }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayServiceInterface.java
Wed Dec 16 21:48:48 2009
@@ -25,5 +25,7 @@
     void submitStringArray(String[] array);
 
     void takeBeanWithFlatArray(BeanWithFlatArray bwfa);
-
+    
+    BeanWithFlatCollection echoBeanWithFlatCollection(BeanWithFlatCollection c);
 }
+

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java
Wed Dec 16 21:48:48 2009
@@ -110,5 +110,25 @@
         client.takeBeanWithFlatArray(bwfa);
         assertArrayEquals(INT_ARRAY, service.beanWithFlatArrayValue.getValues());
     }
+    @Test
+    public void testFlatCollection() throws Exception {
+        ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
+        proxyFac.setDataBinding(new AegisDatabinding());
+        proxyFac.setAddress("local://FlatArray");
+        proxyFac.setServiceClass(FlatArrayServiceInterface.class);
+        proxyFac.setBus(getBus());
+
+        Object proxyObj = proxyFac.create();
+        FlatArrayServiceInterface client = (FlatArrayServiceInterface)proxyObj;
+        BeanWithFlatCollection bwfc = new BeanWithFlatCollection();
+        bwfc.getValues().add(1);
+        bwfc.getValues().add(2);
+        bwfc.getValues().add(3);
+        bwfc = client.echoBeanWithFlatCollection(bwfc);
+        assertEquals(3, bwfc.getValues().size());
+        assertEquals(Integer.valueOf(1), bwfc.getValues().get(0));
+        assertEquals(Integer.valueOf(2), bwfc.getValues().get(1));
+        assertEquals(Integer.valueOf(3), bwfc.getValues().get(2));
+    }
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
Wed Dec 16 21:48:48 2009
@@ -25,6 +25,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.InvalidPropertiesFormatException;
@@ -45,7 +46,6 @@
 
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class AegisJSONProviderTest extends Assert {
@@ -261,12 +261,12 @@
     }
     
     @Test
-    @Ignore("Aegis copies duplicate ns1:tags elements into DOM which is exposed by a new
Jettison writer")
     public void testManyTags() throws Exception {
         AegisJSONProvider<ManyTags> p = new AegisJSONProvider<ManyTags>();
         p.setWriteXsiType(false);
         AbstractAegisProvider.clearContexts();
         p.setSerializeAsArray(true);
+        p.setArrayKeys(Arrays.asList("ns1.tags"));
         
         Tags tags = new Tags();
         tags.addTag(createTag("a", "b"));
@@ -277,13 +277,11 @@
         
         p.writeTo(many, ManyTags.class, ManyTags.class, ManyTags.class.getAnnotations(),

                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
-        
         String s = os.toString();
-        System.out.println(s);
-        String data1 = "{\"ns1.ManyTags\":[{\"ns1.tags\":[{\"ns1.TagVO\""
-            + ":{\"ns1.group\":\"b\",\"ns1.name\":\"a\"}}]}]}";
-        String data2 = "{\"ns1.ManyTags\":[{\"ns1.tags\":[{\"ns1.TagVO\""
-            + ":{\"ns1.name\":\"a\",\"ns1.group\":\"b\"}}]}]}";
+        String data1 = "{\"ns1.ManyTags\":{\"ns1.tags\":[{\"ns1.list\""
+            + ":{\"ns1.group\":\"b\",\"ns1.name\":\"a\"}}]}}";
+        String data2 = "{\"ns1.ManyTags\":{\"ns1.tags\":[{\"ns1.list\""
+            + ":{\"ns1.name\":\"a\",\"ns1.group\":\"b\"}}]}}";
         assertTrue(data1.equals(s) || data2.equals(s));
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Tags.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Tags.java?rev=891440&r1=891439&r2=891440&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Tags.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Tags.java Wed
Dec 16 21:48:48 2009
@@ -24,9 +24,10 @@
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.cxf.aegis.type.java5.XmlFlattenedArray;
+
 @XmlRootElement(name = "Tags")
 public class Tags {
-    @XmlElement
     private List<TagVO> list = new ArrayList<TagVO>();
     
     public Tags() {
@@ -41,6 +42,8 @@
         list.add(tag);
     }
     
+    @XmlFlattenedArray
+    @XmlElement(name = "list")
     public List<TagVO> getTags() {
         return list;
     }



Mime
View raw message