cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1053116 - in /cxf/branches/2.3.x-fixes: ./ rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ rt/frontend/jaxrs/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/xsd/ rt/frontend/jaxrs/s...
Date Mon, 27 Dec 2010 17:50:02 GMT
Author: sergeyb
Date: Mon Dec 27 17:50:02 2010
New Revision: 1053116

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

........
  r1053114 | sergeyb | 2010-12-27 17:46:13 +0000 (Mon, 27 Dec 2010) | 1 line
  
  [CXF-2626] Adding DataBindingProvider and XmlBeansDataBinding tests
........

Added:
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/xsd/
      - copied from r1053114, cxf/trunk/rt/frontend/jaxrs/src/test/xsd/
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/xsd/xmlbeans/
      - copied from r1053114, cxf/trunk/rt/frontend/jaxrs/src/test/xsd/xmlbeans/
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/xsd/xmlbeans/XmlBeanTest.xsd
      - copied unchanged from r1053114, cxf/trunk/rt/frontend/jaxrs/src/test/xsd/xmlbeans/XmlBeanTest.xsd
Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
    cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/pom.xml
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Dec 27 17:50:02 2010
@@ -1 +1 @@
-/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724,1042805,1042821,1043225,1043229,1043902,1043907,1043954,1044085,1044238-1044305,1045024,1048915,1048919,1048930,1049078,1049426,1049937,1050005,1050021,1050095,1050102,1050113,1050156,1050165,1050280,1051115,1051613,1051790,1051792,1052338,1052516,1052541,1052993-1052994,1052996-1052997
+/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724,1042805,1042821,1043225,1043229,1043902,1043907,1043954,1044085,1044238-1044305,1045024,1048915,1048919,1048930,1049078,1049426,1049937,1050005,1050021,1050095,1050102,1050113,1050156,1050165,1050280,1051115,1051613,1051790,1051792,1052338,1052516,1052541,1052993-1052994,1052996-1052997,1053114

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

Modified: cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java?rev=1053116&r1=1053115&r2=1053116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
Mon Dec 27 17:50:02 2010
@@ -19,7 +19,9 @@
 
 package org.apache.cxf.xmlbeans;
 
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.Collection;
 import java.util.logging.Logger;
 
@@ -58,6 +60,34 @@ public class DataReaderImpl implements D
             typeClass = (Class<?>)part.getProperty(XmlAnySimpleType.class.getName());
             unwrap = true;
         }
+        return doRead(reader,
+                      part.getTypeClass(), 
+                      typeClass, 
+                      (SchemaType)part.getProperty(SchemaType.class.getName()), 
+                      unwrap);
+    }
+
+    public Object read(QName name, XMLStreamReader reader, Class typeClass) {
+        SchemaType st = null;
+        try {
+            Field f = typeClass.getField("type");
+            if (Modifier.isStatic(f.getModifiers())) {
+                st = (SchemaType)f.get(null);
+            }
+        } catch (Exception es) {
+            es.printStackTrace();
+            return null;
+        }
+        
+        return doRead(reader,
+                      typeClass, 
+                      typeClass, 
+                      st, 
+                      false);
+    }
+
+    private Object doRead(XMLStreamReader reader, Class<?> partTypeClass, 
+                          Class<?> typeClass, SchemaType st, boolean unwrap) {
         boolean isOutClass = false;
         Class<?> encClass = typeClass.getEnclosingClass();
         if (encClass != null) {
@@ -69,8 +99,6 @@ public class DataReaderImpl implements D
         for (Class<?> c : cls) {
             if ("Factory".equals(c.getSimpleName())) {
                 try {
-                    
-                    SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
                     XmlOptions options = new XmlOptions();
                     if (validate) {
                         options.setValidateOnSet();
@@ -82,13 +110,13 @@ public class DataReaderImpl implements D
                     obj = meth.invoke(null, reader, options);                    
                     break;
                 } catch (Exception e) {
-                    throw new Fault(new Message("UNMARSHAL_ERROR", LOG, part.getTypeClass()),
e);
+                    throw new Fault(new Message("UNMARSHAL_ERROR", LOG, partTypeClass, e));
                 }
             }
         }
         if (unwrap && obj != null) {
             try {
-                Class<?> tc = part.getTypeClass(); 
+                Class<?> tc = partTypeClass; 
                 String methName;
                 if (tc.equals(Integer.TYPE) || tc.equals(Integer.class)) {
                     methName = "getIntValue";
@@ -108,7 +136,7 @@ public class DataReaderImpl implements D
             for (Method m : encClass.getDeclaredMethods()) {
                 if (m.getName().startsWith("get")
                     && m.getParameterTypes().length == 0
-                    && m.getReturnType().equals(part.getTypeClass())) {
+                    && m.getReturnType().equals(partTypeClass)) {
                     try {
                         obj = m.invoke(obj);
                     } catch (Exception e) {
@@ -126,11 +154,6 @@ public class DataReaderImpl implements D
         }
         return obj;
     }
-
-    public Object read(QName name, XMLStreamReader input, Class type) {        
-        return null;
-    }
-
     
     public void setAttachments(Collection<Attachment> attachments) {
     }

Modified: cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=1053116&r1=1053115&r2=1053116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
Mon Dec 27 17:50:02 2010
@@ -26,6 +26,7 @@ import java.lang.reflect.Modifier;
 import java.util.Collection;
 import java.util.logging.Logger;
 
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
@@ -70,7 +71,7 @@ public class DataWriterImpl implements D
     
     public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
         try {
-            Class<?> typeClass = part.getTypeClass();
+            Class<?> typeClass = part != null ? part.getTypeClass() : null;
             if (typeClass == null) {
                 typeClass = obj.getClass();
             }
@@ -158,7 +159,9 @@ public class DataWriterImpl implements D
                         Field f = typeClass.getField("type");
                         if (Modifier.isStatic(f.getModifiers())) {
                             st = (SchemaType)f.get(null);
-                            part.setProperty(SchemaType.class.getName(), st);
+                            if (part != null) {
+                                part.setProperty(SchemaType.class.getName(), st);
+                            }
                         }
                     } catch (Exception es) {
                         //ignore
@@ -172,20 +175,23 @@ public class DataWriterImpl implements D
                 
                 if (st != null && !st.isDocumentType()
                     || reader.getEventType() == XMLStreamReader.CHARACTERS) {
-                    if (StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
-                        output.writeStartElement(part.getConcreteName().getLocalPart());
+                    
+                    QName elementName = part != null ? part.getConcreteName() : st.getName();
+                    
+                    if (StringUtils.isEmpty(elementName.getNamespaceURI())) {
+                        output.writeStartElement(elementName.getLocalPart());
                         
                     } else {
-                        String pfx = output.getPrefix(part.getConcreteName().getNamespaceURI());
+                        String pfx = output.getPrefix(elementName.getNamespaceURI());
                         if (StringUtils.isEmpty(pfx)) {
                             output.writeStartElement("tns",
-                                             part.getConcreteName().getLocalPart(),
-                                             part.getConcreteName().getNamespaceURI());
-                            output.writeNamespace("tns", part.getConcreteName().getNamespaceURI());
+                                                     elementName.getLocalPart(),
+                                                     elementName.getNamespaceURI());
+                            output.writeNamespace("tns", elementName.getNamespaceURI());
                         } else {
                             output.writeStartElement(pfx,
-                                                     part.getConcreteName().getLocalPart(),
-                                                     part.getConcreteName().getNamespaceURI());
+                                                     elementName.getLocalPart(),
+                                                     elementName.getNamespaceURI());
                         }
                     }
                     StaxUtils.copy(reader, output, true);

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/pom.xml?rev=1053116&r1=1053115&r2=1053116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/pom.xml (original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/pom.xml Mon Dec 27 17:50:02 2010
@@ -161,9 +161,38 @@
             <artifactId>xmlbeans</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-databinding-xmlbeans</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.easymock</groupId>
             <artifactId>easymockclassextension</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>xmlbeans-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>xmlbeans-test</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <schemaDirectory>src/test/xsd/xmlbeans</schemaDirectory>
+                    <sourceGenerationDirectory>${project.build.directory}/generated/src/test/java</sourceGenerationDirectory>
+                    <classGenerationDirectory>${project.build.directory}/generated/src/test/resources</classGenerationDirectory>
+                    <!--noJavac>true</noJavac-->
+                    <javaSource>1.5</javaSource>
+                </configuration>
+            </plugin>
+            
+        </plugins>
+    </build>
 </project>

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java?rev=1053116&r1=1053115&r2=1053116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
Mon Dec 27 17:50:02 2010
@@ -40,12 +40,14 @@ import org.apache.cxf.jaxb.JAXBDataBindi
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.providers.xmlbeans.types.Address;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.sdo.Structure;
 import org.apache.cxf.jaxrs.resources.sdo.impl.StructureImpl;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.sdo.SDODataBinding;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.xmlbeans.XmlBeansDataBinding;
 
 import org.junit.Assert;
 import org.junit.Before;
@@ -56,12 +58,14 @@ public class DataBindingProviderTest ext
 
     private ClassResourceInfo c;
     private ClassResourceInfo c2;
+    private ClassResourceInfo c3;
     private Properties properties;
     
     @Before
     public void setUp() throws InvalidPropertiesFormatException, IOException {
         c = ResourceUtils.createClassResourceInfo(TheBooks.class, TheBooks.class, true, true);
         c2 = ResourceUtils.createClassResourceInfo(TheSDOBooks.class, TheSDOBooks.class,
true, true);
+        c3 = ResourceUtils.createClassResourceInfo(TheSDOBooks.class, TheSDOBooks.class,
true, true);
         properties = new Properties();
         properties.loadFromXML(getClass().getResourceAsStream("jsonCases.xml"));
     }
@@ -176,6 +180,40 @@ public class DataBindingProviderTest ext
         assertEquals(3, struct.getInt());
     }
     
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testXmlBeansWrite() throws Exception {
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c3), true);
+        DataBinding binding = new XmlBeansDataBinding();
+        binding.initialize(s);
+        DataBindingProvider p = new DataBindingProvider(binding);
+        Address address = Address.Factory.newInstance();
+        address.setAddressLine1("Street 1");
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        p.writeTo(address, Address.class, Address.class,
+            new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(),
bos);
+        String data = "<tns:Address xmlns:tns=\"http://cxf.apache.org/jaxrs/providers/xmlbeans/types\">"
+            + "<addressLine1>Street 1</addressLine1></tns:Address>";
+        assertEquals(bos.toString(), data);
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testXmlBeansRead() throws Exception {
+        String data = "<tns:Address xmlns:tns=\"http://cxf.apache.org/jaxrs/providers/xmlbeans/types\">"
+            + "<addressLine1>Street 1</addressLine1></tns:Address>";
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c3), true);
+        DataBinding binding = new XmlBeansDataBinding();
+        binding.initialize(s);
+        DataBindingProvider p = new DataBindingProvider(binding);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Address address = (Address)p.readFrom((Class)Address.class, Address.class,
+                                      new Annotation[0], MediaType.APPLICATION_XML_TYPE,

+                                      new MetadataMap<String, String>(), is);
+        assertEquals("Street 1", address.getAddressLine1());
+    }
+    
     @Path("/")
     @Ignore
     public static class TheBooks {
@@ -211,4 +249,16 @@ public class DataBindingProviderTest ext
         }
         
     }
+    
+    @Path("/")
+    @Ignore
+    public static class TheXmlBeansBooks {
+
+        @GET
+        @Path("/books/{bookId}/{new}")
+        public Address getStructure() {
+            return null;
+        }
+        
+    }
 }



Mime
View raw message