incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r515554 - in /incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools: common/idltypes/IdlScopeBase.java processors/wsdl/WSDLParameter.java
Date Wed, 07 Mar 2007 12:44:32 GMT
Author: bravi
Date: Wed Mar  7 04:44:31 2007
New Revision: 515554

URL: http://svn.apache.org/viewvc?view=rev&rev=515554
Log:
[YOKO-305] - Fix to WSDLToIDL to handle doc-literal wsdl's.

Modified:
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlScopeBase.java
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlScopeBase.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlScopeBase.java?view=diff&rev=515554&r1=515553&r2=515554
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlScopeBase.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlScopeBase.java
Wed Mar  7 04:44:31 2007
@@ -74,44 +74,46 @@
 
 
     public IdlDefn lookup(String nm, boolean undefined) {
-        Iterator it = park.iterator();
+        IdlDefn result = null;
+        Iterator it = park.iterator();       
 
         while (it.hasNext()) {
             IdlDefn nextDef = (IdlDefn)it.next();
-
             if (nextDef.localName().equals(nm)) {
-                return nextDef;
+                result = nextDef;
+                break;
             }
         }
 
-        it = hold.iterator();      
-
-        while (it.hasNext()) {
-            IdlDefn nextDef = (IdlDefn)it.next();
+        if (result == null) {
+            it = hold.iterator();      
 
-            if (nextDef.localName().equals(nm)) {
-                return nextDef;
+            while (it.hasNext()) {
+                IdlDefn nextDef = (IdlDefn)it.next();
+                if (nextDef.localName().equals(nm)) {
+                    result = nextDef;
+                    break;
+                }
             }
         }
 
         if (undefined) {
-            return null;
+            return result;
         }
         
         it = defns.iterator();
 
         while (it.hasNext()) {
             IdlDefn nextDef = (IdlDefn)it.next();
-
             if (nextDef.localName().equals(nm)) {
-                return nextDef;
+                result = nextDef;
+                break;
             }
         }
 
-        return null;
+        return result;
     }
 
-
     public IdlDefn lookup(IdlScopedName name) {
         return lookup(name, false);
     }
@@ -139,7 +141,6 @@
     public IdlDefn lookup(String scopedName[]) {
         return lookup(scopedName, false);
     }
-
 
     public IdlDefn lookup(String scopedName[], boolean undefined) {
         IdlScopeBase scope = this;

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java?view=diff&rev=515554&r1=515553&r2=515554
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java
Wed Mar  7 04:44:31 2007
@@ -37,17 +37,12 @@
 import org.apache.schemas.yoko.bindings.corba.ParamType;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAnnotation;
-import org.apache.ws.commons.schema.XmlSchemaChoice;
-import org.apache.ws.commons.schema.XmlSchemaComplexContent;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaContentModel;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaImport;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
-import org.apache.ws.commons.schema.XmlSchemaParticle;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
@@ -65,17 +60,16 @@
         List<ParamType> inputs = new ArrayList<ParamType>();
         List<ParamType> outputs = new ArrayList<ParamType>();
         List<ArgType> returnOutputs = new ArrayList<ArgType>();
+        boolean isWrapped = isWrappedOperation(operation, xmlSchemaList);
 
-        if (inputPartsHaveNoDocWrapper(operation.getName(), operation,
-                xmlSchemaList)) {
+        if (isWrapped) {
             processWrappedInputParams(wsdlToCorbaBinding, operation,
                     xmlSchemaList, inputs);
         } else {
             processInputParams(wsdlToCorbaBinding, operation, xmlSchemaList,
                     inputs);
         }
-        if (outputPartsHaveNoDocWrapper(operation.getName(), operation,
-                xmlSchemaList)) {
+        if (isWrapped) {
             processWrappedOutputParams(wsdlToCorbaBinding, operation,
                     xmlSchemaList, inputs, outputs);
         } else {
@@ -89,67 +83,55 @@
 
     }
 
-    private void processWrappedInputParams(
-            WSDLToCorbaBinding wsdlToCorbaBinding, Operation operation,
-            List<XmlSchema> xmlSchemaList, List<ParamType> inputs)
+    private void processWrappedInputParams(WSDLToCorbaBinding wsdlToCorbaBinding,
+                                           Operation operation,
+                                           List<XmlSchema> xmlSchemaList,
+                                           List<ParamType> inputs)
         throws Exception {
         Input input = operation.getInput();
 
         if (input != null) {
             Message msg = input.getMessage();
-            Iterator i = msg.getOrderedParts(null).iterator();
-            while (i.hasNext()) {
-                Part part = (Part) i.next();
-                XmlSchemaType schemaType = null;
-                schemaType = lookUpType(part, xmlSchemaList);
-                if (part.getElementName() != null) {
-                    // its an anonymous type
-                    if (schemaType instanceof XmlSchemaComplexType
-                            && schemaType.getName() == null) {
-                        Iterator it = getSchemaIterator(schemaType);
-                        Iterator iter = getSchemaIterator(schemaType);
-                        addParams(wsdlToCorbaBinding, inputs, it, iter);
-                    } else {
-                        XmlSchemaElement el = getElement(part, xmlSchemaList);
-                        if (schemaType == null) {
-                            addParam(wsdlToCorbaBinding, schemaType, part
-                                    .getName(), el.getSchemaTypeName(), el
-                                    .isNillable(), inputs);
-                        } else {
-                            addParam(wsdlToCorbaBinding, schemaType, part
-                                    .getName(), part.getElementName(), el
-                                    .isNillable(), inputs);
-                        }
-                    }
-                } else {
-                    if (part.getTypeName() != null) {
-                        addParam(wsdlToCorbaBinding, schemaType,
-                                part.getName(), part.getTypeName(), false,
-                                inputs);
-                    }
-                }
-            }
-        }
-    }
+            Part part = (Part) msg.getOrderedParts(null).iterator().next();
 
-    private void addParams(WSDLToCorbaBinding wsdlToCorbaBinding,
-            List<ParamType> inputs, Iterator it, Iterator iter)
-        throws Exception {
-        if (it != null) {
-            while (it.hasNext()) {
-                if (it.next() instanceof XmlSchemaElement) {
-                    XmlSchemaElement el = (XmlSchemaElement) iter.next();
-                    addParam(wsdlToCorbaBinding, el.getSchemaType(), el
-                            .getQName().getLocalPart(), el.getSchemaTypeName(),
-                            el.isNillable(), inputs);
+            XmlSchemaComplexType schemaType = null;
+
+            XmlSchemaElement el = getElement(part, xmlSchemaList);
+            if ((el != null) && (el.getSchemaType() != null)) {
+                schemaType = (XmlSchemaComplexType) el.getSchemaType();
+            }
+          
+            XmlSchemaSequence seq = (XmlSchemaSequence) schemaType.getParticle();
+            if (seq != null) {
+                XmlSchemaObjectCollection items = seq.getItems();
+                for (int i = 0; i < items.getCount(); i++) {
+                    el = (XmlSchemaElement) items.getItem(i);
+                    //REVISIT, handle element ref's?
+                    QName typeName = el.getSchemaTypeName();
+                    if (typeName == null) {
+                        typeName = el.getQName();
+                    }
+                    QName idltype = getIdlType(wsdlToCorbaBinding,
+                                               el.getSchemaType(),
+                                               typeName,
+                                               el.isNillable());
+                    ParamType paramtype = createParam(wsdlToCorbaBinding,
+                                                      "in",
+                                                      el.getQName().getLocalPart(),
+                                                      idltype);
+                    if (paramtype != null) {
+                        inputs.add(paramtype);
+                    }
                 }
-            }
+            }       
         }
     }
 
     private void processInputParams(WSDLToCorbaBinding wsdlToCorbaBinding,
-            Operation operation, List<XmlSchema> xmlSchemaList,
-            List<ParamType> inputs) throws Exception {
+                                    Operation operation,
+                                    List<XmlSchema> xmlSchemaList,
+                                    List<ParamType> inputs)
+        throws Exception {
 
         Input input = operation.getInput();
 
@@ -159,29 +141,44 @@
             while (i.hasNext()) {
                 Part part = (Part) i.next();
                 XmlSchemaType schemaType = null;
-                schemaType = lookUpType(part, xmlSchemaList);
                 if (part.getElementName() != null) {
                     XmlSchemaElement el = getElement(part, xmlSchemaList);
-                    addParam(wsdlToCorbaBinding, schemaType, part.getName(),
-                            part.getElementName(), el.isNillable(), inputs);
+                    if ((el != null) && (el.getSchemaType() != null)) {
+                        schemaType = el.getSchemaType();
+                    }
+                    QName typeName = el.getSchemaTypeName();
+                    if (typeName == null) {
+                        typeName = el.getQName();
+                    }
+                    QName idltype = getIdlType(wsdlToCorbaBinding,
+                                               schemaType,
+                                               typeName,
+                                               el.isNillable());
+                    ParamType paramtype = createParam(wsdlToCorbaBinding,
+                                                      "in",
+                                                      part.getName(),
+                                                      idltype);
+                    if (paramtype != null) {
+                        inputs.add(paramtype);
+                    }
                 } else if (part.getTypeName() != null) {
-                    addParam(wsdlToCorbaBinding, schemaType, part.getName(),
-                            part.getTypeName(), false, inputs);
+                    schemaType = getType(part, xmlSchemaList);
+                    QName idltype = getIdlType(wsdlToCorbaBinding,
+                                               schemaType,
+                                               part.getTypeName(),
+                                               false);
+                    ParamType paramtype = createParam(wsdlToCorbaBinding,
+                                                      "in",
+                                                      part.getName(),
+                                                      idltype);
+                    if (paramtype != null) {
+                        inputs.add(paramtype);
+                    }
                 }
             }
         }
     }
 
-    private void addParam(WSDLToCorbaBinding wsdlToCorbaBinding,
-            XmlSchemaType schemaType, String name, QName typeName,
-            boolean nillable, List<ParamType> inputs) throws Exception {
-        ParamType paramtype = createParam(wsdlToCorbaBinding, "in", schemaType,
-                name, typeName, nillable);
-        if (paramtype != null) {
-            inputs.add(paramtype);
-        }
-    }
-
     private void processWrappedOutputParams(
             WSDLToCorbaBinding wsdlToCorbaBinding, Operation operation,
             List<XmlSchema> xmlSchemaList, List<ParamType> inputs,
@@ -191,56 +188,65 @@
 
         if (output != null) {
             Message msg = output.getMessage();
-            Iterator i = msg.getOrderedParts(null).iterator();
-            while (i.hasNext()) {
-                Part part = (Part) i.next();
-                XmlSchemaType schemaType = null;
-                schemaType = lookUpType(part, xmlSchemaList);
+            Part part = (Part) msg.getOrderedParts(null).iterator().next();
+            XmlSchemaComplexType schemaType = null;
 
-                // check if in input list
-                if (part.getElementName() != null) {
-                    if (schemaType instanceof XmlSchemaComplexType
-                            && schemaType.getName() == null) {
-                        Iterator it = getSchemaIterator(schemaType);
-                        Iterator iter = getSchemaIterator(schemaType);
-                        updateLists(wsdlToCorbaBinding, inputs, outputs, it,
-                                iter);
-                    } else {
-                        XmlSchemaElement el = getElement(part, xmlSchemaList);
-                        if (schemaType == null) {
-                            updateList(wsdlToCorbaBinding, schemaType, part
-                                    .getName(), el.getSchemaTypeName(), inputs,
-                                    outputs, el.isNillable());
-                        } else {
-                            updateList(wsdlToCorbaBinding, schemaType, part
-                                    .getName(), part.getElementName(), inputs,
-                                    outputs, el.isNillable());
-                        }
-                    }
-                } else {
-                    if (part.getTypeName() != null) {
-                        updateList(wsdlToCorbaBinding, schemaType, part
-                                .getName(), part.getTypeName(), inputs,
-                                outputs, false);
-                    }
-                }
+            XmlSchemaElement el = getElement(part, xmlSchemaList);
+            if (el != null && el.getSchemaType() != null) {
+                schemaType = (XmlSchemaComplexType) el.getSchemaType();
+            }
+            XmlSchemaSequence seq = (XmlSchemaSequence) schemaType.getParticle();
+            XmlSchemaObjectCollection items = seq.getItems();
+            for (int i = 0; i < items.getCount(); i++) {
+                el = (XmlSchemaElement) items.getItem(i);
+                processWrappedOutputParam(wsdlToCorbaBinding, el, inputs, outputs);
             }
         }
     }
 
-    private void updateLists(WSDLToCorbaBinding wsdlToCorbaBinding,
-            List<ParamType> inputs, List<ParamType> outputs, Iterator it,
-            Iterator iter) throws Exception {
-        if (it != null) {
-            while (it.hasNext()) {
-                if (it.next() instanceof XmlSchemaElement) {
-                    XmlSchemaElement el = (XmlSchemaElement) iter.next();
-                    updateList(wsdlToCorbaBinding, el.getSchemaType(), el
-                            .getQName().getLocalPart(), el.getSchemaTypeName(),
-                            inputs, outputs, el.isNillable());
+    private void processWrappedOutputParam(WSDLToCorbaBinding wsdlToCorbaBinding,
+                                           XmlSchemaElement el,
+                                           List<ParamType> inputs,
+                                           List<ParamType> outputs)
+        throws Exception {
+        ParamType paramtype = null;
+        for (int i = 0; i < inputs.size(); i++) {
+            if (inputs.get(i).getName().equals(el.getQName().getLocalPart())) {
+                inputs.remove(i);
+                QName typeName = el.getSchemaTypeName();
+                if (typeName == null) {
+                    typeName = el.getQName();
+                }
+                QName idltype = getIdlType(wsdlToCorbaBinding,
+                                           el.getSchemaType(),
+                                           typeName,
+                                           el.isNillable());
+                paramtype = createParam(wsdlToCorbaBinding,
+                                        "inout",
+                                        el.getQName().getLocalPart(),
+                                        idltype);
+                if (paramtype != null) {
+                    inputs.add(paramtype);
                 }
             }
         }
+        if (paramtype == null) {
+            QName typeName = el.getSchemaTypeName();
+            if (typeName == null) {
+                typeName = el.getQName();
+            }
+            QName idltype = getIdlType(wsdlToCorbaBinding,
+                                       el.getSchemaType(),
+                                       typeName,
+                                       el.isNillable());
+            paramtype = createParam(wsdlToCorbaBinding,
+                                    "out",
+                                    el.getQName().getLocalPart(),
+                                    idltype);
+            if (paramtype != null) {
+                outputs.add(paramtype);
+            }
+        }
     }
 
     private void processOutputParams(WSDLToCorbaBinding wsdlToCorbaBinding,
@@ -255,42 +261,76 @@
             while (i.hasNext()) {
                 Part part = (Part) i.next();
                 XmlSchemaType schemaType = null;
-                schemaType = lookUpType(part, xmlSchemaList);
-
                 // check if in input list
                 String mode = "out";
                 ParamType paramtype = null;
                 for (int x = 0; x < inputs.size(); x++) {
                     paramtype = null;
                     ParamType d2 = (ParamType) inputs.get(x);
-
-                    if (part.getName() != null
-                            && d2.getName().equals(part.getName())) {
-                        inputs.remove(x);
-                        if (part.getElementName() != null) {
-                            XmlSchemaElement el = getElement(part,
-                                    xmlSchemaList);
+                    if (part.getElementName() != null) {
+                        XmlSchemaElement el = getElement(part,
+                                                         xmlSchemaList);
+                        if (el != null && el.getSchemaType() != null) {
+                            schemaType = el.getSchemaType();
+                        }
+                        QName typeName = el.getSchemaTypeName();
+                        if (typeName == null) {
+                            typeName = el.getQName();
+                        }
+                        QName idltype = getIdlType(wsdlToCorbaBinding,
+                                                   schemaType,
+                                                   typeName,
+                                                   el.isNillable());
+                        if ((d2.getName().equals(part.getName()))
+                            && (d2.getIdltype().equals(idltype))) {
+                            inputs.remove(x);
                             paramtype = createParam(wsdlToCorbaBinding,
-                                    "inout", schemaType, part.getName(), part
-                                            .getElementName(), el.isNillable());
-                        } else {
+                                                    "inout",
+                                                    part.getName(),
+                                                    idltype);
+                            inputs.add(paramtype);
+                        }
+                    } else {
+                        schemaType = getType(part, xmlSchemaList);
+                        QName idltype = getIdlType(wsdlToCorbaBinding,
+                                                   schemaType,
+                                                   part.getTypeName(),
+                                                   false);
+                        if ((d2.getName().equals(part.getName()))
+                            && (d2.getIdltype().equals(idltype))) {
+                            inputs.remove(x);
                             paramtype = createParam(wsdlToCorbaBinding,
-                                    "inout", schemaType, part.getName(), part
-                                            .getTypeName(), false);
+                                                    "inout",
+                                                    part.getName(),
+                                                    idltype);
+                            inputs.add(paramtype);
                         }
-                        inputs.add(paramtype);
                     }
                 }
                 if (paramtype == null) {
                     if (part.getElementName() != null) {
                         XmlSchemaElement el = getElement(part, xmlSchemaList);
-                        paramtype = createParam(wsdlToCorbaBinding, mode,
-                                schemaType, part.getName(), part
-                                        .getElementName(), el.isNillable());
+                        QName typeName = el.getSchemaTypeName();
+                        if (typeName == null) {
+                            typeName = el.getQName();
+                        }
+                        QName idltype = getIdlType(wsdlToCorbaBinding,
+                                                   schemaType,
+                                                   typeName,
+                                                   el.isNillable());
+                        paramtype = createParam(wsdlToCorbaBinding,
+                                                mode,
+                                                part.getName(),
+                                                idltype);
                     } else {
-                        paramtype = createParam(wsdlToCorbaBinding, mode,
-                                schemaType, part.getName(), part.getTypeName(),
-                                false);
+                        QName idltype = getIdlType(wsdlToCorbaBinding,
+                                                   schemaType,
+                                                   part.getTypeName(),
+                                                   false);
+                        paramtype = createParam(wsdlToCorbaBinding,
+                                                mode,
+                                                part.getName(),
+                                                idltype);
                     }
                     if (paramtype != null) {
                         outputs.add(paramtype);
@@ -301,7 +341,7 @@
     }
 
     private void processReturnParams(List<ParamType> outputs,
-            List<ArgType> returns) {
+                                     List<ArgType> returns) {
 
         if (outputs.size() > 0) {
             ParamType d2 = (ParamType) outputs.get(0);
@@ -352,134 +392,43 @@
         }
     }
 
-    private void updateList(WSDLToCorbaBinding wsdlToCorbaBinding,
-            XmlSchemaType schemaType, String name, QName typeName,
-            List<ParamType> inputs, List<ParamType> outputs, boolean nillable)
+    private static XmlSchemaType getType(Part part,
+                                         List<XmlSchema> xmlSchemaList)
         throws Exception {
-
-        ParamType paramtype = null;
-
-        for (int x = 0; x < inputs.size(); x++) {
-            paramtype = null;
-            ParamType d2 = (ParamType) inputs.get(x);
-
-            if (d2.getName().equals(name)) {
-                inputs.remove(x);
-                paramtype = createParam(wsdlToCorbaBinding, "inout",
-                        schemaType, name, typeName, nillable);
-                if (paramtype != null) {
-                    inputs.add(paramtype);
-                }
-            }
-        }
-        if (paramtype == null) {            
-            paramtype = createParam(wsdlToCorbaBinding, "out", schemaType,
-                    name, typeName, nillable);
-            if (paramtype != null) {
-                outputs.add(paramtype);
-            }
-        }
-
-    }
-
-    private Iterator getSchemaIterator(XmlSchemaType schemaType) {
-
-        if (schemaType instanceof XmlSchemaComplexType) {
-            XmlSchemaComplexType cpt = (XmlSchemaComplexType) schemaType;
-            XmlSchemaParticle particle = null;
-            if (cpt.getParticle() != null) {
-                particle = (XmlSchemaParticle) cpt.getParticle();
-
-                if (particle instanceof XmlSchemaSequence) {
-                    XmlSchemaSequence seq = (XmlSchemaSequence) particle;
-                    return seq.getItems().getIterator();
-                } else if (particle instanceof XmlSchemaChoice) {
-                    XmlSchemaChoice choice = (XmlSchemaChoice) particle;
-                    return choice.getItems().getIterator();
-                }
-            }
-            if (cpt.getContentModel() != null) {
-                XmlSchemaContentModel xscm = (XmlSchemaContentModel) cpt
-                        .getContentModel();
-                if (xscm instanceof XmlSchemaComplexContent) {
-                    XmlSchemaComplexContent xscc = (XmlSchemaComplexContent) xscm;
-
-                    XmlSchemaComplexContentExtension ext = null;
-                    if (xscc.getContent() instanceof XmlSchemaComplexContentExtension) {
-                        ext = (XmlSchemaComplexContentExtension) xscc
-                                .getContent();
-                    }
-                    if (ext.getParticle() instanceof XmlSchemaSequence) {
-                        XmlSchemaSequence seq = (XmlSchemaSequence) ext
-                                .getParticle();
-                        return seq.getItems().getIterator();
-                    } else if (ext.getParticle() instanceof XmlSchemaChoice) {
-                        XmlSchemaChoice choice = (XmlSchemaChoice) ext
-                                .getParticle();
-                        return choice.getItems().getIterator();
-                    }
-                }
-            }
-        }
-        return null;
-    }
-
-    private static XmlSchemaType lookUpType(Part part,
-            List<XmlSchema> xmlSchemaList) throws Exception {
         XmlSchemaType schemaType = null;
 
         Iterator i = xmlSchemaList.iterator();
         while (i.hasNext()) {
             XmlSchema xmlSchemaType = (XmlSchema) i.next();
 
-            if (part.getElementName() != null) {
-                XmlSchemaElement schemaElement = xmlSchemaType
-                        .getElementByName(part.getElementName());
-                if (schemaElement == null) {
-                    QName elName = part.getElementName();
-                    String prefix = definition.getPrefix(elName
-                            .getNamespaceURI());
-                    QName name = new QName(elName.getNamespaceURI(), prefix
-                            + ":" + elName.getLocalPart(), prefix);
-                    schemaElement = xmlSchemaType.getElementByName(name);
-                }
-                if (schemaElement != null) {
-                    if (schemaElement.getSchemaType() != null) {
-                        schemaType = schemaElement.getSchemaType();
-                    }
-                }
-            } else {
-                if (part.getTypeName() != null) {
-                    schemaType = xmlSchemaType
-                            .getTypeByName(part.getTypeName());
-
-                    // Endpoint reference types will give a null schemaType
-                    // here, so we need to
-                    // go through the list of imports to find the definition for
-                    // an Endpoint
-                    // reference type.
-
-                    if (schemaType == null
-                            && xmlSchemaType.getIncludes().getCount() > 0) {
-                        XmlSchemaObjectCollection includes = xmlSchemaType
-                                .getIncludes();
-                        Iterator includeIter = includes.getIterator();
-                        while (includeIter.hasNext()) {
-                            Object obj = includeIter.next();
-                            if (!(obj instanceof XmlSchemaImport)) {
-                                continue;
-                            }
-                            XmlSchemaImport xmlImport = (XmlSchemaImport) obj;
-                            if (xmlImport.getNamespace().equals(
-                                    part.getTypeName().getNamespaceURI())) {
-                                XmlSchema importSchema = xmlImport.getSchema();
-                                schemaType = importSchema.getTypeByName(part
-                                        .getTypeName());
-                            }
+            if (part.getTypeName() != null) {
+                schemaType = xmlSchemaType
+                    .getTypeByName(part.getTypeName());
+
+                // Endpoint reference types will give a null schemaType
+                // here, so we need to
+                // go through the list of imports to find the definition for
+                // an Endpoint
+                // reference type.
+                
+                if (schemaType == null
+                    && xmlSchemaType.getIncludes().getCount() > 0) {
+                    XmlSchemaObjectCollection includes = xmlSchemaType
+                        .getIncludes();
+                    Iterator includeIter = includes.getIterator();
+                    while (includeIter.hasNext()) {
+                        Object obj = includeIter.next();
+                        if (!(obj instanceof XmlSchemaImport)) {
+                            continue;
+                        }
+                        XmlSchemaImport xmlImport = (XmlSchemaImport) obj;
+                        if (xmlImport.getNamespace().equals(part.getTypeName().getNamespaceURI()))
{
+                            XmlSchema importSchema = xmlImport.getSchema();
+                            schemaType = importSchema.getTypeByName(part.getTypeName());
                         }
                     }
-
                 }
+                
             }
             if (schemaType != null) {
                 return schemaType;
@@ -489,7 +438,8 @@
     }
 
     private static XmlSchemaElement getElement(Part part,
-            List<XmlSchema> xmlSchemaList) throws Exception {
+                                               List<XmlSchema> xmlSchemaList)
+        throws Exception {
         XmlSchemaElement schemaElement = null;
 
         Iterator i = xmlSchemaList.iterator();
@@ -514,28 +464,21 @@
         return schemaElement;
     }
 
-    private static ParamType createParam(WSDLToCorbaBinding wsdlToCorbaBinding,
-            String mode, XmlSchemaType schemaType, String name, QName typeName,
-            boolean nill) throws Exception {
-
+    private static QName getIdlType(WSDLToCorbaBinding wsdlToCorbaBinding,
+                                    XmlSchemaType schemaType,
+                                    QName typeName,
+                                    boolean nill)
+        throws Exception {
+        QName idltype = null;
         CorbaTypeImpl corbaTypeImpl = null;
-        ParamType paramtype = new ParamType();
-
-        ModeType modeType = ModeType.fromValue(mode);
-        paramtype.setName(name);
-        paramtype.setMode(modeType);
-
         if (schemaType == null) {
-            corbaTypeImpl = (CorbaTypeImpl) WSDLToCorbaHelper.CORBAPRIMITIVEMAP
-                    .get(typeName);
+            corbaTypeImpl = (CorbaTypeImpl) WSDLToCorbaHelper.CORBAPRIMITIVEMAP.get(typeName);
             if (nill) {
                 QName qname = corbaTypeImpl.getQName();
-                qname = wsdlToCorbaBinding.getHelper()
-                        .createQNameCorbaNamespace(
-                                qname.getLocalPart() + "_nil");
-                paramtype.setIdltype(qname);
+                idltype =
+                    wsdlToCorbaBinding.getHelper().createQNameCorbaNamespace(qname.getLocalPart()
+ "_nil");
             } else {
-                paramtype.setIdltype(corbaTypeImpl.getQName());
+                idltype = corbaTypeImpl.getQName();
             }
         } else {
             // We need to get annotation information for the schema type we are about to
pass in. 
@@ -557,131 +500,169 @@
                 annotation = ((XmlSchemaElement)schemaObj).getAnnotation();
             }
             
-            corbaTypeImpl = wsdlToCorbaBinding.getHelper()
-                    .convertSchemaToCorbaType(schemaType, typeName, null, annotation, false);
+            corbaTypeImpl =
+                wsdlToCorbaBinding.getHelper().convertSchemaToCorbaType(schemaType,
+                                                                        typeName,
+                                                                        null,
+                                                                        annotation,
+                                                                        false);
             if (corbaTypeImpl == null) {
-                return null;
+                throw new Exception("Couldn't convert schema type to corba type : " + typeName);
             } else {
                 if (nill) {
                     QName qname = corbaTypeImpl.getQName();
-                    qname = wsdlToCorbaBinding.getHelper()
-                            .createQNameCorbaNamespace(
-                                    qname.getLocalPart() + "_nil");
-                    paramtype.setIdltype(qname);
+                    idltype =
+                        wsdlToCorbaBinding.getHelper().createQNameCorbaNamespace(qname.getLocalPart()
+                                                                                 + "_nil");
                 } else {
-                    paramtype.setIdltype(corbaTypeImpl.getQName());
+                    idltype = corbaTypeImpl.getQName();
                 }
             }
-            return paramtype;
         }
-        return paramtype;
+        return idltype;
     }
 
-    private static boolean inputPartsHaveNoDocWrapper(String opName,
-            Operation operation, List<XmlSchema> xmlSchemaList)
-        throws Exception {
 
-        XmlSchemaType schemaType = null;
-        Iterator i = null;
-        Input input = operation.getInput();
+    private static ParamType createParam(WSDLToCorbaBinding wsdlToCorbaBinding,
+                                         String mode,
+                                         String name,
+                                         QName idltype)
+        throws Exception {
+        ParamType paramtype = new ParamType();
+        ModeType modeType = ModeType.fromValue(mode);
+        paramtype.setName(name);
+        paramtype.setMode(modeType);
+        paramtype.setIdltype(idltype);
+        return paramtype;
+    }
 
-        if (input != null) {
-            Message msg = input.getMessage();
-            i = msg.getParts().values().iterator();
+    private boolean isWrappedOperation(Operation op, List<XmlSchema> xmlSchemaList)
+        throws Exception {
+        Message inputMessage = op.getInput().getMessage();
+        Message outputMessage = null;
+        if (op.getOutput() != null) {
+            outputMessage = op.getOutput().getMessage();
+        }
 
-            if (msg.getParts().size() == 0) {
-                return false;
-            }
+        boolean passedRule = true;
 
-            Part part = (Part) i.next();
+        // RULE No.1:
+        // The operation's input and output message (if present) each contain
+        // only a single part
+        // input message must exist
+        if (inputMessage == null || inputMessage.getParts().size() != 1
+            || (outputMessage != null && outputMessage.getParts().size() > 1))
{
+            passedRule = false;
+        }
 
-            if (i.hasNext()) {
-                return true;
-            }
+        if (!passedRule) {
+            return false;
+        }
 
-            schemaType = lookUpType(part, xmlSchemaList);
-            if (!(part.getName().equals(opName))) {
-                return true;
-            }
+        XmlSchemaElement inputEl = null;
+        XmlSchemaElement outputEl = null;
 
-            if (!(schemaType instanceof XmlSchemaComplexType)) {
-                return true;
+        // RULE No.2:
+        // The input message part refers to a global element decalration whose
+        // localname
+        // is equal to the operation name
+        Part inputPart = (Part) inputMessage.getParts().values().iterator().next();
+        if (inputPart.getElementName() == null) {
+            passedRule = false;
+        } else {
+            QName inputElementName = inputPart.getElementName();
+            inputEl = getElement(inputPart, xmlSchemaList);
+            if (inputEl == null || !op.getName().equals(inputElementName.getLocalPart()))
{
+                passedRule = false;
+            }
+        }
+        
+        if (!passedRule) {
+            return false;
+        }
+
+        // RULE No.3:
+        // The output message part refers to a global element declaration
+        Part outputPart = null;
+        if (outputMessage != null && outputMessage.getParts().size() == 1) {
+            outputPart = (Part) outputMessage.getParts().values().iterator().next();
+            if (outputPart != null) {
+                if ((outputPart.getElementName() == null)
+                    || getElement(outputPart, xmlSchemaList) == null) {
+                    passedRule = false;
+                } else {
+                    outputEl = getElement(outputPart, xmlSchemaList);
+                }
             }
-
-            XmlSchemaComplexType cpt = (XmlSchemaComplexType) schemaType;
-            return checkComplex(cpt);
+        }
+        
+        if (!passedRule) {
+            return false;
         }
 
-        return false;
-
-    }
-
-    private static boolean outputPartsHaveNoDocWrapper(String opName,
-            Operation operation, List<XmlSchema> xmlSchemaList)
-        throws Exception {
-
-        XmlSchemaType schemaType = null;
-        Iterator i = null;
-        Output output = operation.getOutput();
-
-        if (output != null) {
-            Message msg = output.getMessage();
-            i = msg.getParts().values().iterator();
-
-            if (msg.getParts().size() == 0) {
-                return false;
-            }
+        // RULE No.4 and No5:
+        // wrapper element should be pure complex type
 
-            Part part = (Part) i.next();
+        // Now lets see if we have any attributes...
+        // This should probably look at the restricted and substitute types too.
 
-            if (i.hasNext()) {
-                return true;
+        XmlSchemaComplexType xsct = null;
+        if (inputEl.getSchemaType() instanceof XmlSchemaComplexType) {
+            xsct = (XmlSchemaComplexType)inputEl.getSchemaType();
+            if (hasAttributes(xsct)
+                || !isWrappableSequence(xsct)) {
+                passedRule = false;
             }
+        } else {
+            passedRule = false;
+        }
+        
+        if (!passedRule) {
+            return false;
+        }
 
-            schemaType = lookUpType(part, xmlSchemaList);
-            if (!part.getName().equals(opName)) {
-                return true;
+        if (outputMessage != null) {
+            if (outputEl != null && outputEl.getSchemaType() instanceof XmlSchemaComplexType)
{
+                xsct = (XmlSchemaComplexType)outputEl.getSchemaType();
+                if (hasAttributes(xsct)
+                    || !isWrappableSequence(xsct)) {
+                    passedRule = false;
+                }
+            } else {
+                passedRule = false;
             }
+        }       
 
-            if (!(schemaType instanceof XmlSchemaComplexType)) {
-                return true;
-            }
+        return passedRule;
+    }
 
-            XmlSchemaComplexType cpt = (XmlSchemaComplexType) schemaType;
-            return checkComplex(cpt);
+    private boolean hasAttributes(XmlSchemaComplexType complexType) {
+        // Now lets see if we have any attributes...
+        // This should probably look at the restricted and substitute types too.
+        if (complexType.getAnyAttribute() != null || complexType.getAttributes().getCount()
> 0) {
+            return true;
         }
-
         return false;
-
     }
 
-    private static boolean checkComplex(XmlSchemaComplexType cpt)
-        throws Exception {
-
-        XmlSchemaParticle particle = (XmlSchemaParticle) cpt.getParticle();
-        if (particle == null) {
-            return true;
-        }
+    private boolean isWrappableSequence(XmlSchemaComplexType type) {
+        if (type.getParticle() instanceof XmlSchemaSequence) {
+            XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
+            XmlSchemaObjectCollection items = seq.getItems();
+
+            for (int x = 0; x < items.getCount(); x++) {
+                XmlSchemaObject o = items.getItem(x);
+                if (!(o instanceof XmlSchemaElement)) {
+                    return false;
+                }
+            }
 
-        if (!(particle instanceof XmlSchemaSequence)) {
             return true;
-        }
-
-        if (cpt.getAttributes().getCount() != 0) {
+        } else if (type.getParticle() == null) {
             return true;
         }
-
-        if (particle instanceof XmlSchemaSequence) {
-            XmlSchemaSequence seq = (XmlSchemaSequence) particle;
-            Iterator it = seq.getItems().getIterator();
-            while (it.hasNext()) {
-                if (!(it.next() instanceof XmlSchemaElement)) {
-                    return true;
-                }
-            }
-        }
-
         return false;
     }
+
 
 }



Mime
View raw message