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/11/09 20:03:18 UTC

svn commit: r593624 - in /incubator/cxf/trunk: common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/ common/xjc/dv-test/src/test/resources/schemas/configuration/ common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/ rt/bindings/http/src/main/java/org/ap...

Author: dkulp
Date: Fri Nov  9 11:03:17 2007
New Revision: 593624

URL: http://svn.apache.org/viewvc?rev=593624&view=rev
Log:
[CXF-1195] Allow dv plugin to do default values for enums
Make sure more MessagePartInfo objects have XmlSchema objects properly set (work in progress)
Fix issue that without asm, wrapper types with collections aren't properly marshalled

Modified:
    incubator/cxf/trunk/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java
    incubator/cxf/trunk/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd
    incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
    incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
    incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/strategy/ConventionStrategy.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Modified: incubator/cxf/trunk/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java (original)
+++ incubator/cxf/trunk/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java Fri Nov  9 11:03:17 2007
@@ -149,6 +149,8 @@
     }
     
     private void assertDefaultElementValues(Foo foo) {
+        assertEquals("Unexpected value for element driving",
+                     "LeftTurn", foo.getDriving().value());
         assertEquals("Unexpected value for element stringElem",
                      "hello", foo.getStringElem());
         assertTrue("Unexpected value for element booleanElem",

Modified: incubator/cxf/trunk/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd (original)
+++ incubator/cxf/trunk/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd Fri Nov  9 11:03:17 2007
@@ -32,9 +32,18 @@
             <xs:minExclusive value="0"/>
         </xs:restriction>
     </xs:simpleType>
+    
+    <xs:simpleType name="drivingDecision">
+    	<xs:restriction base="xs:string">
+    		<xs:enumeration value="RightTurn"/>
+    		<xs:enumeration value="LeftTurn"/>
+    		<xs:enumeration value="U-Turn"/>
+    	</xs:restriction>
+    </xs:simpleType>
 
     <xs:complexType name="foo">        
         <xs:sequence>
+            <xs:element name="driving" type="tns:drivingDecision" default="LeftTurn" minOccurs="0"></xs:element>
             <xs:element name="stringElem" type="xs:string" default="hello" minOccurs="0"></xs:element>
             <xs:element name="booleanElem" type="xs:boolean" default="true" minOccurs="0"></xs:element>
             <xs:element name="integerElem" type="xs:integer" default="11" minOccurs="0"></xs:element>

Modified: incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java (original)
+++ incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java Fri Nov  9 11:03:17 2007
@@ -29,6 +29,7 @@
 
 import org.xml.sax.ErrorHandler;
 
+import com.sun.codemodel.ClassType;
 import com.sun.codemodel.JConditional;
 import com.sun.codemodel.JDefinedClass;
 import com.sun.codemodel.JDocComment;
@@ -185,7 +186,12 @@
                 .arg(qn.getPrefix());
         } else if ("javax.xml.datatype.Duration".equals(typeName)) {
             dv = outline.getCodeModel().ref(org.apache.cxf.jaxb.DatatypeFactory.class)
-            .staticInvoke("createDuration").arg(defaultValue);
+                .staticInvoke("createDuration").arg(defaultValue);
+        } else if (type instanceof JDefinedClass) {
+            JDefinedClass cls = (JDefinedClass)type;
+            if (cls.getClassType() == ClassType.ENUM) {
+                dv = cls.staticInvoke("fromValue").arg(defaultValue);
+            }
         }
         // TODO: GregorianCalendar, ...
         return dv;

Modified: incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java (original)
+++ incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java Fri Nov  9 11:03:17 2007
@@ -218,6 +218,10 @@
         if (schemaAnnotation instanceof XmlSchemaElement) {
             element = (XmlSchemaElement)schemaAnnotation;
             qname = element.getQName();
+            if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
+                throw new Fault(new Message("SIMPLE_TYPE", BUNDLE));
+            }
+            
             cplxType = (XmlSchemaComplexType)element.getSchemaType();
             unQualified = findSchemaUnQualified(schemas, element.getSchemaTypeName());
             if (cplxType == null) {

Modified: incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/strategy/ConventionStrategy.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/strategy/ConventionStrategy.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/strategy/ConventionStrategy.java (original)
+++ incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/strategy/ConventionStrategy.java Fri Nov  9 11:03:17 2007
@@ -21,10 +21,13 @@
 import java.lang.reflect.Method;
 import java.util.logging.Logger;
 
+import javax.xml.namespace.QName;
+
 import org.apache.cxf.binding.http.URIMapper;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.ws.commons.schema.XmlSchemaElement;
 
 import static org.apache.cxf.binding.http.HttpConstants.DELETE;
 import static org.apache.cxf.binding.http.HttpConstants.GET;
@@ -132,8 +135,13 @@
 
     private boolean isXSDPrimitive(MessagePartInfo part) {
         String xsdNs = "http://www.w3.org/2001/XMLSchema";
-        if (!part.isElement() 
-            && part.getTypeQName().getNamespaceURI().equals(xsdNs)) {
+        QName tn = null;
+        if (part.isElement()) {
+            tn = ((XmlSchemaElement)part.getXmlSchema()).getSchemaTypeName();
+        } else {
+            tn = part.getTypeQName();
+        }
+        if (tn != null && tn.getNamespaceURI().equals(xsdNs)) {
             return true;
         }
         

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java Fri Nov  9 11:03:17 2007
@@ -150,6 +150,8 @@
                 QName typeName = getTypeName(beanInfo);
 
                 createBridgeXsElement(part, qn, typeName);
+            } else if (part.getXmlSchema() == null) {
+                part.setXmlSchema(el);
             }
         }
     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java Fri Nov  9 11:03:17 2007
@@ -268,7 +268,11 @@
                 Object ret = wrapperType.newInstance();
 
                 for (int x = 0; x < setMethods.length; x++) {
-                    if (setMethods[x] == null && fields[x] == null) {
+                    if (getMethods[x] == null
+                        && setMethods[x] == null 
+                        && fields[x] == null) {
+                        //this part is a header or something
+                        //that is not part of the wrapper.
                         continue;
                     }
                     Object o = lst.get(x);

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Fri Nov  9 11:03:17 2007
@@ -346,6 +346,61 @@
         } else {
             buildServiceFromClass();
         }
+        //assert validateServiceModel();
+    }
+    
+    public boolean validateServiceModel() {
+        for (ServiceInfo si : getService().getServiceInfos()) {
+            for (OperationInfo opInfo : si.getInterface().getOperations()) {
+                for (MessagePartInfo mpi : opInfo.getInput().getMessageParts()) {
+                    assert mpi.getXmlSchema() != null;
+                    if (mpi.isElement()) {
+                        assert mpi.getXmlSchema() instanceof XmlSchemaElement;
+                    } else {
+                        assert !(mpi.getXmlSchema() instanceof XmlSchemaElement);
+                    }
+                }
+                for (MessagePartInfo mpi : opInfo.getOutput().getMessageParts()) {
+                    assert mpi.getXmlSchema() != null;
+                    if (mpi.isElement()) {
+                        assert mpi.getXmlSchema() instanceof XmlSchemaElement;
+                    } else {
+                        assert !(mpi.getXmlSchema() instanceof XmlSchemaElement);
+                    }
+                }
+                if (opInfo.isUnwrappedCapable()) {
+                    opInfo = opInfo.getUnwrappedOperation();
+                    for (MessagePartInfo mpi : opInfo.getInput().getMessageParts()) {
+                        assert mpi.getXmlSchema() != null;
+                        if (mpi.isElement()) {
+                            assert mpi.getXmlSchema() instanceof XmlSchemaElement;
+                        } else {
+                            assert !(mpi.getXmlSchema() instanceof XmlSchemaElement);
+                        }
+                    }
+                    for (MessagePartInfo mpi : opInfo.getOutput().getMessageParts()) {
+                        assert mpi.getXmlSchema() != null;
+                        if (mpi.isElement()) {
+                            assert mpi.getXmlSchema() instanceof XmlSchemaElement;
+                        } else {
+                            assert !(mpi.getXmlSchema() instanceof XmlSchemaElement);
+                        }
+                    }
+                }
+                if (opInfo.hasFaults()) {
+                    //check to make sure the faults are elements
+                    for (FaultInfo fault : opInfo.getFaults()) {
+                        MessagePartInfo mpi = fault.getMessagePart(0);
+                        assert mpi != null;
+                        assert mpi.getXmlSchema() != null;
+                        assert mpi.isElement();
+                        assert mpi.getXmlSchema() instanceof XmlSchemaElement;
+                    }
+                }
+
+            }
+        }
+        return true;
     }
 
     public boolean isPopulateFromClass() {
@@ -710,12 +765,15 @@
                         addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                     }
                 }
+                mpi.setElement(true);
                 mpi.setXmlSchema(el);
                 mpi.setElementQName(qname);
                 mpi.setConcreteName(qname);
                 continue;
             } else {
                 el.setSchemaTypeName(mpi.getTypeQName());
+                mpi.setXmlSchema(el);
+                mpi.setConcreteName(qname);
                 addImport(schema, mpi.getTypeQName().getNamespaceURI());
             }
 
@@ -814,16 +872,20 @@
                 el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
                 if (schema.getElementFormDefault().getValue().equals(XmlSchemaForm.UNQUALIFIED)) {
                     mpi.setConcreteName(new QName(null, mpi.getName().getLocalPart()));
+                } else {
+                    mpi.setConcreteName(mpi.getName());
                 }
             }
             if (!Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
-                if (!mpi.isElement()) {
-                    mpi.setXmlSchema(el);                    
-                }
-                Annotation[] parameterAnnotation = getMethodParameterAnnotations(mpi);
-                if (parameterAnnotation != null) {
-                    addMimeType(el, parameterAnnotation);
+                boolean wasType = !mpi.isElement();
+                if (wasType) {
+                    QName concreteName = mpi.getConcreteName();
+                    mpi.setXmlSchema(el);
+                    mpi.setElement(true);
+                    mpi.setElementQName(el.getQName());
+                    mpi.setConcreteName(concreteName);
                 }
+                addMimeType(el, getMethodParameterAnnotations(mpi));
                 
                 Annotation[] methodAnnotations = getMethodAnnotations(mpi);
                 if (methodAnnotations != null) {
@@ -849,13 +911,14 @@
                 } else if (Collection.class.isAssignableFrom(mpi.getTypeClass())
                            && mpi.getTypeClass().isInterface()) {
                     Type type = (Type)mpi.getProperty(GENERIC_TYPE);
+                    
                     if (!(type instanceof java.lang.reflect.ParameterizedType)
-                        && mpi.getTypeQName() == null) {
+                        && el.getSchemaTypeName() == null
+                        && el.getSchemaType() == null) {
                         el.setMinOccurs(0);
                         el.setMaxOccurs(Long.MAX_VALUE);
                         el.setSchemaTypeName(Constants.XSD_ANYTYPE);
                     }
-
                 } else {
                     el.setMaxOccurs(1);
                     if (mpi.getTypeClass() != null && !mpi.getTypeClass().isPrimitive()) {
@@ -895,13 +958,15 @@
     }    
     
     private void addMimeType(final XmlSchemaElement element, final Annotation[] annotations) {
-        for (Annotation annotation : annotations) {
-            if (annotation instanceof XmlMimeType) {
-                MimeAttribute attr = new MimeAttribute();
-                attr.setValue(((XmlMimeType)annotation).value());
-                element.addMetaInfo(MimeAttribute.MIME_QNAME, attr);
+        if (annotations != null) {
+            for (Annotation annotation : annotations) {
+                if (annotation instanceof XmlMimeType) {
+                    MimeAttribute attr = new MimeAttribute();
+                    attr.setValue(((XmlMimeType)annotation).value());
+                    element.addMetaInfo(MimeAttribute.MIME_QNAME, attr);
+                }
             }
-        }         
+        }
     }
 
     

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=593624&r1=593623&r2=593624&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java (original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java Fri Nov  9 11:03:17 2007
@@ -401,7 +401,8 @@
     //Test for cxf774
     public void testList() throws Exception {
         env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/list_test.wsdl");
-        env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.cxf774.ListTestImpl");
+        env.put(ToolConstants.CFG_CLASSNAME, 
+                org.apache.cxf.tools.fortest.cxf774.ListTestImpl.class.getName());
         env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
         try {
             processor.setEnvironment(env);