cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1124645 - in /cxf/trunk: rt/core/src/main/java/org/apache/cxf/wsdl11/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/ tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/int...
Date Thu, 19 May 2011 09:46:08 GMT
Author: ema
Date: Thu May 19 09:46:07 2011
New Revision: 1124645

URL: http://svn.apache.org/viewvc?rev=1124645&view=rev
Log:
[CXF-2193]:Allow for WRAPPED style code generation for warpper elements with xsd:extension
of a wrapper-compatible type

Added:
    cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf2193/
    cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
    cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
    cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java?rev=1124645&r1=1124644&r2=1124645&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java Thu May
19 09:46:07 2011
@@ -83,6 +83,7 @@ import org.apache.ws.commons.schema.XmlS
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
+import org.apache.ws.commons.schema.XmlSchemaType;
 
 import static org.apache.cxf.helpers.CastUtils.cast;
 
@@ -742,55 +743,76 @@ public class WSDLServiceBuilder {
                                                MessageInfo wrapper, boolean allowRefs) {
         if (type.getParticle() instanceof XmlSchemaSequence) {
             XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
-            List<XmlSchemaSequenceMember> items = seq.getItems();
-            boolean ret = true;
-            for (XmlSchemaSequenceMember seqItem : items) {
-                if (!(seqItem instanceof XmlSchemaElement)) {
-                    return false;
-                }
-                XmlSchemaElement el = (XmlSchemaElement)seqItem;
-
-                if (el.getSchemaTypeName() != null) {
-                    MessagePartInfo mpi = wrapper.addMessagePart(new QName(namespaceURI,
el.getName()));
-                    mpi.setTypeQName(el.getSchemaTypeName());
-                    mpi.setElement(true);
-                    mpi.setElementQName(el.getWireName());
-                    mpi.setConcreteName(el.getWireName());
-                    mpi.setXmlSchema(el);
-                } else if (el.getRef().getTargetQName() != null) {
-                    MessagePartInfo mpi = wrapper.addMessagePart(el.getRef().getTargetQName());
-                    mpi.setTypeQName(el.getRef().getTargetQName());
-                    mpi.setElementQName(el.getRef().getTargetQName());
-                    mpi.setElement(true);
-                    mpi.setXmlSchema(el);
-                    mpi.setProperty("isRefElement", true);
-                    // element reference is not permitted for wrapper element
-                    if (!allowRefs) {
-                        ret = false;
-                    }
-                } else {
-                    // anonymous type
-                    MessagePartInfo mpi = wrapper.addMessagePart(new QName(namespaceURI,
el.getName()));
-                    mpi.setElementQName(mpi.getName());
-                    mpi.setConcreteName(el.getWireName());
-                    mpi.setElement(true);
-                    mpi.setXmlSchema(el);
-                }
-            }
-
-            return ret;
+            return buildMessageParts(seq, namespaceURI, wrapper, allowRefs);
         } else if (type.getParticle() == null) {
             if (type.getContentModel() == null) {
                 return true;
             }
             if (type.getContentModel().getContent() instanceof XmlSchemaComplexContentExtension)
{
-                return false;
+                XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)type
+                    .getContentModel().getContent();
+                QName baseTypeName = extension.getBaseTypeName();
+                ServiceInfo serviceInfo = wrapper.getOperation().getInterface().getService();
+                XmlSchemaType schemaType = serviceInfo.getXmlSchemaCollection().getTypeByQName(baseTypeName);
+                if (!(schemaType instanceof XmlSchemaComplexType)
+                    || !isWrappableSequence((XmlSchemaComplexType)schemaType, namespaceURI,
wrapper,
+                                            allowRefs)) {
+                    return false;
+                }
+                             
+                if (extension.getParticle() instanceof XmlSchemaSequence) {
+                    XmlSchemaSequence seq = (XmlSchemaSequence)extension.getParticle();
+                    return buildMessageParts(seq, namespaceURI, wrapper, allowRefs);
+                }  
+                
             }
             return true;
         }
         return false;
     }
 
+        
+    private static boolean buildMessageParts(XmlSchemaSequence seq, String namespaceURI,
MessageInfo wrapper,
+                                             boolean allowRefs) {
+        List<XmlSchemaSequenceMember> items = seq.getItems();
+        boolean ret = true;
+        for (XmlSchemaSequenceMember seqItem : items) {
+            if (!(seqItem instanceof XmlSchemaElement)) {
+                return false;
+            }
+            XmlSchemaElement el = (XmlSchemaElement)seqItem;
+
+            if (el.getSchemaTypeName() != null) {
+                MessagePartInfo mpi = wrapper.addMessagePart(new QName(namespaceURI, el.getName()));
+                mpi.setTypeQName(el.getSchemaTypeName());
+                mpi.setElement(true);
+                mpi.setElementQName(el.getWireName());
+                mpi.setConcreteName(el.getWireName());
+                mpi.setXmlSchema(el);
+            } else if (el.getRef().getTargetQName() != null) {
+                MessagePartInfo mpi = wrapper.addMessagePart(el.getRef().getTargetQName());
+                mpi.setTypeQName(el.getRef().getTargetQName());
+                mpi.setElementQName(el.getRef().getTargetQName());
+                mpi.setElement(true);
+                mpi.setXmlSchema(el);
+                mpi.setProperty("isRefElement", true);
+                // element reference is not permitted for wrapper element
+                if (!allowRefs) {
+                    ret = false;
+                }
+            } else {
+                // anonymous type
+                MessagePartInfo mpi = wrapper.addMessagePart(new QName(namespaceURI, el.getName()));
+                mpi.setElementQName(mpi.getName());
+                mpi.setConcreteName(el.getWireName());
+                mpi.setElement(true);
+                mpi.setXmlSchema(el);
+            }
+        }
+        return ret;
+    }
+        
+        
     private void buildMessage(AbstractMessageContainer minfo, Message msg) {
         SchemaCollection schemas = minfo.getOperation().getInterface().getService()
             .getXmlSchemaCollection();

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java?rev=1124645&r1=1124644&r2=1124645&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
(original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
Thu May 19 09:46:07 2011
@@ -176,7 +176,7 @@ public class Wsdl11AttachmentPolicyProvi
             for (UnknownExtensibilityElement e : extensions) {
                 Policy p = null;
                 if (Constants.isPolicyElement(e.getElementType())) {
-                    p = builder.getPolicy(e.getElement());                    
+                    p = builder.getPolicy(e.getElement());
 
                 } else if (Constants.isPolicyRef(e.getElementType())) {
                     PolicyReference ref = builder.getPolicyReference(e.getElement());

Modified: cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java?rev=1124645&r1=1124644&r2=1124645&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
(original)
+++ cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
Thu May 19 09:46:07 2011
@@ -47,11 +47,14 @@ import org.apache.cxf.tools.util.NameUti
 import org.apache.cxf.tools.util.URIParserUtil;
 import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
 import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaContent;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
+import org.apache.ws.commons.schema.XmlSchemaType;
 
 public final class ProcessorUtil {
     private static final String KEYWORDS_PREFIX = "_";
@@ -378,9 +381,41 @@ public final class ProcessorUtil {
         XmlSchemaElement elementByName = schema.getElementByQName(partElement);
 
         XmlSchemaComplexType type = (XmlSchemaComplexType)elementByName.getSchemaType();
-
+        
         XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
 
+        qnames.addAll(createWrappedElements(seq));    
+
+        //If it's extension
+        if (seq == null && type.getContentModel() != null) {
+            
+            XmlSchemaContent xmlSchemaConent = type.getContentModel().getContent();
+            if (xmlSchemaConent instanceof XmlSchemaComplexContentExtension) {
+                XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)type
+                    .getContentModel().getContent();
+                QName baseTypeName = extension.getBaseTypeName();
+                XmlSchemaType schemaType = schema.getTypeByQName(baseTypeName);
+                if (schemaType instanceof XmlSchemaComplexType) {
+                    XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
+                    if (complexType.getParticle() instanceof XmlSchemaSequence) {
+                        seq = (XmlSchemaSequence)complexType.getParticle();
+                        qnames.addAll(createWrappedElements(seq));
+                    }
+                }
+
+                if (extension.getParticle() instanceof XmlSchemaSequence) {
+                    XmlSchemaSequence xmlSchemaSeq = (XmlSchemaSequence)extension.getParticle();
+                    qnames.addAll(createWrappedElements(xmlSchemaSeq));
+                }
+            }
+
+        }
+        return qnames;
+    }
+
+    private static List<WrapperElement> createWrappedElements(XmlSchemaSequence seq)
{
+       
+        List<WrapperElement> qnames = new ArrayList<WrapperElement>();
         if (seq != null) {
 
             List<XmlSchemaSequenceMember> items = seq.getItems();
@@ -398,7 +433,7 @@ public final class ProcessorUtil {
         }
         return qnames;
     }
-
+    
     public static boolean isSchemaFormQualified(ToolContext context, QName partElement) {
         ServiceInfo serviceInfo = (ServiceInfo)context.get(ServiceInfo.class);
         SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();

Modified: cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java?rev=1124645&r1=1124644&r2=1124645&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
(original)
+++ cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
Thu May 19 09:46:07 2011
@@ -1366,5 +1366,26 @@ public class CodeGenTest extends Abstrac
         fault = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_http.BadRecordLitFault");
         assertEquals(fault.getName().hashCode(), ObjectStreamClass.lookup(fault).getSerialVersionUID());
     }
+    
+    
+    @Test
+    public void testExtensionWrapper() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL,
+                getLocation("/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl"));
+        processor.setContext(env);
+        processor.execute();
+
+        File infFile = new File(output, "org/apache/cxf/w2j/extension_wrapped/Greeter.java");
+        assertTrue(infFile.exists());
+
+        Class<?> interfaceClass = classLoader.loadClass("org.apache.cxf.w2j.extension_wrapped.Greeter");
+
+        Method method = interfaceClass.getMethod("greetMe", new Class[] {
+            Holder.class, Holder.class, Holder.class, Holder.class, Holder.class
+        });
+        assertTrue("greetMe operation is NOT generated correctly as excepted", method !=
null);
+        RequestWrapper reqWrapper = method.getAnnotation(RequestWrapper.class);
+        assertNotNull("@RequestWrapper is expected", reqWrapper);
+    }
 
 }

Added: cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl?rev=1124645&view=auto
==============================================================================
--- cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl
(added)
+++ cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl
Thu May 19 09:46:07 2011
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
+	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cxf.apache.org/w2j/extension_wrapped"
+	xmlns:x1="http://cxf.apache.org/w2j/extension_wrapped/types"
+	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+	targetNamespace="http://cxf.apache.org/w2j/extension_wrapped" name="HelloWorld">
+	<wsdl:types>
+		<schema targetNamespace="http://cxf.apache.org/w2j/extension_wrapped/types"
+			xmlns="http://www.w3.org/2001/XMLSchema" xmlns:x1="http://cxf.apache.org/w2j/extension_wrapped/types"
+			elementFormDefault="qualified">
+			<element name="greetMe">
+				<complexType>
+					<sequence>
+						<element name="content" type="xsd:base64Binary" minOccurs="0" />
+						<element name="id" type="xsd:string" minOccurs="0" />
+						<element name="name" type="xsd:string" minOccurs="0" />
+					</sequence>
+				</complexType>
+			</element>
+
+			<element name="greetMeResponse" type="x1:ComplexContext" />
+
+			<complexType name="ComplexContext">
+				<complexContent>
+					<extension base="x1:ComplexContextType">
+						<sequence>
+							<element name="extraElement" type="xsd:string" />
+						</sequence>
+					</extension>
+				</complexContent>
+			</complexType>
+
+			<complexType name="ComplexContextType">
+				<sequence>
+					<element name="content" type="xsd:base64Binary" minOccurs="0" />
+					<element name="id" type="xsd:string" minOccurs="0" />
+					<element name="name" type="xsd:string" minOccurs="0" />
+					<element name="testlist" type="xsd:string" minOccurs="0"
+						maxOccurs="unbounded" />
+				</sequence>
+			</complexType>
+
+
+
+		</schema>
+	</wsdl:types>
+
+	<wsdl:message name="greetMeRequest">
+		<wsdl:part name="in" element="x1:greetMe" />
+	</wsdl:message>
+	<wsdl:message name="greetMeResponse">
+		<wsdl:part name="out" element="x1:greetMeResponse" />
+	</wsdl:message>
+
+	<wsdl:portType name="Greeter">
+		>
+		<wsdl:operation name="greetMe">
+			<wsdl:input name="greetMeRequest" message="tns:greetMeRequest" />
+			<wsdl:output name="greetMeResponse" message="tns:greetMeResponse" />
+		</wsdl:operation>
+	</wsdl:portType>
+	<wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
+		<soap:binding style="document"
+			transport="http://schemas.xmlsoap.org/soap/http" />
+		<wsdl:operation name="greetMe">
+			<soap:operation style="document" />
+			<wsdl:input>
+				<soap:body use="literal" />
+			</wsdl:input>
+			<wsdl:output>
+				<soap:body use="literal" />
+			</wsdl:output>
+		</wsdl:operation>
+	</wsdl:binding>
+	<wsdl:service name="SOAPService">
+		<wsdl:port name="SoapPort" binding="tns:Greeter_SOAPBinding">
+			<soap:address location="http://localhost:9000/SoapContext/SoapPort" />
+			<wswa:UsingAddressing xmlns:wswa="http://www.w3.org/2005/02/addressing/wsdl" />
+		</wsdl:port>
+	</wsdl:service>
+</wsdl:definitions>
+



Mime
View raw message