Author: jkaputin
Date: Mon Nov 28 09:00:50 2005
New Revision: 349434

URL: http://svn.apache.org/viewcvs?rev=349434&view=rev
Log:
Resequenced the parseXXX methods, implemented parsing

methods for binding and its sub-elements and created 

placeholder parsing methods for service and endpoint.

Modified:
    incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java

Modified: incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL: 
http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java?rev=349434&r1=349433&r2=349434&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java 
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java Mon 
Nov 28 09:00:50 2005
@@ -47,16 +47,23 @@
 import org.apache.woden.schema.Schema;

 import org.apache.woden.wsdl20.enumeration.Direction;

 import org.apache.woden.wsdl20.enumeration.MessageLabel;

+import org.apache.woden.wsdl20.xml.BindingElement;

+import org.apache.woden.wsdl20.xml.BindingFaultElement;

+import org.apache.woden.wsdl20.xml.BindingMessageReferenceElement;

+import org.apache.woden.wsdl20.xml.BindingOperationElement;

 import org.apache.woden.wsdl20.xml.DescriptionElement;

 import org.apache.woden.wsdl20.xml.DocumentationElement;

+import org.apache.woden.wsdl20.xml.EndpointElement;

 import org.apache.woden.wsdl20.xml.FaultReferenceElement;

 import org.apache.woden.wsdl20.xml.FeatureElement;

 import org.apache.woden.wsdl20.xml.ImportElement;

+import org.apache.woden.wsdl20.xml.IncludeElement;

 import org.apache.woden.wsdl20.xml.InterfaceElement;

 import org.apache.woden.wsdl20.xml.InterfaceFaultElement;

 import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement;

 import org.apache.woden.wsdl20.xml.InterfaceOperationElement;

 import org.apache.woden.wsdl20.xml.PropertyElement;

+import org.apache.woden.wsdl20.xml.ServiceElement;

 import org.apache.woden.wsdl20.xml.TypesElement;

 import org.apache.woden.wsdl20.xml.WSDLElement;

 import org.apache.ws.commons.schema.XmlSchema;

@@ -85,6 +92,10 @@
         super();

     }

     

+    /* ************************************************************

+     *  API public methods

+     * ************************************************************/

+    

     //TODO add other types of readWSDL methods.

     

     /*

@@ -129,6 +140,10 @@
         }

     }

     

+    /* ************************************************************

+     *  Parsing methods - e.g. parseXXXX()

+     * ************************************************************/

+    

     /* Parse the attributes and child elements of the <description> element.

      * As per the WSDL 2.0 spec, the child elements must be in the 

      * following order if present:

@@ -216,6 +231,10 @@
             {

                 desc.addInterfaceElement(parseInterface(tempEl, desc));

             }

+            else if (QNameUtils.matches(Constants.Q_ELEM_BINDING, tempEl))

+            {

+                desc.addBindingElement(parseBinding(tempEl, desc));

+            }

             else

             {

                 //TODO import, include, binding, service, extension elements

@@ -234,63 +253,206 @@
         documentation.setContent(docEl);

         return documentation;

     }

-

-    private FeatureElement parseFeature(Element featEl, 

+    

+    private ImportElement parseImport(Element importEl,

+                                      DescriptionElement desc,

+                                      Map importedDescs) 

+                                      throws WSDLException

+    {

+        //TODO complete this method

+        return null;

+    }

+        

+    private IncludeElement parseInclude(Element includeEl,

                                         DescriptionElement desc,

-                                        WSDLElement parent) 

+                                        Map includedDescs) 

                                         throws WSDLException

     {

-        FeatureElement feature = desc.createFeatureElement();

-        feature.setParentElement(parent);

+        //TODO complete this method

+        return null;

+    }

 

-        String ref = DOMUtils.getAttribute(featEl, Constants.ATTR_REF);

-        if(ref != null)

-        {

-            feature.setRef(getURI(ref));

-        }

+    /*

+     * TODO Initial schema parsing is specific to XML Schema. 

+     * Need generic support for other type systems.

+     * Consider extension architecture with serializer/deserializer.

+     */

+    private TypesElement parseTypes(Element typesEl,

+                                    DescriptionElement desc) 

+                                    throws WSDLException

+    {

+        TypesElement types = desc.createTypesElement();

         

-        String req = DOMUtils.getAttribute(featEl, Constants.ATTR_REQUIRED);

-        feature.setRequired(Constants.VALUE_TRUE.equals(req) ? true : false);

-        //TODO t.b.c. what if attr value is not 'true' or 'false'? (eg, 
missing, mispelt or not lower case.

+        //TODO for now set to W3 XML Schema. Later,

+        //add support for non-XML Schema type systems

+        types.setTypeSystem(Constants.TYPE_XSD_2001);

         

         //TODO extension attributes

-        

-        /* Parse the child elements of the <feature> element. 

-         * As per WSDL 2.0 spec, they must be in the following order if 
present:

-         * <documentation>

-         * extension elements.

-         * 

-         * TODO validate that the elements are in correct order

-         */ 

 

-        Element tempEl = DOMUtils.getFirstChildElement(featEl);

+        Element tempEl = DOMUtils.getFirstChildElement(typesEl);

 

         while (tempEl != null)

         {

+            QName tempElType = QNameUtils.newQName(tempEl);

+            

+            //TODO validate element order? <documentation> must be first.

+            

             if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

             {

-                feature.addDocumentationElement(parseDocumentation(tempEl, 
desc));

+                types.addDocumentationElement(parseDocumentation(tempEl, 
desc));

+            }

+            else if 
(SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType))

+            {

+                types.addSchema(parseSchemaImport(tempEl, desc));

+            }

+            else if 
(SchemaConstants.XSD_SCHEMA_QNAME_LIST.contains(tempElType))

+            {

+                types.addSchema(parseSchemaInline(tempEl, desc));

             }

             else

             {

-                //TODO extension elements

+                //TODO extensions element (e.g. for xml type systems that are 
not W3C XML Schema)

             }

             

             tempEl = DOMUtils.getNextSiblingElement(tempEl);

         }

-           

-        return feature;

+        

+        return types;

     }

-    

-    private ImportElement parseImport(Element importEl,

-                                      DescriptionElement desc,

-                                      Map importedDescs) 

-                                      throws WSDLException

+

+    private Schema parseSchemaInline(Element schemaEl,

+                                     DescriptionElement desc) 

+                                     throws WSDLException

     {

-        //TODO complete this method

-        return null;

+        InlinedSchema schema = new InlinedSchemaImpl();

+        

+        schema.setId(DOMUtils.getAttribute(schemaEl, Constants.ATTR_ID));

+        

+        String tns = DOMUtils.getAttribute(schemaEl, 
Constants.ATTR_TARGET_NAMESPACE);

+        if(tns != null) {

+            schema.setNamespace(getURI(tns));

+        }

+        

+        XmlSchemaCollection xsc = new XmlSchemaCollection();

+        XmlSchema xs = xsc.read(schemaEl);

+        schema.setSchemaDefinition(xs);

+        

+        return schema;

     }

+

+    /*

+     * Parse the &lt;xs:import&gt; element and retrieve the imported

+     * schema document if schemaLocation specified. Failure to retrieve 

+     * the schema will only matter if any WSDL components contain elements or

+     * constraints that refer to the schema, and typically this will be 

+     * determined later by WSDL validation. So just report any such errors

+     * and return the SchemaImport object (i.e. with a null schema property).

+     * 

+     * WSDL 2.0 spec validation:

+     * - namespace attribute is REQUIRED

+     * - imported schema MUST have a targetNamespace

+     * - namespace and targetNamespace MUST be the same

+     */

+    private Schema parseSchemaImport(Element importEl,

+                                     DescriptionElement desc) 

+                                     throws WSDLException

+    {

+        ImportedSchema schema = new ImportedSchemaImpl();

+        

+        String ns = DOMUtils.getAttribute(importEl, Constants.ATTR_NAMESPACE);

+        if(ns != null) {

+            schema.setNamespace(getURI(ns));

+        }

+        

+        String sloc = DOMUtils.getAttribute(importEl, 
SchemaConstants.ATTR_SCHEMA_LOCATION);

+        if(sloc != null) {

+            schema.setSchemaLocation(getURI(sloc));

+        }

+        

+        if(schema.getNamespace() == null)

+        {

+            //The namespace attribute is REQUIRED on xs:import.

+            //TODO leave this for the validator for now, but decide if we want 
to skip the schema doc retrieval

+            //return schemaImport;

+        }

+        

+        if(schema.getSchemaLocation() == null)

+        {

+            //No schema doc to retrieve, importing namespace only.

+            

+            //TODO try to resolve namespace to an existing SchemaReference

+            throw new WSDLException(WSDLException.OTHER_ERROR,

+            "Resolving namespace-only schema import is not supported yet.");

+            //return schemaImport;

+        }

+        

+        //Now try to retrieve the schema import using schemaLocation

+        

+        Document importedSchemaDoc = null;

+        Element schemaEl = null;

+        URL url = null;

+        

+        try 

+        {

+            String contextURI = desc.getDocumentBaseURI().toString();

+            URL contextURL = (contextURI != null) ? 

+                    StringUtils.getURL(null, contextURI) : null;

+                    url = StringUtils.getURL(contextURL, 

+                            schema.getSchemaLocation().toString());

+                    

+        } catch (MalformedURLException e) {

+            

+            String locURI = schema.getSchemaLocation().toString();

+            String baseURI = desc.getDocumentBaseURI() != null ?

+                    desc.getDocumentBaseURI().toString() : "null";

+                    

+                    getErrorReporter().reportError(

+                            new ErrorLocatorImpl(),  //TODO line&col nos.

+                            "WSDL013", 

+                            new Object[] {baseURI, locURI}, 

+                            ErrorReporter.SEVERITY_ERROR);

+                    

+                    //can't continue schema retrieval with a bad URL.

+                    ((ImportedSchemaImpl)schema).setReferenceable(false);

+                    return schema;

+        }

+        

+        String schemaURL = url.toString();

+        

+        //If the schema has already been imported, reuse it.

+        XmlSchema schemaDef = (XmlSchema)fImportedSchemas.get(schemaURL); 

+        

+        if(schemaDef == null)

+        {

+            //not previously imported, so retrieve it now.

+            try {

+                importedSchemaDoc = getDocument(new InputSource(schemaURL), 
schemaURL);

+                

+            } catch (IOException e4) {

+                

+                //schema retrieval failed (e.g. 'not found')

+                getErrorReporter().reportError(

+                        new ErrorLocatorImpl(),  //TODO line&col nos.

+                        "WSDL015", 

+                        new Object[] {schemaURL}, 

+                        ErrorReporter.SEVERITY_WARNING, 

+                        e4);

+                

+                //cannot continue without an imported schema

+                ((ImportedSchemaImpl)schema).setReferenceable(false);

+                return schema;

+            }

+            

+            schemaEl = importedSchemaDoc.getDocumentElement();

+            XmlSchemaCollection xsc = new XmlSchemaCollection();

+            schemaDef = xsc.read(schemaEl);

+            schema.setSchemaDefinition(schemaDef);

+            fImportedSchemas.put(schemaURL, schemaDef);

+        }

         

+        return schema;

+    }

+    

     private InterfaceElement parseInterface(Element interfaceEl,

                                             DescriptionElement desc) 

                                             throws WSDLException

@@ -488,6 +650,13 @@
        

         //TODO extension attributes

         

+        /* Parse the child elements of interface <operation>. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation> 

+         * <input> <output> <infault> <outfault> <feature> <property> or 
extension elements in any order

+         * TODO validate that the elements are in correct order

+         */ 

+

         Element tempEl = DOMUtils.getFirstChildElement(operEl);

 

         while (tempEl != null)

@@ -531,57 +700,130 @@
         return oper;

     }

     

-    private InterfaceMessageReferenceElement parseInterfaceMessageReference(

-                                                 Element messageEl,

+    private FaultReferenceElement parseInterfaceFaultReference(

+                                                 Element faultRefEl,

                                                  DescriptionElement desc,

                                                  InterfaceOperationElement 
parent)

                                                  throws WSDLException

     {

-        InterfaceMessageReferenceElement message = 
desc.createInterfaceMessageReferenceElement();

-        message.setParentElement(parent);

-        
((InterfaceMessageReferenceImpl)message).setTypes(desc.getTypesElement());

+        FaultReferenceElement faultRef = 
desc.createInterfaceFaultReferenceElement();

+        faultRef.setParentElement(parent);

         

-        if(Constants.ELEM_INPUT.equals(messageEl.getLocalName())) {

-            message.setDirection(Direction.IN);

+        if(Constants.ELEM_INFAULT.equals(faultRefEl.getLocalName())) {

+            faultRef.setDirection(Direction.IN);

         } 

-        else if(Constants.ELEM_OUTPUT.equals(messageEl.getLocalName())) {

-            message.setDirection(Direction.OUT);

+        else if(Constants.ELEM_OUTFAULT.equals(faultRefEl.getLocalName())){

+            faultRef.setDirection(Direction.OUT);

         }

         

-        String msgLabel = DOMUtils.getAttribute(messageEl, 
Constants.ATTR_MESSAGE_LABEL);

-        if(msgLabel != null) 

+        String ref = DOMUtils.getAttribute(faultRefEl, Constants.ATTR_REF);

+        if(ref != null)

+        {

+            try {

+                QName qname = DOMUtils.getQName(ref, faultRefEl, desc);

+                faultRef.setRef(qname);

+            } catch (WSDLException e) {

+                getErrorReporter().reportError( 

+                        new ErrorLocatorImpl(),  //TODO line&col nos.

+                        "WSDL504",

+                        new Object[] {ref, faultRefEl.getLocalName()}, 

+                        ErrorReporter.SEVERITY_ERROR);

+            }

+        }

+        

+        String msgLabel = DOMUtils.getAttribute(faultRefEl, 
Constants.ATTR_MESSAGE_LABEL);

+        if(msgLabel != null)

         {

             if(msgLabel.equals(MessageLabel.IN.toString())) {

-                message.setMessageLabel(MessageLabel.IN);

+                faultRef.setMessageLabel(MessageLabel.IN);

             } else if(msgLabel.equals(MessageLabel.OUT.toString())) {

-                message.setMessageLabel(MessageLabel.OUT);

+                faultRef.setMessageLabel(MessageLabel.OUT);

             } else {

                 //invalid value, but capture it anyway.

-                message.setMessageLabel(MessageLabel.invalidValue(msgLabel));

+                faultRef.setMessageLabel(MessageLabel.invalidValue(msgLabel));

             }

         }

         

-        String element = DOMUtils.getAttribute(messageEl, 
Constants.ATTR_ELEMENT);

-        if(element != null)

+        //TODO extension attributes

+        

+        Element tempEl = DOMUtils.getFirstChildElement(faultRefEl);

+        

+        while (tempEl != null)

         {

-            if(element.equals(Constants.NMTOKEN_ANY) ||

-               element.equals(Constants.NMTOKEN_NONE) ||

-               element.equals(Constants.NMTOKEN_OTHER))

+            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

             {

-                message.setMessageContentModel(element);

+                faultRef.addDocumentationElement(parseDocumentation(tempEl, 
desc));

             }

-            else

+            else if (QNameUtils.matches(Constants.Q_ELEM_FEATURE, tempEl))

             {

-                //element is not #any, #none or #other, so it must be an 
element qname

-                message.setMessageContentModel(Constants.NMTOKEN_ELEMENT);

+                faultRef.addFeatureElement(parseFeature(tempEl, desc, 
faultRef));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_PROPERTY, tempEl))

+            {

+                faultRef.addPropertyElement(parseProperty(tempEl, desc, 
faultRef));

+            }

+            else

+            {

+                //TODO extension elements

+            }

+            

+            tempEl = DOMUtils.getNextSiblingElement(tempEl);

+        }

+        

+        return faultRef;

+    }

+

+    private InterfaceMessageReferenceElement parseInterfaceMessageReference(

+                                                 Element msgRefEl,

+                                                 DescriptionElement desc,

+                                                 InterfaceOperationElement 
parent)

+                                                 throws WSDLException

+    {

+        InterfaceMessageReferenceElement message = 
desc.createInterfaceMessageReferenceElement();

+        message.setParentElement(parent);

+        
((InterfaceMessageReferenceImpl)message).setTypes(desc.getTypesElement());

+        

+        if(Constants.ELEM_INPUT.equals(msgRefEl.getLocalName())) {

+            message.setDirection(Direction.IN);

+        } 

+        else if(Constants.ELEM_OUTPUT.equals(msgRefEl.getLocalName())) {

+            message.setDirection(Direction.OUT);

+        }

+        

+        String msgLabel = DOMUtils.getAttribute(msgRefEl, 
Constants.ATTR_MESSAGE_LABEL);

+        if(msgLabel != null) 

+        {

+            if(msgLabel.equals(MessageLabel.IN.toString())) {

+                message.setMessageLabel(MessageLabel.IN);

+            } else if(msgLabel.equals(MessageLabel.OUT.toString())) {

+                message.setMessageLabel(MessageLabel.OUT);

+            } else {

+                //invalid value, but capture it anyway.

+                message.setMessageLabel(MessageLabel.invalidValue(msgLabel));

+            }

+        }

+        

+        String element = DOMUtils.getAttribute(msgRefEl, 
Constants.ATTR_ELEMENT);

+        if(element != null)

+        {

+            if(element.equals(Constants.NMTOKEN_ANY) ||

+               element.equals(Constants.NMTOKEN_NONE) ||

+               element.equals(Constants.NMTOKEN_OTHER))

+            {

+                message.setMessageContentModel(element);

+            }

+            else

+            {

+                //element is not #any, #none or #other, so it must be an 
element qname

+                message.setMessageContentModel(Constants.NMTOKEN_ELEMENT);

                 try {

-                    QName qname = DOMUtils.getQName(element, messageEl, desc);

+                    QName qname = DOMUtils.getQName(element, msgRefEl, desc);

                     message.setElementName(qname);

                 } catch (WSDLException e) {

                     getErrorReporter().reportError( 

                             new ErrorLocatorImpl(),  //TODO line&col nos.

                             "WSDL504",

-                            new Object[] {element, messageEl.getLocalName()}, 

+                            new Object[] {element, msgRefEl.getLocalName()}, 

                             ErrorReporter.SEVERITY_ERROR);

                 }

             }

@@ -595,7 +837,7 @@
 

         //TODO extension attributes

 

-        Element tempEl = DOMUtils.getFirstChildElement(messageEl);

+        Element tempEl = DOMUtils.getFirstChildElement(msgRefEl);

 

         while (tempEl != null)

         {

@@ -622,13 +864,229 @@
         return message;

     }

 

-    private FaultReferenceElement parseInterfaceFaultReference(

-                                         Element faultRefEl,

-                                         DescriptionElement desc,

-                                         InterfaceOperationElement parent)

-                                         throws WSDLException

+    private BindingElement parseBinding(Element bindEl,

+                                        DescriptionElement desc)

+                                        throws WSDLException

     {

-        FaultReferenceElement faultRef = 
desc.createInterfaceFaultReferenceElement();

+        BindingElement binding = desc.createBindingElement();

+

+        //'name' attribute

+        String name = DOMUtils.getAttribute(bindEl, Constants.ATTR_NAME);

+        if(name != null)

+        {

+            QName qname = 
QNameUtils.newQName(desc.getTargetNamespace().toString(), 

+                                              name);

+            binding.setName(qname);

+        }

+        

+        //'interface' attribute

+        String intface = DOMUtils.getAttribute(bindEl, 
Constants.ATTR_INTERFACE);

+        if(intface != null)

+        {

+            try {

+                QName qname = DOMUtils.getQName(intface, bindEl, desc);

+                binding.setInterfaceName(qname);

+            } catch (WSDLException e) {

+                getErrorReporter().reportError( 

+                        new ErrorLocatorImpl(),  //TODO line&col nos.

+                        "WSDL504",

+                        new Object[] {intface, bindEl.getLocalName()}, 

+                        ErrorReporter.SEVERITY_ERROR);

+            }

+        }

+        

+        //'type' attribute

+        String type = DOMUtils.getAttribute(bindEl, Constants.ATTR_TYPE);

+        if(type != null) {

+            binding.setType(getURI(type));

+        }

+        

+        //TODO extension attributes

+        

+        /* Parse the child elements of <binding>. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation>

+         * <fault> <operation> <feature> <property> or extension elements in 
any order

+         * TODO validate that the elements are in correct order

+         */ 

+

+        Element tempEl = DOMUtils.getFirstChildElement(bindEl);

+

+        while (tempEl != null)

+        {

+            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

+            {

+                binding.addDocumentationElement(parseDocumentation(tempEl, 
desc));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_FAULT, tempEl))

+            {

+                binding.addBindingFaultElement(parseBindingFault(tempEl, desc, 
binding));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_OPERATION, tempEl))

+            {

+                
binding.addBindingOperationElement(parseBindingOperation(tempEl, desc, 
binding));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_FEATURE, tempEl))

+            {

+                binding.addFeatureElement(parseFeature(tempEl, desc, binding));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_PROPERTY, tempEl))

+            {

+                binding.addPropertyElement(parseProperty(tempEl, desc, 
binding));

+            }

+            else

+            {

+                //TODO extension elements

+            }

+            

+            tempEl = DOMUtils.getNextSiblingElement(tempEl);

+        }

+        

+        return binding;

+    }

+

+    private BindingFaultElement parseBindingFault(Element bindFaultEl,

+                                                  DescriptionElement desc,

+                                                  WSDLElement parent)

+                                                  throws WSDLException

+    {

+        BindingFaultElement fault = desc.createBindingFaultElement();

+        

+        //'ref' attribute

+        String ref = DOMUtils.getAttribute(bindFaultEl, Constants.ATTR_REF);

+        if(ref != null)

+        {

+            try {

+                QName qname = DOMUtils.getQName(ref, bindFaultEl, desc);

+                fault.setRef(qname);

+            } catch (WSDLException e) {

+                getErrorReporter().reportError( 

+                        new ErrorLocatorImpl(),  //TODO line&col nos.

+                        "WSDL504",

+                        new Object[] {ref, bindFaultEl.getLocalName()}, 

+                        ErrorReporter.SEVERITY_ERROR);

+            }

+        }

+        

+        //TODO extension attributes

+        

+        /* Parse the child elements of binding <fault>. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation> 

+         * <feature> <property> or extension elements in any order

+         * TODO validate that the elements are in correct order

+         */ 

+

+        Element tempEl = DOMUtils.getFirstChildElement(bindFaultEl);

+

+        while (tempEl != null)

+        {

+            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

+            {

+                fault.addDocumentationElement(parseDocumentation(tempEl, 
desc));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_FEATURE, tempEl))

+            {

+                fault.addFeatureElement(parseFeature(tempEl, desc, fault));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_PROPERTY, tempEl))

+            {

+                fault.addPropertyElement(parseProperty(tempEl, desc, fault));

+            }

+            else

+            {

+                //TODO extension elements

+            }

+            

+            tempEl = DOMUtils.getNextSiblingElement(tempEl);

+        }

+        

+        return fault;

+    }

+

+    private BindingOperationElement parseBindingOperation(

+                                                 Element bindOpEl,

+                                                 DescriptionElement desc,

+                                                 WSDLElement parent)

+                                                 throws WSDLException

+    {

+        BindingOperationElement oper = desc.createBindingOperationElement();

+        

+        //'ref' attribute

+        String ref = DOMUtils.getAttribute(bindOpEl, Constants.ATTR_REF);

+        if(ref != null)

+        {

+            try {

+                QName qname = DOMUtils.getQName(ref, bindOpEl, desc);

+                oper.setRef(qname);

+            } catch (WSDLException e) {

+                getErrorReporter().reportError( 

+                        new ErrorLocatorImpl(),  //TODO line&col nos.

+                        "WSDL504",

+                        new Object[] {ref, bindOpEl.getLocalName()}, 

+                        ErrorReporter.SEVERITY_ERROR);

+            }

+        }

+        

+        //TODO extension attributes

+        

+        /* Parse the child elements of binding <operation>. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation> 

+         * <input> <output> <infault> <outfault> <feature> <property> or 
extension elements in any order

+         * TODO validate that the elements are in correct order

+         */ 

+

+        Element tempEl = DOMUtils.getFirstChildElement(bindOpEl);

+

+        while (tempEl != null)

+        {

+            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

+            {

+                oper.addDocumentationElement(parseDocumentation(tempEl, desc));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_FEATURE, tempEl))

+            {

+                oper.addFeatureElement(parseFeature(tempEl, desc, oper));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_PROPERTY, tempEl))

+            {

+                oper.addPropertyElement(parseProperty(tempEl, desc, oper));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_INPUT, tempEl))

+            {

+                
oper.addMessageReferenceElement(parseBindingMessageReference(tempEl, desc, 
oper));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_OUTPUT, tempEl))

+            {

+                
oper.addMessageReferenceElement(parseBindingMessageReference(tempEl, desc, 
oper));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_INFAULT, tempEl))

+            {

+                
oper.addFaultReferenceElement(parseBindingFaultReference(tempEl, desc, oper));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_OUTFAULT, tempEl))

+            {

+                
oper.addFaultReferenceElement(parseBindingFaultReference(tempEl, desc, oper));

+            }

+            else

+            {

+                //TODO extension elements

+            }

+            

+            tempEl = DOMUtils.getNextSiblingElement(tempEl);

+        }

+        

+        return oper;

+    }

+

+    private FaultReferenceElement parseBindingFaultReference(

+                                                  Element faultRefEl,

+                                                  DescriptionElement desc,

+                                                  WSDLElement parent)

+                                                  throws WSDLException

+    {

+        FaultReferenceElement faultRef = 
desc.createBindingFaultReferenceElement();

         faultRef.setParentElement(parent);

         

         if(Constants.ELEM_INFAULT.equals(faultRefEl.getLocalName())) {

@@ -652,7 +1110,7 @@
                         ErrorReporter.SEVERITY_ERROR);

             }

         }

-

+        

         String msgLabel = DOMUtils.getAttribute(faultRefEl, 
Constants.ATTR_MESSAGE_LABEL);

         if(msgLabel != null)

         {

@@ -667,9 +1125,16 @@
         }

         

         //TODO extension attributes

+        

+        /* Parse the child elements of binding operation <infault> or 
<outfault>. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation> 

+         * <feature> <property> or extension elements in any order

+         * TODO validate that the elements are in correct order

+         */ 

 

         Element tempEl = DOMUtils.getFirstChildElement(faultRefEl);

-

+        

         while (tempEl != null)

         {

             if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

@@ -694,6 +1159,132 @@
         

         return faultRef;

     }

+    

+    private BindingMessageReferenceElement parseBindingMessageReference(

+                                                 Element msgRefEl,

+                                                 DescriptionElement desc,

+                                                 WSDLElement parent)

+                                                 throws WSDLException

+    {

+        BindingMessageReferenceElement message = 
desc.createBindingMessageReferenceElement();

+        message.setParentElement(parent);

+        
((InterfaceMessageReferenceImpl)message).setTypes(desc.getTypesElement());

+        

+        if(Constants.ELEM_INPUT.equals(msgRefEl.getLocalName())) {

+            message.setDirection(Direction.IN);

+        } 

+        else if(Constants.ELEM_OUTPUT.equals(msgRefEl.getLocalName())) {

+            message.setDirection(Direction.OUT);

+        }

+        

+        String msgLabel = DOMUtils.getAttribute(msgRefEl, 
Constants.ATTR_MESSAGE_LABEL);

+        if(msgLabel != null) 

+        {

+            if(msgLabel.equals(MessageLabel.IN.toString())) {

+                message.setMessageLabel(MessageLabel.IN);

+            } else if(msgLabel.equals(MessageLabel.OUT.toString())) {

+                message.setMessageLabel(MessageLabel.OUT);

+            } else {

+                //invalid value, but capture it anyway.

+                message.setMessageLabel(MessageLabel.invalidValue(msgLabel));

+            }

+        }

+        

+        //TODO extension attributes

+

+        /* Parse the child elements of binding operation <input> or <output>. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation> 

+         * <feature> <property> or extension elements in any order

+         * TODO validate that the elements are in correct order

+         */ 

+

+        Element tempEl = DOMUtils.getFirstChildElement(msgRefEl);

+

+        while (tempEl != null)

+        {

+            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

+            {

+                message.addDocumentationElement(parseDocumentation(tempEl, 
desc));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_FEATURE, tempEl))

+            {

+                message.addFeatureElement(parseFeature(tempEl, desc, message));

+            }

+            else if (QNameUtils.matches(Constants.Q_ELEM_PROPERTY, tempEl))

+            {

+                message.addPropertyElement(parseProperty(tempEl, desc, 
message));

+            }

+            else

+            {

+                //TODO extension elements

+            }

+            

+            tempEl = DOMUtils.getNextSiblingElement(tempEl);

+        }

+        

+        return message;

+    }

+

+    private ServiceElement parseService(Element serviceEl,

+                                        DescriptionElement desc)

+    {

+        return null;

+    }

+                                        

+    private EndpointElement parseEndpoint(Element endpointEl,

+                                          DescriptionElement desc,

+                                          WSDLElement parent)

+    {

+        return null;

+    }

+

+    private FeatureElement parseFeature(Element featEl, 

+                                        DescriptionElement desc,

+                                        WSDLElement parent) 

+                                        throws WSDLException

+    {

+        FeatureElement feature = desc.createFeatureElement();

+        feature.setParentElement(parent);

+        

+        String ref = DOMUtils.getAttribute(featEl, Constants.ATTR_REF);

+        if(ref != null)

+        {

+            feature.setRef(getURI(ref));

+        }

+        

+        String req = DOMUtils.getAttribute(featEl, Constants.ATTR_REQUIRED);

+        feature.setRequired(Constants.VALUE_TRUE.equals(req) ? true : false);

+        //TODO t.b.c. what if attr value is not 'true' or 'false'? (eg, 
missing, mispelt or not lower case.

+        

+        //TODO extension attributes

+        

+        /* Parse the child elements of the <feature> element. 

+         * As per WSDL 2.0 spec, they must be in the following order if 
present:

+         * <documentation>

+         * extension elements.

+         * 

+         * TODO validate that the elements are in correct order

+         */ 

+        

+        Element tempEl = DOMUtils.getFirstChildElement(featEl);

+        

+        while (tempEl != null)

+        {

+            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

+            {

+                feature.addDocumentationElement(parseDocumentation(tempEl, 
desc));

+            }

+            else

+            {

+                //TODO extension elements

+            }

+            

+            tempEl = DOMUtils.getNextSiblingElement(tempEl);

+        }

+        

+        return feature;

+    }

 

     /* ******************************************************************

      * Parse the attributes and child elements of the <property> element.

@@ -798,187 +1389,11 @@
         return property;

     }

 

-    private Schema parseSchemaInline(Element schemaEl,

-                                     DescriptionElement desc) 

-                                     throws WSDLException

-    {

-        InlinedSchema schema = new InlinedSchemaImpl();

-        

-        schema.setId(DOMUtils.getAttribute(schemaEl, Constants.ATTR_ID));

-    

-        String tns = DOMUtils.getAttribute(schemaEl, 
Constants.ATTR_TARGET_NAMESPACE);

-        if(tns != null) {

-            schema.setNamespace(getURI(tns));

-        }

-    

-        XmlSchemaCollection xsc = new XmlSchemaCollection();

-        XmlSchema xs = xsc.read(schemaEl);

-        schema.setSchemaDefinition(xs);

-        

-        return schema;

-    }

-

-    /*

-     * Parse the &lt;xs:import&gt; element and retrieve the imported

-     * schema document if schemaLocation specified. Failure to retrieve 

-     * the schema will only matter if any WSDL components contain elements or

-     * constraints that refer to the schema, and typically this will be 

-     * determined later by WSDL validation. So just report any such errors

-     * and return the SchemaImport object (i.e. with a null schema property).

-     * 

-     * WSDL 2.0 spec validation:

-     * - namespace attribute is REQUIRED

-     * - imported schema MUST have a targetNamespace

-     * - namespace and targetNamespace MUST be the same

-     */

-    private Schema parseSchemaImport(Element importEl,

-                                     DescriptionElement desc) 

-                                     throws WSDLException

-    {

-        ImportedSchema schema = new ImportedSchemaImpl();

-        

-        String ns = DOMUtils.getAttribute(importEl, Constants.ATTR_NAMESPACE);

-        if(ns != null) {

-            schema.setNamespace(getURI(ns));

-        }

-        

-        String sloc = DOMUtils.getAttribute(importEl, 
SchemaConstants.ATTR_SCHEMA_LOCATION);

-        if(sloc != null) {

-            schema.setSchemaLocation(getURI(sloc));

-        }

-        

-        if(schema.getNamespace() == null)

-        {

-            //The namespace attribute is REQUIRED on xs:import.

-            //TODO leave this for the validator for now, but decide if we want 
to skip the schema doc retrieval

-            //return schemaImport;

-        }

-        

-        if(schema.getSchemaLocation() == null)

-        {

-            //No schema doc to retrieve, importing namespace only.

-            

-            //TODO try to resolve namespace to an existing SchemaReference

-            throw new WSDLException(WSDLException.OTHER_ERROR,

-                    "Resolving namespace-only schema import is not supported 
yet.");

-            //return schemaImport;

-        }

-        

-        //Now try to retrieve the schema import using schemaLocation

-        

-        Document importedSchemaDoc = null;

-        Element schemaEl = null;

-        URL url = null;

-            

-        try 

-        {

-            String contextURI = desc.getDocumentBaseURI().toString();

-            URL contextURL = (contextURI != null) ? 

-                              StringUtils.getURL(null, contextURI) : null;

-            url = StringUtils.getURL(contextURL, 

-                                     schema.getSchemaLocation().toString());

-            

-        } catch (MalformedURLException e) {

-            

-            String locURI = schema.getSchemaLocation().toString();

-            String baseURI = desc.getDocumentBaseURI() != null ?

-                             desc.getDocumentBaseURI().toString() : "null";

-                    

-            getErrorReporter().reportError(

-                new ErrorLocatorImpl(),  //TODO line&col nos.

-                "WSDL013", 

-                new Object[] {baseURI, locURI}, 

-                ErrorReporter.SEVERITY_ERROR);

-            

-            //can't continue schema retrieval with a bad URL.

-            ((ImportedSchemaImpl)schema).setReferenceable(false);

-            return schema;

-        }

-

-        String schemaURL = url.toString();

-        

-        //If the schema has already been imported, reuse it.

-        XmlSchema schemaDef = (XmlSchema)fImportedSchemas.get(schemaURL); 

-        

-        if(schemaDef == null)

-        {

-            //not previously imported, so retrieve it now.

-            try {

-                importedSchemaDoc = getDocument(new InputSource(schemaURL), 
schemaURL);

-                

-            } catch (IOException e4) {

-                

-                //schema retrieval failed (e.g. 'not found')

-                getErrorReporter().reportError(

-                        new ErrorLocatorImpl(),  //TODO line&col nos.

-                        "WSDL015", 

-                        new Object[] {schemaURL}, 

-                        ErrorReporter.SEVERITY_WARNING, 

-                        e4);

-                

-                //cannot continue without an imported schema

-                ((ImportedSchemaImpl)schema).setReferenceable(false);

-                return schema;

-            }

-            

-            schemaEl = importedSchemaDoc.getDocumentElement();

-            XmlSchemaCollection xsc = new XmlSchemaCollection();

-            schemaDef = xsc.read(schemaEl);

-            schema.setSchemaDefinition(schemaDef);

-            fImportedSchemas.put(schemaURL, schemaDef);

-        }

-            

-        return schema;

-    }

-

-    /*

-     * TODO Initial schema parsing is specific to XML Schema. 

-     * Need generic support for other type systems.

-     * Consider extension architecture with serializer/deserializer.

-     */

-    private TypesElement parseTypes(Element typesEl,

-                                    DescriptionElement desc) 

-                                    throws WSDLException

-    {

-        TypesElement types = desc.createTypesElement();

-        

-        //TODO for now set to W3 XML Schema. Later,

-        //add support for non-XML Schema type systems

-        types.setTypeSystem(Constants.TYPE_XSD_2001);

-        

-        //TODO extension attributes

-

-        Element tempEl = DOMUtils.getFirstChildElement(typesEl);

-

-        while (tempEl != null)

-        {

-            QName tempElType = QNameUtils.newQName(tempEl);

-            

-            //TODO validate element order? <documentation> must be first.

-            

-            if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl))

-            {

-                types.addDocumentationElement(parseDocumentation(tempEl, 
desc));

-            }

-            else if 
(SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType))

-            {

-                types.addSchema(parseSchemaImport(tempEl, desc));

-            }

-            else if 
(SchemaConstants.XSD_SCHEMA_QNAME_LIST.contains(tempElType))

-            {

-                types.addSchema(parseSchemaInline(tempEl, desc));

-            }

-            else

-            {

-                //TODO extensions element (e.g. for xml type systems that are 
not W3C XML Schema)

-            }

-            

-            tempEl = DOMUtils.getNextSiblingElement(tempEl);

-        }

-        

-        return types;

-    }

 

+    /* ************************************************************

+     *  Utility/helper methods

+     * ************************************************************/

+    

     /**

      * Check the actual element encountered against the expected qname

      * 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to