Author: jkaputin
Date: Sat Jul  8 22:05:08 2006
New Revision: 420242

URL: http://svn.apache.org/viewvc?rev=420242&view=rev
Log:
Modified building of ElementDeclaration and TypeDefinition
components to traverse schema includes as well.

Modified:
    
incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java

Modified: 
incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java?rev=420242&r1=420241&r2=420242&view=diff
==============================================================================
--- 
incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
 (original)
+++ 
incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
 Sat Jul  8 22:05:08 2006
@@ -16,7 +16,6 @@
 package org.apache.woden.internal.util;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
@@ -65,6 +64,9 @@
 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.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 
 /**
@@ -141,24 +143,7 @@
        private void buildElementsAndTypes(DescriptionImpl desc) {
                TypesElement types = desc.getTypesElement();
 
-               URI typeSystemURI = null;
-               try {
-                       typeSystemURI = new URI(Constants.TYPE_XSD_2001);
-               } catch (URISyntaxException e) {
-                       // TODO this code will propagate 'throws WSDLException' 
up through
-                       // the
-                       // method call path to the API getter methods of the 
Component
-                       // model. Try to
-                       // find a better way of initializing the Component 
model without
-                       // this
-                       // consequence, if possible.
-                       //
-                       // String msg = fErrorRpt.getFormattedMessage(
-                       // "WSDL506",
-                       // new Object[] {Constants.TYPE_XSD_2001});
-                       // throw new 
WSDLException(WSDLException.CONFIGURATION_ERROR, msg,
-                       // e);
-               }
+               URI typeSystemURI = URI.create(Constants.TYPE_XSD_2001); //TODO 
support other type systems?
 
                if (types != null) {
                        List referenceableSchemaDefs = ((TypesImpl) types)
@@ -166,76 +151,91 @@
                        Iterator i = referenceableSchemaDefs.iterator();
                        while (i.hasNext()) {
                                XmlSchema schemaDef = (XmlSchema) i.next();
-
-                               // Following code is a work around for a bug in
-                               // XmlSchemaObject.equals - this method
-                               // gets invoked via List.contains(o), but 
currently it always
-                               // return true!!!
-
-                               boolean newSchema = true;
-                               for (Iterator i2 = fSchemasDone.iterator(); 
i2.hasNext();) {
-                                       XmlSchema schemaDone = (XmlSchema) 
i2.next();
-                                       if (schemaDef == schemaDone) {
-                                               newSchema = false;
-                                               break;
-                                       }
-                               }
-
-                               // if(!fSchemasDone.contains(schemaDef)) TODO 
re-instate when
-                               // XmlSchemaObject.equals bug is fixed
-                               if (newSchema) {
-                                       buildElementDeclarations(schemaDef, 
typeSystemURI);
-                                       buildTypeDefinitions(schemaDef, 
typeSystemURI);
-                                       fSchemasDone.add(schemaDef);
-                               }
+                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()) || 
+                   "DEFAULT".equals(schema.getTargetNamespace()) ) //this is 
how XmlSchema stores a null tns
+                {
+                    buildElementsAndTypes(schema, schemaTns, typeSystemURI);
+                }
+            }
+            
+            //parse elements and types declared directly in this schema
+            buildElementDeclarations(schemaDef, schemaTns, typeSystemURI);
+            buildTypeDefinitions(schemaDef, schemaTns, typeSystemURI);
+            fSchemasDone.add(schemaDef);
+        }
+    }
 
        /*
         * Extract the element declarations from the given schema.
         */
-       private void buildElementDeclarations(XmlSchema schemaDef, URI 
typeSystemURI) {
-               String schemaTns = schemaDef.getTargetNamespace();
-               if (schemaTns != null) {
-                       XmlSchemaObjectTable elementTable = 
schemaDef.getElements();
-                       Iterator qnames = elementTable.getNames();
-                       while (qnames.hasNext()) {
-                               QName qname = (QName) qnames.next();
-
-                               if (qname.getNamespaceURI().equals(schemaTns)) {
-                                       ElementDeclarationImpl ed = new 
ElementDeclarationImpl();
-                                       ed.setName(qname);
-                                       ed.setSystem(typeSystemURI);
-                                       
ed.setContentModel(Constants.API_APACHE_WS_XS);
-                                       
ed.setContent(elementTable.getItem(qname));
-                                       fDesc.addElementDeclaration(ed);
-                               }
-                       }
-               }
+       private void buildElementDeclarations(XmlSchema schemaDef, String 
schemaTns, URI typeSystemURI) {
+        
+           XmlSchemaObjectTable elementTable = schemaDef.getElements();
+           Iterator qnames = elementTable.getNames();
+           while (qnames.hasNext()) {
+               QName xseQN = (QName) qnames.next();
+            QName edQN = xseQN;
+            if(xseQN.getNamespaceURI().equals("DEFAULT")) {
+                //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)) //TODO test with 
schema imports, may be incorrect.
+            {
+                   ElementDeclarationImpl ed = new ElementDeclarationImpl();
+                   ed.setName(edQN);
+                   ed.setSystem(typeSystemURI);
+                   ed.setContentModel(Constants.API_APACHE_WS_XS);
+                   ed.setContent(elementTable.getItem(xseQN));
+                   fDesc.addElementDeclaration(ed);
+               }
+           }
+           
        }
 
        /*
         * Extract the type definitions from the given schema.
         */
-       private void buildTypeDefinitions(XmlSchema schemaDef, URI 
typeSystemURI) {
-               String schemaTns = schemaDef.getTargetNamespace();
-               if (schemaTns != null) {
-                       XmlSchemaObjectTable typeTable = 
schemaDef.getSchemaTypes();
-                       Iterator qnames = typeTable.getNames();
-                       while (qnames.hasNext()) {
-                               QName qname = (QName) qnames.next();
-
-                               if (qname.getNamespaceURI().equals(schemaTns)) {
-                                       TypeDefinitionImpl td = new 
TypeDefinitionImpl();
-                                       td.setName(qname);
-                                       td.setSystem(typeSystemURI);
-                                       
td.setContentModel(Constants.API_APACHE_WS_XS);
-                                       td.setContent(typeTable.getItem(qname));
-                                       fDesc.addTypeDefinition(td);
-                               }
-                       }
-               }
+       private void buildTypeDefinitions(XmlSchema schemaDef, String 
schemaTns, URI typeSystemURI) {
+        
+           XmlSchemaObjectTable typeTable = schemaDef.getSchemaTypes();
+           Iterator qnames = typeTable.getNames();
+           while (qnames.hasNext()) {
+               QName xsdQN = (QName) qnames.next();
+            QName tdQN = xsdQN;
+            if(xsdQN.getNamespaceURI().equals("DEFAULT")) {
+                //this is how XmlSchema represents tns for chameleon 
xs:includes,
+                //so replace it with the including schema's tns.
+                tdQN = new QName(schemaTns, xsdQN.getLocalPart(), 
xsdQN.getPrefix());
+            }
+               if (tdQN.getNamespaceURI().equals(schemaTns)) {
+                   TypeDefinitionImpl td = new TypeDefinitionImpl();
+                   td.setName(tdQN);
+                   td.setSystem(typeSystemURI);
+                   td.setContentModel(Constants.API_APACHE_WS_XS);
+                   td.setContent(typeTable.getItem(xsdQN));
+                   fDesc.addTypeDefinition(td);
+               }
+           }
        }
 
        
/***************************************************************************



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

Reply via email to