You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/12/20 16:58:38 UTC

svn commit: r605971 - in /incubator/cxf/trunk: distribution/ distribution/bundle/ distribution/manifest/ rt/core/src/main/java/org/apache/cxf/test/ rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ rt/databinding/xmlbeans/src/test/java/org...

Author: dkulp
Date: Thu Dec 20 07:58:35 2007
New Revision: 605971

URL: http://svn.apache.org/viewvc?rev=605971&view=rev
Log:
Updates to get xmlbeans databinding to support more primitives

Added:
    incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java   (with props)
    incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java   (with props)
Modified:
    incubator/cxf/trunk/distribution/bundle/pom.xml
    incubator/cxf/trunk/distribution/manifest/pom.xml
    incubator/cxf/trunk/distribution/pom.xml
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java
    incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
    incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java
    incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/AbstractXmlBeansTest.java

Modified: incubator/cxf/trunk/distribution/bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/bundle/pom.xml?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/bundle/pom.xml (original)
+++ incubator/cxf/trunk/distribution/bundle/pom.xml Thu Dec 20 07:58:35 2007
@@ -84,6 +84,11 @@
         </dependency>
         <dependency>
             <groupId>${pom.groupId}</groupId>
+            <artifactId>cxf-rt-databinding-xmlbeans</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
             <artifactId>cxf-tools-wsdlto-frontend-jaxws</artifactId>
             <version>${pom.version}</version>
             <optional>true</optional>

Modified: incubator/cxf/trunk/distribution/manifest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/manifest/pom.xml?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/manifest/pom.xml (original)
+++ incubator/cxf/trunk/distribution/manifest/pom.xml Thu Dec 20 07:58:35 2007
@@ -180,7 +180,11 @@
             <artifactId>cxf-rt-databinding-aegis</artifactId>
             <version>${pom.version}</version>
         </dependency>
-        
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>cxf-rt-databinding-xmlbeans</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
         <dependency>
             <groupId>${pom.groupId}</groupId>
             <artifactId>cxf-rt-ws-addr</artifactId>

Modified: incubator/cxf/trunk/distribution/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/pom.xml?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/pom.xml (original)
+++ incubator/cxf/trunk/distribution/pom.xml Thu Dec 20 07:58:35 2007
@@ -184,6 +184,11 @@
             <artifactId>cxf-rt-databinding-aegis</artifactId>
             <version>${pom.version}</version>
         </dependency>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>cxf-rt-databinding-xmlbeans</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>${pom.groupId}</groupId>

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java Thu Dec 20 07:58:35 2007
@@ -92,6 +92,12 @@
         return testUtilities.invoke(address, transport, message);
     }
 
+    protected Node invoke(String address, 
+                          String transport,
+                          byte[] message) throws Exception {
+        return testUtilities.invoke(address, transport, message);
+    }
+
     /**
      * Assert that the following XPath query selects one or more nodes.
      * 

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java Thu Dec 20 07:58:35 2007
@@ -193,11 +193,45 @@
         os.close();
 
         byte[] bs = obs.getResponseStream().toByteArray();
-
+        
         return bs;
     }
+    public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
+        EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
+        ei.setAddress(address);
+
+        ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
+        ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
+        Conduit conduit = conduitInit.getConduit(ei);
+
+        TestMessageObserver obs = new TestMessageObserver();
+        conduit.setMessageObserver(obs);
+
+        Message m = new MessageImpl();
+        conduit.prepare(m);
+
+        OutputStream os = m.getContent(OutputStream.class);
+        os.write(message);
+
+        // TODO: shouldn't have to do this. IO caching needs cleaning
+        // up or possibly removal...
+        os.flush();
+        os.close();
+
+        return obs.getResponseStream().toByteArray();
+    }
 
     public Node invoke(String address, String transport, String message) throws Exception {
+        byte[] bs = invokeBytes(address, transport, message);
+
+        ByteArrayInputStream input = new ByteArrayInputStream(bs);
+        try {
+            return DOMUtils.readXml(input);
+        } catch (SAXParseException e) {
+            throw new IllegalStateException("Could not parse message:\n" + new String(bs), e);
+        }
+    }
+    public Node invoke(String address, String transport, byte[] message) throws Exception {
         byte[] bs = invokeBytes(address, transport, message);
 
         ByteArrayInputStream input = new ByteArrayInputStream(bs);

Modified: incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java (original)
+++ incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java Thu Dec 20 07:58:35 2007
@@ -84,7 +84,18 @@
         }
         if (unwrap && obj != null) {
             try {
-                Method m = obj.getClass().getMethod("get" + part.getTypeClass().getSimpleName() + "Value");
+                Class<?> tc = part.getTypeClass(); 
+                String methName;
+                if (tc.equals(Integer.TYPE) || tc.equals(Integer.class)) {
+                    methName = "getIntValue";
+                } else if (tc.equals(byte[].class)) {
+                    methName = "byteArrayValue";
+                } else {
+                    String tp = tc.getSimpleName();
+                    tp = Character.toUpperCase(tp.charAt(0)) + tp.substring(1);
+                    methName = "get" + tp + "Value";
+                }
+                Method m = obj.getClass().getMethod(methName);
                 obj = m.invoke(obj);
             } catch (Exception e) {
                 e.printStackTrace();

Modified: incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java (original)
+++ incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java Thu Dec 20 07:58:35 2007
@@ -22,6 +22,10 @@
 
 import java.io.InputStream;
 import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Logger;
@@ -48,7 +52,6 @@
 import org.apache.xmlbeans.SchemaTypeSystem;
 import org.apache.xmlbeans.XmlAnySimpleType;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlString;
 import org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem;
 
 /**
@@ -64,7 +67,26 @@
         = new HashMap<String, XmlSchema>();
     
     static {
-        CLASS_MAP.put(String.class, XmlString.class);
+        CLASS_MAP.put(String.class, org.apache.xmlbeans.XmlString.class);
+        CLASS_MAP.put(Integer.class, org.apache.xmlbeans.XmlInt.class);
+        CLASS_MAP.put(Integer.TYPE, org.apache.xmlbeans.XmlInt.class);
+        CLASS_MAP.put(Short.class, org.apache.xmlbeans.XmlShort.class);
+        CLASS_MAP.put(Short.TYPE, org.apache.xmlbeans.XmlShort.class);
+        CLASS_MAP.put(Byte.class, org.apache.xmlbeans.XmlByte.class);
+        CLASS_MAP.put(Byte.TYPE, org.apache.xmlbeans.XmlByte.class);
+        CLASS_MAP.put(Float.class, org.apache.xmlbeans.XmlFloat.class);
+        CLASS_MAP.put(Float.TYPE, org.apache.xmlbeans.XmlFloat.class);
+        CLASS_MAP.put(Double.class, org.apache.xmlbeans.XmlDouble.class);
+        CLASS_MAP.put(Double.TYPE, org.apache.xmlbeans.XmlDouble.class);
+        CLASS_MAP.put(Long.class, org.apache.xmlbeans.XmlLong.class);
+        CLASS_MAP.put(Long.TYPE, org.apache.xmlbeans.XmlLong.class);
+        CLASS_MAP.put(Boolean.class, org.apache.xmlbeans.XmlBoolean.class);
+        CLASS_MAP.put(Boolean.TYPE, org.apache.xmlbeans.XmlBoolean.class);
+        CLASS_MAP.put(BigDecimal.class, org.apache.xmlbeans.XmlDecimal.class);
+        CLASS_MAP.put(BigInteger.class, org.apache.xmlbeans.XmlInteger.class);
+        CLASS_MAP.put(Date.class, org.apache.xmlbeans.XmlDate.class);
+        CLASS_MAP.put(Calendar.class, org.apache.xmlbeans.XmlDate.class);
+        CLASS_MAP.put(byte[].class, org.apache.xmlbeans.XmlBase64Binary.class);
     }
     
     public XmlBeansSchemaInitializer(ServiceInfo serviceInfo,
@@ -136,6 +158,9 @@
         if (!XmlObject.class.isAssignableFrom(clazz)) {
             
             Class<? extends XmlAnySimpleType> type = CLASS_MAP.get(clazz);
+            if (type == null) {
+                System.out.println(clazz);
+            }
             SchemaTypeSystem sts = BuiltinSchemaTypeSystem.get();
             SchemaType st2 = sts.typeForClassname(type.getName());
 

Modified: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/AbstractXmlBeansTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/AbstractXmlBeansTest.java?rev=605971&r1=605970&r2=605971&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/AbstractXmlBeansTest.java (original)
+++ incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/AbstractXmlBeansTest.java Thu Dec 20 07:58:35 2007
@@ -109,6 +109,9 @@
     protected Node invoke(String service, String message) throws Exception {
         return invoke("local://" + service, LocalTransportFactory.TRANSPORT_ID, message);
     }
+    protected Node invoke(String service, byte[] message) throws Exception {
+        return invoke("local://" + service, LocalTransportFactory.TRANSPORT_ID, message);
+    }
     
     public Server createService(Class serviceClass, QName name) {
         return createService(serviceClass, null, name);

Added: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java?rev=605971&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java (added)
+++ incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java Thu Dec 20 07:58:35 2007
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.xmlbeans;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+
+import org.apache.cxf.common.util.Base64Utility;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class PrimitiveTypesTest extends AbstractXmlBeansTest {
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        createService(TypesService.class, new TypesService(),
+                      "TypesService", new QName("urn:TypesService", "TypesService"));
+
+    }
+    
+    @Test
+    public void testPrimitives() throws Exception {
+        doTestType("testInt", "24", "In:24");
+        doTestType("testInteger", "24", "In:24");        
+
+        doTestType("testFloat", "3.14", "In:3.14");
+        doTestType("testFloatPrim", "3.14", "In:3.14");        
+
+        doTestType("testBoolean", "false", "In:false");
+        doTestType("testBooleanPrim", "true", "In:true");
+        
+        doTestType("testBase64Binary", Base64Utility.encode("HelloWorld".getBytes()), "In:HelloWorld");
+    }
+    
+    
+    public void doTestType(String operation, String data, String expected) throws Exception {
+        String req = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>"
+            + "<env:Header/>"
+            + "<env:Body xmlns='urn:TypesService' xmlns:x='http://example.com'>"
+            + "   <" + operation + ">"
+            + "      <arg0>" + data + "</arg0>"
+            + "   </" + operation + ">"
+            + "</env:Body>"
+            + "</env:Envelope>";
+        Node nd = invoke("TypesService", req.getBytes());
+        
+        addNamespace("t", "urn:TypesService");
+        assertValid("//t:return[text()='" + expected + "']", nd);
+        assertValid("//t:return1[text()='" + data + "']", nd);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/PrimitiveTypesTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java?rev=605971&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java (added)
+++ incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java Thu Dec 20 07:58:35 2007
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.xmlbeans;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.xml.ws.Holder;
+
+@WebService(targetNamespace = "urn:TypesService")
+public class TypesService {
+
+    @WebMethod
+    public String testInt(int i, @WebParam(mode = WebParam.Mode.OUT) Holder<Integer> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testInteger(Integer i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Integer> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testFloatPrim(float i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Float> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testFloat(Float i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Float> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testBooleanPrim(boolean i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Boolean> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testBoolean(Boolean i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Boolean> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testLongPrim(long i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Long> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    @WebMethod
+    public String testLong(Long i,  @WebParam(mode = WebParam.Mode.OUT) Holder<Long> i2) {
+        i2.value = i;
+        return "In:" + i;
+    }
+    
+    @WebMethod 
+    public String testBase64Binary(byte i[],  @WebParam(mode = WebParam.Mode.OUT) Holder<byte[]> i2) {
+        i2.value = i;
+        return "In:" + new String(i);
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/TypesService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date