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 2006/01/21 22:31:39 UTC

svn commit: r371116 - in /incubator/woden/java/src/org/apache/woden/internal: util/ComponentModelBuilder.java wsdl20/DescriptionImpl.java

Author: jkaputin
Date: Sat Jan 21 13:31:30 2006
New Revision: 371116

URL: http://svn.apache.org/viewcvs?rev=371116&view=rev
Log:
Added support for import and include to the initialization
of the Component model (i.e. flattening of top-level
components from modularized WSDL documents into the
properties of the Description component). Now, calling
DescriptionElement.toComponent() will trigger the
traversal of any import or include tree.

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

Modified: incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java?rev=371116&r1=371115&r2=371116&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 Jan 21 13:31:30 2006
@@ -40,12 +40,16 @@
 import org.apache.woden.internal.wsdl20.TypeDefinitionImpl;
 import org.apache.woden.internal.wsdl20.TypesImpl;
 import org.apache.woden.wsdl20.Interface;
+import org.apache.woden.wsdl20.Service;
 import org.apache.woden.wsdl20.WSDLComponent;
 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.FaultReferenceElement;
+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;
@@ -71,31 +75,54 @@
 
     private DescriptionImpl fDesc;
     //TODO private ErrorReporter fErrorRpt;  see todo in buildElementDeclarations()
-    private List fInScopeSchemas = new Vector();
-    private List fInterfaces = new Vector();
+    private List fSchemasDone = new Vector();
+    private List fInterfacesDone = new Vector();
+    private List fBindingsDone = new Vector();
+    private List fServicesDone = new Vector();
     
     public ComponentModelBuilder(DescriptionImpl desc)
     {
         fDesc = desc;
         //TODO fErrorRpt = errorRpt;  see todo in buildElementDeclarations()
-        initComponents();
+        initComponents(fDesc);
     }
     
-    private void initComponents()
+    private void initComponents(DescriptionImpl desc)
     {
         
-        buildElementsAndTypes();
-        buildInterfaces();
-        buildBindings();
+        buildElementsAndTypes(desc);
+        buildInterfaces(desc);
+        buildBindings(desc);
+        buildServices(desc);
+        
+        IncludeElement[] includes = desc.getIncludeElements();
+        for(int i = 0; i < includes.length; i++)
+        {
+            DescriptionElement inclDesc = includes[i].getDescriptionElement();
+            if(inclDesc != null)
+            {
+                initComponents((DescriptionImpl)inclDesc);
+            }
+        }
+        
+        ImportElement[] imports = desc.getImportElements();
+        for(int i = 0; i < imports.length; i++)
+        {
+            DescriptionElement impDesc = imports[i].getDescriptionElement();
+            if(impDesc != null)
+            {
+                initComponents((DescriptionImpl)impDesc);
+            }
+        }
     }
     
     /*
      * Extract from the collections of in-scope schemas
      * the element declarations and type definitions.
      */
-    private void buildElementsAndTypes()
+    private void buildElementsAndTypes(DescriptionImpl desc)
     {
-        TypesElement types = fDesc.getTypesElement();
+        TypesElement types = desc.getTypesElement();
         
         URI typeSystemURI = null;
         try {
@@ -119,8 +146,27 @@
         	while(i.hasNext())
         	{
         		XmlSchema schemaDef = (XmlSchema)i.next();
-        		buildElementDeclarations(schemaDef, typeSystemURI);
-        		buildTypeDefinitions(schemaDef, typeSystemURI);
+                
+                //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);
+                }
         	}
         }
     }
@@ -146,7 +192,7 @@
                     ed.setSystem(typeSystemURI);
                     ed.setContentModel(Constants.API_APACHE_WS_XS);
                     ed.setContent(elementTable.getItem(qname));
-                    fDesc.addElementDeclaration(ed);
+                    fDesc.addAllElementDeclarations(ed);
                 }
             }
         }
@@ -173,7 +219,7 @@
                     td.setSystem(typeSystemURI);
                     td.setContentModel(Constants.API_APACHE_WS_XS);
                     td.setContent(typeTable.getItem(qname));
-                    fDesc.addTypeDefinition(td);
+                    fDesc.addAllTypeDefinitions(td);
                 }
             }
         }
@@ -183,15 +229,20 @@
      * Initialize the Interface component and its child components from the
      * InterfaceElement and its child elements.
      */
-    private void buildInterfaces()
+    private void buildInterfaces(DescriptionImpl desc)
     {
-        InterfaceElement[] interfaceEls = fDesc.getInterfaceElements();
+        InterfaceElement[] interfaceEls = desc.getInterfaceElements();
         for(int i=0; i<interfaceEls.length; i++)
         {
             InterfaceImpl intImpl = (InterfaceImpl)interfaceEls[i];
-            buildProperties(intImpl.getPropertyElements(), intImpl);
-            buildInterfaceFaults(intImpl);
-            buildInterfaceOperations(intImpl);
+            if(!fInterfacesDone.contains(intImpl))
+            {
+                fDesc.addAllInterfaces(intImpl);
+                buildProperties(intImpl.getPropertyElements(), intImpl);
+                buildInterfaceFaults(intImpl);
+                buildInterfaceOperations(intImpl);
+                fInterfacesDone.add(intImpl);
+            }
         }
     }
     
@@ -260,15 +311,20 @@
      * Initialize the Binding component and its child components from the
      * BindingElement and its child elements.
      */
-    private void buildBindings()
+    private void buildBindings(DescriptionImpl desc)
     {
-        BindingElement[] bindingEls = fDesc.getBindingElements();
+        BindingElement[] bindingEls = desc.getBindingElements();
         for(int i=0; i<bindingEls.length; i++)
         {
             BindingImpl bindImpl = (BindingImpl)bindingEls[i];
-            buildProperties(bindImpl.getPropertyElements(), bindImpl);
-            buildBindingFaults(bindImpl);
-            buildBindingOperations(bindImpl);
+            if(!fBindingsDone.contains(bindImpl))
+            {
+                fDesc.addAllBindings(bindImpl);
+                buildProperties(bindImpl.getPropertyElements(), bindImpl);
+                buildBindingFaults(bindImpl);
+                buildBindingOperations(bindImpl);
+                fBindingsDone.add(bindImpl);
+            }
         }
     }
     
@@ -324,6 +380,20 @@
             if(qname != null)
             {
                 prop.setValueConstraint(fDesc.getTypeDefinition(qname));
+            }
+        }
+    }
+    
+    private void buildServices(DescriptionImpl desc)
+    {
+        Service[] services = desc.getServices();
+        for(int i=0; i<services.length; i++)
+        {
+            Service service = services[i];
+            if(!fServicesDone.contains(service))
+            {
+                fDesc.addAllServices(service);
+                fServicesDone.add(service);
             }
         }
     }

Modified: incubator/woden/java/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java?rev=371116&r1=371115&r2=371116&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java Sat Jan 21 13:31:30 2006
@@ -71,13 +71,16 @@
                              implements Description, DescriptionElement 
 {
     /*
-     * WSDL Component model data
+     * WSDL Component model data (flattened properties of Description Component)
      */
-    private List fElementDeclarations = new Vector(); //TODO consider using Map
-    private List fTypeDefinitions = new Vector(); //TODO consider using Map
+    private List fAllInterfaces = new Vector();
+    private List fAllBindings = new Vector();
+    private List fAllServices = new Vector();
+    private List fAllElementDeclarations = new Vector();
+    private List fAllTypeDefinitions = new Vector();
     
     /*
-     * XML Element model data
+     * WSDL Element model data
      */
     private URI fDocumentBaseURI = null;
 
@@ -144,8 +147,8 @@
     public ElementDeclaration[] getElementDeclarations() 
     {
         if(!fComponentsInitialized) initComponents();
-        ElementDeclaration[] array = new ElementDeclaration[fElementDeclarations.size()];
-        fElementDeclarations.toArray(array);
+        ElementDeclaration[] array = new ElementDeclaration[fAllElementDeclarations.size()];
+        fAllElementDeclarations.toArray(array);
         return array;
     }
     
@@ -159,7 +162,7 @@
         ElementDeclaration elDec = null;
         if(qname != null)
         {
-            Iterator i = fElementDeclarations.iterator();
+            Iterator i = fAllElementDeclarations.iterator();
             while(i.hasNext())
             {
                 ElementDeclaration ed = (ElementDeclaration)i.next();
@@ -179,8 +182,8 @@
     public TypeDefinition[] getTypeDefinitions() 
     {
         if(!fComponentsInitialized) initComponents();
-        TypeDefinition[] array = new TypeDefinition[fTypeDefinitions.size()];
-        fTypeDefinitions.toArray(array);
+        TypeDefinition[] array = new TypeDefinition[fAllTypeDefinitions.size()];
+        fAllTypeDefinitions.toArray(array);
         return array;
     }
     
@@ -194,7 +197,7 @@
         TypeDefinition typeDef = null;
         if(qname != null)
         {
-            Iterator i = fTypeDefinitions.iterator();
+            Iterator i = fAllTypeDefinitions.iterator();
             while(i.hasNext())
             {
                 TypeDefinition td = (TypeDefinition)i.next();
@@ -432,6 +435,7 @@
      */
     public Description toComponent()
     {
+        //TODO synchronizing the Component data when Element model is modified
         if(!fComponentsInitialized) {
             initComponents();
         }
@@ -442,17 +446,46 @@
      *  Non-API implementation methods
      * ************************************************************/
 
-    public void addElementDeclaration(ElementDeclaration elDec) 
+    //The 'addAllXXX' methods are used to initialize the Description Component 
+    //with its flattened properties - {Interfaces}, {Bindings}, {Services},
+    //{ElementDeclarations}, {TypeDefinitions}. Currently these are non-API
+    //public helper methods used by the implementation to convert the Element
+    //model into the Component model (i.e. the Component model is read-only).
+    //If we need to support programmatic creation/updating of the Component model,
+    //we will need to consider exposing these methods on the API.
+    
+    public void addAllInterfaces(Interface intface)
+    {
+        if(intface != null) {
+            fAllInterfaces.add(intface);
+        }
+    }
+    
+    public void addAllBindings(Binding binding)
+    {
+        if(binding != null) {
+            fAllBindings.add(binding);
+        }
+    }
+    
+    public void addAllServices(Service service)
+    {
+        if(service != null) {
+            fAllServices.add(service);
+        }
+    }
+    
+    public void addAllElementDeclarations(ElementDeclaration elDec) 
     {
         if(elDec != null) {
-            fElementDeclarations.add(elDec);
+            fAllElementDeclarations.add(elDec);
         }
     }
 
-    public void addTypeDefinition(TypeDefinition typeDef) 
+    public void addAllTypeDefinitions(TypeDefinition typeDef) 
     {
         if(typeDef != null) {
-            fTypeDefinitions.add(typeDef);
+            fAllTypeDefinitions.add(typeDef);
         }
     }
     



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