You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by am...@apache.org on 2007/02/13 13:36:07 UTC

svn commit: r506985 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description: AxisService.java WSDL11ToAxisServiceBuilder.java WSDL20ToAxisServiceBuilder.java WSDLToAxisServiceBuilder.java

Author: amilas
Date: Tue Feb 13 04:36:05 2007
New Revision: 506985

URL: http://svn.apache.org/viewvc?view=rev&rev=506985
Log:
Add a method to AxisService to keep the operation order to be used in code generation

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDLToAxisServiceBuilder.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=506985&r1=506984&r2=506985
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Tue Feb 13 04:36:05 2007
@@ -194,6 +194,9 @@
     // name of the  binding used : use in codegeneration
     private String bindingName;
 
+    // names list keep to preserve the parameter order
+    private List operationsNameList;
+
     public AxisEndpoint getEndpoint(String key) {
         return (AxisEndpoint)endpointMap.get(key);
     }
@@ -1947,5 +1950,13 @@
 
     public void setCustomWsld(boolean customWsld) {
         this.customWsld = customWsld;
+    }
+
+    public List getOperationsNameList() {
+        return operationsNameList;
+    }
+
+    public void setOperationsNameList(List operationsNameList) {
+        this.operationsNameList = operationsNameList;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java?view=diff&rev=506985&r1=506984&r2=506985
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java Tue Feb 13 04:36:05 2007
@@ -362,6 +362,7 @@
         }
 
         AxisOperation axisOperation;
+        List operationNames = new ArrayList();
 
         QName opName;
         Operation wsdl4jOperation;
@@ -370,9 +371,8 @@
             wsdl4jOperation = (Operation) iterator.next();
 
             opName = new QName("", wsdl4jOperation.getName());
-
-            axisOperation = axisService.getOperation(new QName("", wsdl4jOperation.getName()));
-
+            axisOperation = axisService.getOperation(opName);
+            operationNames.add(opName);
             if (axisOperation == null) {
                 String mep = getMEP(wsdl4jOperation);
                 axisOperation = AxisOperationFactory.getOperationDescription(mep);
@@ -383,6 +383,11 @@
             populateOperation(axisOperation, wsdl4jPortType, wsdl4jOperation);
         }
 
+        // this is used only in codegen to perserve operation order
+        if (isCodegen){
+            axisService.setOperationsNameList(operationNames);
+        }
+
     }
 
     public void populateOperation(AxisOperation axisOperation, PortType wsdl4jPortType,
@@ -1462,8 +1467,7 @@
         // target namespace for this should be the namespace URI for
         // the porttype
         PortType portType = wsdl4jBinding.getPortType();
-        String porttypeNamespaceURI = wsdl4jBinding.getPortType().getQName()
-                .getNamespaceURI();
+        String porttypeNamespaceURI = wsdl4jBinding.getPortType().getQName().getNamespaceURI();
 
         // //////////////////////////////////////////////////////////////////////
         // if there are any bindings present then we have to process them. we
@@ -1502,9 +1506,9 @@
         // loop through the messages. We'll populate thins map with the relevant
         // messages
         // from the operations
-        Map name_to_msg = new HashMap();
-        Map OpeartionsToInputMessages = new HashMap();
-        Map op_to_output = new HashMap();
+        Map messageQnameToMessageMap = new HashMap();
+        Map operationToInputMessageMap = new HashMap();
+        Map operationToOutputMessageMap = new HashMap();
         Map faultyOperationsMap = new HashMap();
         // this contains the required namespace imports. the key in this
         // map would be the namaspace URI
@@ -1530,15 +1534,15 @@
             Message message;
             if (input != null) {
                 message = input.getMessage();
-                name_to_msg.put(message.getQName(), message);
-                OpeartionsToInputMessages.put(op.getName(), message);
+                messageQnameToMessageMap.put(message.getQName(), message);
+                operationToInputMessageMap.put(op, message);
             }
 
             Output output = op.getOutput();
             if (output != null) {
                 message = output.getMessage();
-                name_to_msg.put(message.getQName(), message);
-                op_to_output.put(op.getName(), message);
+                messageQnameToMessageMap.put(message.getQName(), message);
+                operationToOutputMessageMap.put(op, message);
             }
 
             Map faultMap = op.getFaults();
@@ -1549,7 +1553,7 @@
                     Fault fault = (Fault) faultMap.get(key);
                     if (fault != null) {
                         message = fault.getMessage();
-                        name_to_msg.put(message.getQName(), message);
+                        messageQnameToMessageMap.put(message.getQName(), message);
                         faultyOperationsMap.put(key, message);
                     }
                 }
@@ -1568,8 +1572,8 @@
         // just take all the messages and wrap them, we've already selected
         // the relevant messages by looking at the SOAP binding
 
-        keys = (QName[]) name_to_msg.keySet().toArray(
-                new QName[name_to_msg.size()]);
+        keys = (QName[]) messageQnameToMessageMap.keySet().toArray(
+                new QName[messageQnameToMessageMap.size()]);
 
         // /////////////////////////////////////////////////////////////////////////////////////////
         // Now we have the message list to process - Process the whole list of
@@ -1577,152 +1581,127 @@
         // since we need to generate one single schema
         // /////////////////////////////////////////////////////////////////////////////////////////
 
-        List resolved_msg_qnames = new ArrayList();
+        List resolvedMessageQnames = new ArrayList();
         // find the xsd prefix
         String xsdPrefix = findSchemaPrefix();
         Message wsdl4jMessage;
         // DOM document that will be the ultimate creator
         Document document = getDOMDocumentBuilder().newDocument();
         for (int i = 0; i < keys.length; i++) {
-            wsdl4jMessage = (Message) name_to_msg.get(keys[i]);
+            wsdl4jMessage = (Message) messageQnameToMessageMap.get(keys[i]);
             // No need to check the wrappable,
 
             // This message is wrappabel. However we need to see whether the
             // message is already
             // resolved!
-            if (!resolved_msg_qnames.contains(wsdl4jMessage.getQName())) {
+            if (!resolvedMessageQnames.contains(wsdl4jMessage.getQName())) {
                 // This message has not been touched before!. So we can go ahead
                 // now
                 Map parts = wsdl4jMessage.getParts();
-                // add the complex type
-                Element newComplexType = document.createElementNS(
-                        XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
-                        + XML_SCHEMA_COMPLEX_TYPE_LOCAL_NAME);
-
-                Element cmplxTypeSequence = document.createElementNS(
-                        XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
-                        + XML_SCHEMA_SEQUENCE_LOCAL_NAME);
-                Element child;
-                Iterator iterator = parts.keySet().iterator();
-
-                while (iterator.hasNext()) {
-                    Part part = (Part) parts.get(iterator.next());
-                    // the part name
-                    String elementName = part.getName();
-                    boolean isTyped = true;
-                    // the type name
-                    QName schemaTypeName;
-                    if (part.getTypeName() != null) {
-                        schemaTypeName = part.getTypeName();
-                    } else if (part.getElementName() != null) {
-                        schemaTypeName = part.getElementName();
-                        isTyped = false;
-                    } else {
-                        throw new RuntimeException(" Unqualified Message part!");
-                    }
-
-                    child = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
-                            xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME);
-
-                    String prefix;
-                    if (XMLSCHEMA_NAMESPACE_URI.equals(schemaTypeName
-                            .getNamespaceURI())) {
-                        prefix = xsdPrefix;
-                    } else {
-                        // this schema is a third party one. So we need to have
-                        // an import statement in our generated schema
-                        String uri = schemaTypeName.getNamespaceURI();
-                        if (!namespaceImportsMap.containsKey(uri)) {
-                            // create Element for namespace import
-                            Element namespaceImport = document.createElementNS(
-                                    XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
-                                    + XML_SCHEMA_IMPORT_LOCAL_NAME);
-                            namespaceImport.setAttribute(NAMESPACE_URI, uri);
-                            // add this to the map
-                            namespaceImportsMap.put(uri, namespaceImport);
-                            // we also need to associate this uri with a prefix
-                            // and include that prefix
-                            // in the schema's namspace declarations. So add
-                            // theis particular namespace to the
-                            // prefix map as well
-                            prefix = getTemporaryNamespacePrefix();
-                            namespacePrefixMap.put(uri, prefix);
-                        } else {
-                            // this URI should be already in the namspace prefix
-                            // map
-                            prefix = (String) namespacePrefixMap.get(uri);
-                        }
-
-                    }
-                    // If it's from a type the element we need to add a name and
-                    // the type
-                    // if not it's the element reference
-                    if (isTyped) {
-                        child.setAttribute(XSD_NAME, elementName);
-                        child.setAttribute(XSD_TYPE, prefix + ":"
-                                + schemaTypeName.getLocalPart());
-                    } else {
-                        child.setAttribute(XSD_REF, prefix + ":"
-                                + schemaTypeName.getLocalPart());
-                    }
-                    cmplxTypeSequence.appendChild(child);
-                }
-                newComplexType.appendChild(cmplxTypeSequence);
+                Element newComplexType = getNewComplextType(document,
+                        xsdPrefix,
+                        parts.values().iterator(),
+                        namespaceImportsMap,
+                        namespacePrefixMap);
                 // add this newly created complextype to the list
                 complexTypeElementsMap.put(wsdl4jMessage.getQName(),
                         newComplexType);
-                resolved_msg_qnames.add(wsdl4jMessage.getQName());
+                resolvedMessageQnames.add(wsdl4jMessage.getQName());
             }
 
         }
 
         Element elementDeclaration;
 
-        // loop through the input op map and generate the elements
-        String[] input_op_names = (String[]) OpeartionsToInputMessages.keySet()
-                .toArray(new String[OpeartionsToInputMessages.size()]);
-        for (int j = 0; j < input_op_names.length; j++) {
-            String input_op_name = input_op_names[j];
+        //loop through the input op map and generate the elements
+        Operation operation;
+        for (Iterator operationsIter = operationToInputMessageMap.keySet().iterator();
+             operationsIter.hasNext();){
+            operation = (Operation) operationsIter.next();
             elementDeclaration = document.createElementNS(
                     XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
                     + XML_SCHEMA_ELEMENT_LOCAL_NAME);
-            elementDeclaration.setAttribute(XSD_NAME, input_op_name);
+            elementDeclaration.setAttribute(XSD_NAME, operation.getName());
+            List parameterOrder = operation.getParameterOrdering();
+            Message message = (Message) operationToInputMessageMap.get(operation);
+
+            Node newComplexType;
+            if ((parameterOrder != null) && (parameterOrder.size() != 0)){
+                // create new complex element according to the parameter order given
+                newComplexType = getNewComplextType(document,
+                        xsdPrefix,
+                        message.getOrderedParts(parameterOrder).iterator(),
+                        namespaceImportsMap,
+                        namespacePrefixMap);
 
-            QName typeQName = ((Message) OpeartionsToInputMessages.get(input_op_name))
-                    .getQName();
-            // add the anonymous
-            elementDeclaration.appendChild(((Element) complexTypeElementsMap
-                    .get(typeQName)).cloneNode(true));
+            } else {
+                newComplexType = ((Element) complexTypeElementsMap.get(message.getQName())).cloneNode(true);
+            }
 
+            elementDeclaration.appendChild(newComplexType);
             elementElementsList.add(elementDeclaration);
-            resolvedRpcWrappedElementMap.put(input_op_name, new QName(
-                    namespaceURI, input_op_name, AXIS2WRAPPED));
-        }
+            resolvedRpcWrappedElementMap.put(operation.getName(), new QName(
+                    namespaceURI, operation.getName(), AXIS2WRAPPED));
 
-        // loop through the output op map and generate the elements
-        String[] outputOperationtNames = (String[]) op_to_output
-                .keySet().toArray(new String[op_to_output.size()]);
-        for (int j = 0; j < outputOperationtNames.length; j++) {
+        }
 
-            String baseoutputOpName = outputOperationtNames[j];
+        // loop through the output to map and generate the elements
+        for (Iterator operationsIterator = operationToOutputMessageMap.keySet().iterator();
+                operationsIterator.hasNext();){
+            operation = (Operation) operationsIterator.next();
+            String baseoutputOpName = operation.getName();
             String outputOpName = baseoutputOpName + WRAPPED_OUTPUTNAME_SUFFIX;
             elementDeclaration = document.createElementNS(
                     XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
                     + XML_SCHEMA_ELEMENT_LOCAL_NAME);
             elementDeclaration.setAttribute(XSD_NAME, outputOpName);
+            Message message = (Message) operationToOutputMessageMap.get(operation);
+            List parameterOrder = operation.getParameterOrdering();
 
-            QName typeQName = ((Message) op_to_output
-                    .get(baseoutputOpName)).getQName();
-            // add the anonymous
-            elementDeclaration.appendChild(((Element) complexTypeElementsMap
-                    .get(typeQName)).cloneNode(true));
-            elementElementsList.add(elementDeclaration);
+            Node newComplexType;
+            if ((parameterOrder != null) && (parameterOrder.size() != 0)){
+                // create new complex element according to the parameter order given
+                newComplexType = getNewComplextType(document,
+                        xsdPrefix,
+                        message.getOrderedParts(parameterOrder).iterator(),
+                        namespaceImportsMap,
+                        namespacePrefixMap);
 
-            resolvedRpcWrappedElementMap.put(outputOpName, new QName(
-                    namespaceURI, outputOpName, AXIS2WRAPPED));
+            } else {
+                newComplexType = ((Element) complexTypeElementsMap.get(message.getQName())).cloneNode(true);
+            }
+
+            elementDeclaration.appendChild(newComplexType);
+            elementElementsList.add(elementDeclaration);
+            resolvedRpcWrappedElementMap.put(outputOpName, new QName(namespaceURI, outputOpName, AXIS2WRAPPED));
 
         }
 
+
+        // loop through the output op map and generate the elements
+//        String[] outputOperationtNames = (String[]) operationToOutputMessageMap
+//                .keySet().toArray(new String[operationToOutputMessageMap.size()]);
+//        for (int j = 0; j < outputOperationtNames.length; j++) {
+//
+//            String baseoutputOpName = outputOperationtNames[j];
+//            String outputOpName = baseoutputOpName + WRAPPED_OUTPUTNAME_SUFFIX;
+//            elementDeclaration = document.createElementNS(
+//                    XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
+//                    + XML_SCHEMA_ELEMENT_LOCAL_NAME);
+//            elementDeclaration.setAttribute(XSD_NAME, outputOpName);
+//
+//            QName typeQName = ((Message) operationToOutputMessageMap
+//                    .get(baseoutputOpName)).getQName();
+//            // add the anonymous
+//            elementDeclaration.appendChild(((Element) complexTypeElementsMap
+//                    .get(typeQName)).cloneNode(true));
+//            elementElementsList.add(elementDeclaration);
+//
+//            resolvedRpcWrappedElementMap.put(outputOpName, new QName(
+//                    namespaceURI, outputOpName, AXIS2WRAPPED));
+//
+//        }
+
         // loop through the faultoutput op map and generate the elements
         String[] faultyOperationtNames = (String[]) faultyOperationsMap
                 .keySet().toArray(new String[faultyOperationsMap.size()]);
@@ -1839,6 +1818,98 @@
             return schemaElement;
         }
 
+    }
+
+    /**
+     * creates a new shema complex element according to the elements sequence difined
+     * @param document
+     * @param xsdPrefix
+     * @param partsIterator
+     * @param namespaceImportsMap
+     * @param namespacePrefixMap
+     * @return the new complex type element
+     */
+
+    private Element getNewComplextType(Document document,
+                                       String xsdPrefix,
+                                       Iterator partsIterator,
+                                       Map namespaceImportsMap,
+                                       Map namespacePrefixMap) {
+        // add the complex type
+        Element newComplexType = document.createElementNS(
+                XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
+                + XML_SCHEMA_COMPLEX_TYPE_LOCAL_NAME);
+
+        Element cmplxTypeSequence = document.createElementNS(
+                XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
+                + XML_SCHEMA_SEQUENCE_LOCAL_NAME);
+        Element child;
+        Part part;
+
+        while (partsIterator.hasNext()) {
+            part = (Part) partsIterator.next();
+            // the part name
+            String elementName = part.getName();
+            boolean isTyped = true;
+            // the type name
+            QName schemaTypeName;
+            if (part.getTypeName() != null) {
+                schemaTypeName = part.getTypeName();
+            } else if (part.getElementName() != null) {
+                schemaTypeName = part.getElementName();
+                isTyped = false;
+            } else {
+                throw new RuntimeException(" Unqualified Message part!");
+            }
+
+            child = document.createElementNS(XMLSCHEMA_NAMESPACE_URI,
+                    xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME);
+
+            String prefix;
+            if (XMLSCHEMA_NAMESPACE_URI.equals(schemaTypeName
+                    .getNamespaceURI())) {
+                prefix = xsdPrefix;
+            } else {
+                // this schema is a third party one. So we need to have
+                // an import statement in our generated schema
+                String uri = schemaTypeName.getNamespaceURI();
+                if (!namespaceImportsMap.containsKey(uri)) {
+                    // create Element for namespace import
+                    Element namespaceImport = document.createElementNS(
+                            XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":"
+                            + XML_SCHEMA_IMPORT_LOCAL_NAME);
+                    namespaceImport.setAttribute(NAMESPACE_URI, uri);
+                    // add this to the map
+                    namespaceImportsMap.put(uri, namespaceImport);
+                    // we also need to associate this uri with a prefix
+                    // and include that prefix
+                    // in the schema's namspace declarations. So add
+                    // theis particular namespace to the
+                    // prefix map as well
+                    prefix = getTemporaryNamespacePrefix();
+                    namespacePrefixMap.put(uri, prefix);
+                } else {
+                    // this URI should be already in the namspace prefix
+                    // map
+                    prefix = (String) namespacePrefixMap.get(uri);
+                }
+
+            }
+            // If it's from a type the element we need to add a name and
+            // the type
+            // if not it's the element reference
+            if (isTyped) {
+                child.setAttribute(XSD_NAME, elementName);
+                child.setAttribute(XSD_TYPE, prefix + ":"
+                        + schemaTypeName.getLocalPart());
+            } else {
+                child.setAttribute(XSD_REF, prefix + ":"
+                        + schemaTypeName.getLocalPart());
+            }
+            cmplxTypeSequence.appendChild(child);
+        }
+        newComplexType.appendChild(cmplxTypeSequence);
+        return newComplexType;
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java?view=diff&rev=506985&r1=506984&r2=506985
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java Tue Feb 13 04:36:05 2007
@@ -59,11 +59,7 @@
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.*;
 
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -768,10 +764,18 @@
         // copyExtensionAttributes(wsdl4jPortType.getExtensionAttributes(),
         // axisService, PORT_TYPE);
 
+        List operationNames = new ArrayList();
+
+
         InterfaceOperation[] interfaceOperations = serviceInterface
                 .getInterfaceOperations();
         for (int i = 0; i < interfaceOperations.length; i++) {
             axisService.addOperation(populateOperations(interfaceOperations[i]));
+            operationNames.add(interfaceOperations[i].getName());
+        }
+
+        if (isCodegen){
+            axisService.setOperationsNameList(operationNames);
         }
 
         Interface[] extendedInterfaces = serviceInterface.getExtendedInterfaces();

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDLToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDLToAxisServiceBuilder.java?view=diff&rev=506985&r1=506984&r2=506985
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDLToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDLToAxisServiceBuilder.java Tue Feb 13 04:36:05 2007
@@ -80,6 +80,9 @@
     private URIResolver customResolver;
     private String baseUri = null;
     protected static final String TYPES = "Types";
+
+    // keeping whether builder is used in codegen or not
+    protected boolean isCodegen;
     
     protected WSDLToAxisServiceBuilder(){
         
@@ -185,5 +188,13 @@
 
     public void setBaseUri(String baseUri) {
         this.baseUri = baseUri;
+    }
+
+    public boolean isCodegen() {
+        return isCodegen;
+    }
+
+    public void setCodegen(boolean codegen) {
+        isCodegen = codegen;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org