cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r469363 - in /incubator/cxf/trunk/tools/wsdl2java/src: main/java/org/apache/cxf/tools/wsdl2java/processor/ main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ test/java/org/apache/cxf/tools/wsdl2java/processor/ test/resources/wsdl2...
Date Tue, 31 Oct 2006 04:13:35 GMT
Author: ema
Date: Mon Oct 30 20:13:34 2006
New Revision: 469363

URL: http://svn.apache.org/viewvc?view=rev&rev=469363
Log:
[CXF-161]Fixed the parameters order in generated code does not correspond to wsdl parts order
issue
Locally import the references.xsd

Added:
    incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/
    incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
  (with props)
Modified:
    incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java
    incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java
    incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ParameterProcessor.java
    incubator/cxf/trunk/tools/wsdl2java/src/test/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessorTest.java
    incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_schemas/references.xsd

Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java?view=diff&rev=469363&r1=469362&r2=469363
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java
(original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java
Mon Oct 30 20:13:34 2006
@@ -162,7 +162,7 @@
         }
         
         bindingGenerator.generate();
-        //env.put(ToolConstants.BINDING_GENERATOR, bindingGenerator);
+       
         
 
     }

Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java?view=diff&rev=469363&r1=469362&r2=469363
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java
(original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java
Mon Oct 30 20:13:34 2006
@@ -240,6 +240,11 @@
         for (Definition def : importedDefinitions) {
             extractSchema(def);
         }
+        env.put(ToolConstants.WSDL_DEFINITION, wsdlDefinition);
+        env.put(ToolConstants.IMPORTED_DEFINITION, importedDefinitions);
+        env.put(ToolConstants.SCHEMA_LIST, schemaList);
+        env.put(ToolConstants.SCHEMA_TARGET_NAMESPACES, schemaTargetNamespaces);
+        env.put(ToolConstants.PORTTYPE_MAP, getPortTypes(wsdlDefinition));
 
         if (schemaList.size() == 0) {
             if (env.isVerbose()) {
@@ -248,13 +253,7 @@
             return;
         }
 
-        schemaTargetNamespaces.clear();
         try {
-            env.put(ToolConstants.WSDL_DEFINITION, wsdlDefinition);
-            env.put(ToolConstants.IMPORTED_DEFINITION, importedDefinitions);
-            env.put(ToolConstants.SCHEMA_LIST, schemaList);
-            env.put(ToolConstants.SCHEMA_TARGET_NAMESPACES, schemaTargetNamespaces);
-            env.put(ToolConstants.PORTTYPE_MAP, getPortTypes(wsdlDefinition));
             bindingGenerator = (DataBindingGenerator)new JAXBBindingGenerator();
             bindingGenerator.initialize(env);
             env.put(ToolConstants.BINDING_GENERATOR, bindingGenerator);

Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ParameterProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ParameterProcessor.java?view=diff&rev=469363&r1=469362&r2=469363
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ParameterProcessor.java
(original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ParameterProcessor.java
Mon Oct 30 20:13:34 2006
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.tools.wsdl2java.processor.internal;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -27,15 +28,26 @@
 import java.util.Map;
 
 import javax.jws.soap.SOAPBinding;
+import javax.wsdl.Definition;
 import javax.wsdl.Message;
 import javax.wsdl.Part;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.SAXException;
+
 import com.sun.codemodel.JType;
 import com.sun.tools.xjc.api.Property;
 
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.common.ToolContext;
 import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.common.WSDLConstants;
 import org.apache.cxf.tools.common.model.JavaAnnotation;
 import org.apache.cxf.tools.common.model.JavaMethod;
 import org.apache.cxf.tools.common.model.JavaParameter;
@@ -44,14 +56,23 @@
 import org.apache.cxf.tools.util.ProcessorUtil;
 
 public class ParameterProcessor extends AbstractProcessor {
-   
-    public ParameterProcessor(ToolContext penv) {      
-           super(penv);
+    
+    private Map<String, Element> wsdlElementMap = new HashMap<String, Element>();
+    private Map<String, String>  wsdlLoc = new HashMap<String, String>();
+    
+    @SuppressWarnings("unchecked")
+    public ParameterProcessor(ToolContext penv) {
+        super(penv);
+        Definition definition = (Definition)penv.get(ToolConstants.WSDL_DEFINITION);
+        wsdlLoc.put(definition.getTargetNamespace(), definition.getDocumentBaseURI());
+        List<Definition> defs = (List<Definition>)penv.get(ToolConstants.IMPORTED_DEFINITION);
+        for (Definition def : defs) {
+            wsdlLoc.put(def.getTargetNamespace(), def.getDocumentBaseURI());
+        }
     }
 
     public void process(JavaMethod method, Message inputMessage, Message outputMessage,
-                        boolean isRequestResponse, List<String> parameterOrder) throws
ToolException {
-
+                        boolean isRequestResponse, List<String> parameterOrder) throws
ToolException {     
         boolean parameterOrderPresent = false;
 
         if (parameterOrder != null && !parameterOrder.isEmpty()) {
@@ -158,12 +179,85 @@
 
     @SuppressWarnings("unchecked")
     private void processInput(JavaMethod method, Message inputMessage) throws ToolException
{
-        Map<String, Part> inputPartsMap = inputMessage.getParts();
-        Collection<Part> inputParts = inputPartsMap.values();
+        List<Part> inputParts = getDefaultOrderParts(inputMessage);
         for (Part part : inputParts) {
             addParameter(method, getParameterFromPart(method, part, JavaType.Style.IN));
         }
     }
+    
+    @SuppressWarnings("unchecked")
+    private List<Part> getDefaultOrderParts(Message message) {
+        Map<String, Part> partsMap = message.getParts();
+        List<Part> parts = new ArrayList<Part>();
+        if (message.getParts().size() > 1) {
+            List<String> paraOrder = getDefaultOrderPartNameList(message);
+            parts = message.getOrderedParts(paraOrder);
+        } else {
+            Collection<Part> partsValues = partsMap.values();
+            for (Part part : partsValues) {
+                parts.add(part);
+            }
+        }
+        return parts;
+    }
+    
+    
+    private Element getWSDLElement(Message message) {
+        String ns = message.getQName().getNamespaceURI();
+        String wsdlLocation = wsdlLoc.get(ns);
+        Element wsdlElement = wsdlElementMap.get(ns);
+        if (wsdlElementMap.get(ns) == null) {
+            Document doc = null;
+            try {
+                doc = DOMUtils.createDocumentBuilder().parse(wsdlLocation);
+                wsdlElement = doc.getDocumentElement();
+                wsdlElementMap.put(ns, wsdlElement);
+            } catch (SAXException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+        return wsdlElement;
+    }
+    
+    
+    private List<String> getDefaultOrderPartNameList(Message message) {
+        List<String> nameList = new ArrayList<String>(); 
+        Element wsdlElement = getWSDLElement(message);     
+        NodeList messageNodeList = wsdlElement.getElementsByTagNameNS(message.getQName().getNamespaceURI(),
+                                   WSDLConstants.QNAME_MESSAGE.getLocalPart());       
+        Node messageNode = null;
+        
+        for (int i = 0; i < messageNodeList.getLength(); i++) {
+            Node node = messageNodeList.item(i);
+            if (DOMUtils.getAttribute(node, 
+                                      WSDLConstants.ATTR_NAME).
+                                          equals(message.getQName().getLocalPart())) {
+                messageNode = node;
+                break;
+            }
+        }
+        if (messageNode == null) {
+            return null;
+        }
+        Node partNode = DOMUtils.getChild(messageNode, Node.ELEMENT_NODE);
+        nameList.add(DOMUtils.getAttribute(partNode, WSDLConstants.ATTR_NAME));
+        while (partNode.getNextSibling() != null) {
+            partNode = partNode.getNextSibling();
+            if (partNode.getNodeType() == Node.ELEMENT_NODE) {
+                nameList.add(DOMUtils.getAttribute(partNode, WSDLConstants.ATTR_NAME));
+            }
+        }
+        
+        
+        return nameList;
+        
+        
+    }
+    
 
     @SuppressWarnings("unchecked")
     private void processWrappedInput(JavaMethod method, Message inputMessage) throws ToolException
{
@@ -193,9 +287,8 @@
                                boolean isRequestResponse) throws ToolException {
         Map<String, Part> inputPartsMap = 
             inputMessage == null ? new HashMap<String, Part>() : inputMessage.getParts();
-        Map<String, Part> outputPartsMap = 
-            outputMessage == null ? new HashMap<String, Part>() : outputMessage.getParts();
-        Collection<Part> outputParts = outputPartsMap.values();
+        List<Part> outputParts = 
+            outputMessage == null ? new ArrayList<Part>() : this.getDefaultOrderParts(outputMessage);
         // figure out output parts that are not present in input parts
         List<Part> outParts = new ArrayList<Part>();
         if (isRequestResponse) {

Modified: incubator/cxf/trunk/tools/wsdl2java/src/test/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/test/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessorTest.java?view=diff&rev=469363&r1=469362&r2=469363
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/test/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessorTest.java
(original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/test/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessorTest.java
Mon Oct 30 20:13:34 2006
@@ -1103,7 +1103,17 @@
         processor.process();
     }
     
-
+    public void testDefaultParameterOrder() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/bug161/header2.wsdl"));
+        processor.setEnvironment(env);
+        processor.process();
+        Class clz = classLoader.loadClass("org.apache.header2.Header2Test");
+        Class headerData = classLoader.loadClass("org.apache.header2.HeaderData");
+        Class header = classLoader.loadClass("org.apache.header2.Header");
+        Method method = clz.getMethod("headerMethod", new Class[] {headerData, header});
      
+        assertNotNull("method should be generated", method);
+    }
+    
     private String getLocation(String wsdlFile) {
         return WSDLToJavaProcessorTest.class.getResource(wsdlFile).getFile();
     }

Modified: incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_schemas/references.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_schemas/references.xsd?view=diff&rev=469363&r1=469362&r2=469363
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_schemas/references.xsd
(original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_schemas/references.xsd
Mon Oct 30 20:13:34 2006
@@ -17,30 +17,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<!--
-     Copyright 2001-2004 IONA Technologies, PLC. All rights reserved.
 
-     This document and the information contained herein is provided on an
-     "AS IS" basis and to the maximum extent permitted by applicable law,
-     IONA provides the document AS IS AND WITH ALL FAULTS, and hereby
-     disclaims all other warranties and conditions, either express, implied
-     or statutory, including, but not limited to, any (if any) implied
-     warranties, duties or conditions of merchantability, of fitness for a
-     particular purpose, of accuracy or completeness of responses, of
-     results, of workmanlike effort, of lack of viruses, and of lack of
-     negligence, all with regard to the document. ALSO, THERE IS NO
-     WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, QUIET POSSESSION,
-     CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT WITH REGARD TO THE
-     DOCUMENT.
-
-     IN NO EVENT WILL IONA BE LIABLE TO ANY OTHER PARTY FOR THE COST OF
-     PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS OF USE,
-     LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, INDIRECT, OR
-     SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, OR OTHERWISE,
-     ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT RELATING TO THIS
-     DOCUMENT, WHETHER OR NOT SUCH PARTY HAD ADVANCE NOTICE OF THE
-     POSSIBILITY OF SUCH DAMAGES.  
--->
 <xs:schema targetNamespace="http://schemas.iona.com/references"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:ref="http://schemas.iona.com/references"

Added: incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl?view=auto&rev=469363
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
(added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
Mon Oct 30 20:13:34 2006
@@ -0,0 +1,94 @@
+<?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.
+-->
+
+<definitions name="header2" targetNamespace="http://apache.org/header2" 
+    xmlns="http://schemas.xmlsoap.org/wsdl/" 
+    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
+    xmlns:tns="http://apache.org/header2" 
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+    <types>
+        <schema targetNamespace="http://apache.org/header2" 
+            xmlns="http://www.w3.org/2001/XMLSchema" 
+            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+
+            <complexType name="HeaderData">
+                <sequence>
+                    <element maxOccurs="1" minOccurs="1" name="count" type="int"/>
+                </sequence>
+            </complexType>
+            <element name="HeaderInfo" type="tns:HeaderData"/>
+
+            <element name="Header">
+               <complexType>
+                    <sequence>
+                        <element name="requestType" type="xsd:string"/>
+                    </sequence>
+                </complexType>
+            </element>
+            <element name="HeaderResponse">
+               <complexType>
+                    <sequence>
+                        <element name="responseType" type="xsd:string"/>
+                    </sequence>
+                </complexType>
+            </element>
+        </schema>
+    </types>
+
+    <message name="headerRequest">
+        <part element="tns:HeaderInfo" name="header_info"/>
+        <part element="tns:Header" name="the_request"/>
+    </message>
+    <message name="headerResponse">
+        <part element="tns:HeaderResponse" name="the_response"/>
+    </message>
+
+    <portType name="header2Test">
+        <operation name="headerMethod">
+            <input message="tns:headerRequest" name="headerRequest"/>
+            <output message="tns:headerResponse" name="headerResponse"/>
+        </operation>
+    </portType>
+
+    <binding name="header2Binding" type="tns:header2Test">
+        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+        <operation name="headerMethod">
+            <soap:operation soapAction="" style="document"/>
+            <input name="headerRequest">
+                <soap:header message="tns:headerRequest" part="header_info" 
+                    use="literal"/>
+                <soap:body parts="the_request" use="literal"/>
+            </input>
+            <output name="headerResponse">
+                <soap:header message="tns:headerResponse" part="header_info" 
+                    use="literal"/>
+                <soap:body parts="the_response" use="literal"/>
+            </output>
+        </operation>
+    </binding>
+
+    <service name="Header2Service">
+        <port binding="tns:header2Binding" name="SoapPort">
+            <soap:address location="http://localhost:9000/header2"/>
+        </port>
+    </service>
+</definitions>

Propchange: incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/tools/wsdl2java/src/test/resources/wsdl2java_wsdl/bug161/header2.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message