You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2007/01/15 00:59:53 UTC

svn commit: r496195 - in /incubator/woden/trunk/java/src/org/apache/woden: internal/util/ComponentModelBuilder.java internal/wsdl20/TypesImpl.java wsdl20/xml/TypesElement.java

Author: jkaputin
Date: Sun Jan 14 15:59:52 2007
New Revision: 496195

URL: http://svn.apache.org/viewvc?view=rev&rev=496195
Log:
WODEN-123 removed old code based on 'referenceable'
schemas and now build ElementDeclarations and 
TypeDefinitions in the component model using ALL
accessible schemas, including those in nested WSDL
documents and any nested within other schemas.

Modified:
    incubator/woden/trunk/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
    incubator/woden/trunk/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java
    incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java

Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java?view=diff&rev=496195&r1=496194&r2=496195
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java Sun Jan 14 15:59:52 2007
@@ -37,9 +37,9 @@
 import org.apache.woden.internal.wsdl20.InterfaceOperationImpl;
 import org.apache.woden.internal.wsdl20.ServiceImpl;
 import org.apache.woden.internal.wsdl20.TypeDefinitionImpl;
-import org.apache.woden.internal.wsdl20.TypesImpl;
 import org.apache.woden.internal.wsdl20.extensions.ComponentExtensionsImpl;
 import org.apache.woden.internal.wsdl20.extensions.rpc.RPCConstants;
+import org.apache.woden.schema.Schema;
 import org.apache.woden.wsdl20.Binding;
 import org.apache.woden.wsdl20.BindingFault;
 import org.apache.woden.wsdl20.BindingFaultReference;
@@ -64,8 +64,7 @@
 import org.apache.woden.wsdl20.xml.TypesElement;
 import org.apache.woden.wsdl20.xml.WSDLElement;
 import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaImport;
-import org.apache.ws.commons.schema.XmlSchemaInclude;
+import org.apache.ws.commons.schema.XmlSchemaExternal;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 
@@ -90,6 +89,8 @@
 
 	// TODO private ErrorReporter fErrorRpt; see todo in
 	// buildElementDeclarations()
+    private List fDescTypesDone = new Vector();
+    
 	private List fSchemasDone = new Vector();
 
 	private List fInterfacesDone = new Vector();
@@ -139,51 +140,91 @@
 	 * and type definitions.
 	 */
 	private void buildElementsAndTypes(DescriptionImpl desc) {
-		TypesElement types = desc.getTypesElement();
-
+        
+        if(fDescTypesDone.contains(desc)) {
+            return;
+        } else {
+            fDescTypesDone.add(desc);
+        }
+        
+        //process the schema components declared within this description's types element
 		URI typeSystemURI = URI.create(Constants.TYPE_XSD_2001); //TODO support other type systems?
-
+        TypesElement types = desc.getTypesElement();
 		if (types != null) {
-			List referenceableSchemaDefs = ((TypesImpl) types)
-					.getReferenceableSchemaDefs();
-			Iterator i = referenceableSchemaDefs.iterator();
-			while (i.hasNext()) {
-				XmlSchema schemaDef = (XmlSchema) i.next();
-                buildElementsAndTypes(schemaDef, schemaDef.getTargetNamespace(), typeSystemURI);
-			}
-		}
+            Schema[] schemas = types.getSchemas(); //schema inline/imported directly by <types>
+            XmlSchema xmlSchema;
+            for(int i=0; i<schemas.length; i++) {
+                xmlSchema = schemas[i].getSchemaDefinition();
+                if(xmlSchema != null && !fSchemasDone.contains(xmlSchema)) {
+                    buildElementsAndTypes(xmlSchema, xmlSchema.getTargetNamespace(), typeSystemURI);
+                }
+            }
+        }
+        
+        //process the schema components declared within any included descriptions
+        IncludeElement[] includes = desc.getIncludeElements();
+        DescriptionElement includedDesc;
+        for(int i = 0; i < includes.length; i++)
+        {
+            includedDesc = includes[i].getDescriptionElement();
+            if(includedDesc != null) 
+            {
+                buildElementsAndTypes((DescriptionImpl)includedDesc);
+            }
+        }
+        
+        //process the schema components declared within any imported descriptions
+        ImportElement[] imports = desc.getImportElements();
+        DescriptionElement importedDesc;
+        for(int i = 0; i < imports.length; i++)
+        {
+            importedDesc = imports[i].getDescriptionElement();
+            if(importedDesc != null) 
+            {
+                buildElementsAndTypes((DescriptionImpl)importedDesc);
+            }
+        }
+            
+            
+			//List referenceableSchemaDefs = ((TypesImpl) types)
+			//		.getReferenceableSchemaDefs();
+			//Iterator i = referenceableSchemaDefs.iterator();
+			//while (i.hasNext()) {
+			//	XmlSchema schemaDef = (XmlSchema) i.next();
+            //    buildElementsAndTypes(schemaDef, schemaDef.getTargetNamespace(), typeSystemURI);
+			//}
 	}
     
     private void buildElementsAndTypes(XmlSchema schemaDef, String schemaTns, URI typeSystemURI) {
         
-        if(!fSchemasDone.contains(schemaDef)) {
-            
-            //TODO recurse imported schemas
-            
-            //recurse included schemas
-            XmlSchemaObjectCollection includeColl = schemaDef.getIncludes();
-            Iterator includes = includeColl.getIterator();
-            while(includes.hasNext()) {
-                Object o = includes.next();
-                if(o instanceof XmlSchemaImport) continue;  //TODO seems to be a bug in XmlSchema...includes contains an XmlSchemaImport object?
-                XmlSchemaInclude include = (XmlSchemaInclude)o;
-                XmlSchema schema = include.getSchema();
-                if(schemaTns.equals(schema.getTargetNamespace()) || 
-                   schema.getTargetNamespace() == null ) //this is how XmlSchema represents no target namespace
-                {
-                    buildElementsAndTypes(schema, schemaTns, typeSystemURI);
-                }
-            }
-            
-            //Now parse elements and types declared directly in this schema
+        if(fSchemasDone.contains(schemaDef)) {
+            return;
+        } else {
+            fSchemasDone.add(schemaDef);
+        }
+        
+        //process elements and types declared directly in this schema
+        
+        if(!SchemaConstants.NS_URI_XSD_2001.equals(schemaDef.getTargetNamespace())) {
+            //XML Schema namespace is implicitly imported to get built-in types...we don't want the elements.
+            //TODO detect if the XML Schema NS has been explicitly imported (if so, we do want the elements) 
+            buildElementDeclarations(schemaDef, schemaTns, typeSystemURI);
+        }
+        buildTypeDefinitions(schemaDef, schemaTns, typeSystemURI);
             
-            if(!SchemaConstants.NS_URI_XSD_2001.equals(schemaDef.getTargetNamespace())) {
-                //XML Schema namespace is implicitly imported to get built-in types...we don't want the elements.
-                //TODO detect if the XML Schema NS has been explicitly imported (if so, we do want the elements) 
-                buildElementDeclarations(schemaDef, schemaTns, typeSystemURI);
+        //process elements and types declared in any included or imported schemas.
+        //note that XmlSchema keeps included and imported schemas together, via getIncludes().
+        
+        XmlSchemaObjectCollection includeColl = schemaDef.getIncludes();
+        Iterator includes = includeColl.getIterator();
+        while(includes.hasNext()) {
+            Object o = includes.next();
+            XmlSchemaExternal externalSchema = (XmlSchemaExternal)o;
+            XmlSchema schema = externalSchema.getSchema();
+            if(schema != null )
+            {
+                buildElementsAndTypes(schema, schema.getTargetNamespace(), typeSystemURI);
             }
-            buildTypeDefinitions(schemaDef, schemaTns, typeSystemURI);
-            fSchemasDone.add(schemaDef);
         }
     }
 
@@ -196,13 +237,25 @@
 	    Iterator qnames = elementTable.getNames();
 	    while (qnames.hasNext()) {
 	        QName xseQN = (QName) qnames.next();
+            if(fDesc.getElementDeclaration(xseQN) != null) {
+                //The Description already contains this Element Declaration.
+                continue;
+                //This check is necessary because the XmlSchema.equals method, which gets used
+                //to evaluate fSchemas.contains(..), cannot detect the equivalence of a schema 
+                //that is xs:imported within <wsdl:types> and also xs:imported within by 
+                //an inlined schema within the same <wsdl:types> element.
+                //Error case is result.xsd in the W3C WSDL 2.0 test case SparqlQuerySimplified-1G.
+                //This check may be necessary anyway, because if the document assertion Schema-0018
+                //is violated, we don't want the duplicate schema components in the component model.
+                //TODO check that this behaviour is correct (eliminating duplicates)
+            }
             QName edQN = xseQN;
-            if(xseQN.getNamespaceURI() == null) {
+            if(xseQN.getNamespaceURI() == null && schemaTns != null) {
                 //this is how XmlSchema represents tns for chameleon xs:includes,
                 //so replace it with the including schema's tns.
                 edQN = new QName(schemaTns, xseQN.getLocalPart(), xseQN.getPrefix());
             }
-	        if(edQN.getNamespaceURI().equals(schemaTns) || schemaTns == null) //TODO test with schema imports, may be incorrect.
+	        if(schemaTns == null || schemaTns.equals(edQN.getNamespaceURI())) //TODO test with schema imports, may be incorrect.
             {
 	            ElementDeclarationImpl ed = new ElementDeclarationImpl();
 	            ed.setName(edQN);
@@ -231,13 +284,20 @@
                 continue;
             }
             
+            if(fDesc.getTypeDefinition(xstQN) != null) {
+                //The Description already contains this Type Definition.
+                continue;
+                //The same comments apply here as stated in the buildElementDeclarations method.
+                //TODO check that this behaviour is correct (per assertion Schema-0018).
+            }
             QName tdQN = xstQN;
-            if(xstQN.getNamespaceURI() == null) {
+            if(xstQN.getNamespaceURI() == null && schemaTns != null) {
                 //this is how XmlSchema represents tns for chameleon xs:includes,
                 //so replace it with the including schema's tns.
                 tdQN = new QName(schemaTns, xstQN.getLocalPart(), xstQN.getPrefix());
             }
-	        if (tdQN.getNamespaceURI().equals(schemaTns)) {
+	        if (schemaTns == null || schemaTns.equals(tdQN.getNamespaceURI())) 
+            {
 	            TypeDefinitionImpl td = new TypeDefinitionImpl();
 	            td.setName(tdQN);
 	            td.setSystem(typeSystemURI);

Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java?view=diff&rev=496195&r1=496194&r2=496195
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java Sun Jan 14 15:59:52 2007
@@ -182,7 +182,7 @@
      * ************************************************************/
     
     /* 
-     * TODO decide if this should be on the API or package private or just left as a non-API public impl method.
+     * TODO decide if this helper method should be on the API, either as-is or replaced by method that returns all accessible schemas.
      * 
      * Returns the schema element declaration identified by the QName,
      * providing the element declaration is referenceable to the 
@@ -221,7 +221,7 @@
     }
     
     /*
-     * TODO decide if this should be on the API or or package private just left as a non-API public impl method.
+     * TODO decide if this helper method should be on the API, either as-is or replaced by method that returns all accessible schemas.
      * 
      * Returns the schema type definition identified by the QName,
      * providing the type definition is referenceable by the 
@@ -267,8 +267,10 @@
      * NOTE: This is an implementation-only method used to build the ElementDeclarations
      * components (i.e. it is not an API method). If it is required on the API it must be 
      * changed to use a type safe return value.
+     * 
+     * TODO t.b.c. remove if made redundant by WODEN-123 
      */
-    public List getReferenceableSchemaDefs()
+    private List getReferenceableSchemaDefs()
     {
         List schemas = new Vector();
         Iterator i = fSchemas.iterator();
@@ -288,6 +290,8 @@
      * Return a Lists of XmlSchema for all schemas with the specified target namespace 
      * or import namespace that are referenceable by the WSDL.
      * Note, this method requires a non-null namespace argument.
+     * 
+     * TODO t.b.d. remove the notion of referenceability - just get ALL schemas?
      */
     private List getReferenceableSchemaDefs(String namespace)
     {
@@ -308,67 +312,6 @@
             }
         }
         return schemas;
-    }
-    
-    /*
-     * TODO decide if needed on API or by internally - delete if not used.
-     * 
-     * Indicates if the namespace represented by the specified URI
-     * is in-scope or referenceable by the WSDL description. 
-     * This means it must be the target namespace of a schema correctly
-     * imported or inlined directly within the &lt;types&gt; element.
-     * 
-     * @return true if the namespace is in-scope, or false if it is not.
-     * 
-     * @see org.apache.woden.wsdl20.xml.TypesElement#isNamespaceInScope(java.net.URI)
-     */
-    public boolean isNamespaceInScope(URI namespaceURI)
-    {
-        return isNamespaceInScope(namespaceURI.toString());
-    }
-    
-    /*
-     * TODO decide if needed on API or by internally - delete if not used.
-     * 
-     * Indicates if the namespace represented by the specified QName
-     * is in-scope or referenceable by the WSDL description. 
-     * This means it must be the target namespace of a schema correctly
-     * imported or inlined directly within the &lt;types&gt; element.
-     * 
-     * @see org.apache.woden.wsdl20.xml.TypesElement#isNamespaceInScope(javax.xml.namespace.QName)
-     */
-    public boolean isNamespaceInScope(QName qname)
-    {
-        return isNamespaceInScope(qname.getNamespaceURI());
-    }
-
-    /*
-     * TODO decide if needed on API or by internally - delete if not used.
-     * 
-     * Indicates if the namespace represented by the specified String
-     * is in-scope or referenceable by the WSDL description. 
-     * This means it must be the target namespace of a schema correctly
-     * imported or inlined directly within the &lt;types&gt; element.
-     * 
-     * @see org.apache.woden.wsdl20.xml.TypesElement#isNamespaceInScope(java.lang.String)
-     */
-    public boolean isNamespaceInScope(String namespace)
-    {
-        boolean result = false;
-        if(namespace != null)
-        {
-            Iterator i = fSchemas.iterator();
-            while(i.hasNext())
-            {
-                SchemaImpl s = (SchemaImpl)i.next();
-                if(s.isReferenceable() && namespace.equals(s.getNamespaceAsString()))
-                {
-                    result = true;
-                    break;
-                }
-            }
-        }
-        return result;
     }
     
 }

Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java?view=diff&rev=496195&r1=496194&r2=496195
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java Sun Jan 14 15:59:52 2007
@@ -66,48 +66,36 @@
     public void removeSchema(Schema schema);
     
     /**
-     * Return the Schemas representing all inlined schemas or schema imports,
-     * in the order in which they occur within the &lt;types&gt; element.
+     * Return the schemas inlined or imported directly within this &lt;types&gt; element.
      * 
      * @return an array of Schema objects
      */
     public Schema[] getSchemas();
     
     /**
-     * Return all Schemas where the specified namespace argument is either the
-     * target namespace of an inlined schema or the imported namespace of a 
-     * schema import. Schemas are returned in the order in which they occur 
-     * within the &lt;types&gt; element.
+     * Return the schemas inlined or imported directly within this &lt;types&gt; element
+     * whose target namespace matches the specified namespace. 
      * <p>
-     * A null namespace argument will return any inlined schemas missing their
-     * target namespace attribute or any schema imports missing their namespace 
-     * attribute.
+     * If the namespace argument is null an empty array is returned.
      * 
-     * @return the Schemas for the schema with the specified target namespace.
+     * @return an array of Schema objects with the specified target namespace.
      */
     public Schema[] getSchemas(URI namespace);
     
     /**
-     * Return all schemas inlined within the &lt;types&gt; element, in the order
-     * in which they occur within &lt;types&gt;.
+     * Return the schemas inlined directly within this &lt;types&gt; element
+     * in the order in which they occur.
      * 
      * @return an array of Schema objects.
      */
     public InlinedSchema[] getInlinedSchemas();
     
     /**
-     * Return all schema imports from within the &lt;types&gt; element, in the order
-     * in which they occur within &lt;types&gt;.
+     * Return the schemas imported directly by this &lt;types&gt; element 
+     * in the order in which they occur.
      * 
      * @return an array of Schema objects.
      */
     public ImportedSchema[] getImportedSchemas();
-    
-    //TODO is there a use case to remove all schemas for a given namespace?
-    //E.g.
-    //public void removeSchemas(String namespace);
-
-
-    //TODO methods to add/get/remove extension elements ... i.e. for other type systems
-
+        
 }



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