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 2005/11/29 20:01:32 UTC

svn commit: r349794 - in /incubator/woden/java/src/org/apache/woden: internal/schema/SchemaImpl.java internal/wsdl20/TypesImpl.java wsdl20/xml/TypesElement.java

Author: jkaputin
Date: Tue Nov 29 11:01:23 2005
New Revision: 349794

URL: http://svn.apache.org/viewcvs?rev=349794&view=rev
Log:
modified the methods on the TypesElement interface. 
Now have:
Schema[] getSchemas()
Schema[] getSchemas(URI namespace)
InlineSchema[] getInlinedSchemas()
ImportedSchema[] getImportedSchemas()

and modified implementation accordingly.

Modified:
    incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java
    incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java
    incubator/woden/java/src/org/apache/woden/wsdl20/xml/TypesElement.java

Modified: incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java?rev=349794&r1=349793&r2=349794&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java Tue Nov 29 11:01:23 2005
@@ -85,4 +85,9 @@
     public boolean isReferenceable() {
         return fIsReferenceable;
     }
+    
+    public String getNamespaceAsString()
+    {
+        return fNamespace != null ? fNamespace.toString() : null;
+    }
 }

Modified: incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java?rev=349794&r1=349793&r2=349794&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java Tue Nov 29 11:01:23 2005
@@ -16,17 +16,15 @@
 package org.apache.woden.internal.wsdl20;
 
 import java.net.URI;
-import java.util.Collection;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import java.util.Vector;
 
 import javax.xml.namespace.QName;
 
 import org.apache.woden.internal.schema.SchemaImpl;
+import org.apache.woden.schema.ImportedSchema;
+import org.apache.woden.schema.InlinedSchema;
 import org.apache.woden.schema.Schema;
 import org.apache.woden.wsdl20.xml.TypesElement;
 import org.apache.ws.commons.schema.XmlSchema;
@@ -42,7 +40,7 @@
                        implements TypesElement 
 {
     private String fTypeSystem;
-    private Map fSchemaMap = new HashMap();
+    private List fSchemas = new Vector();
     
     //TODO extension attributes and elements
 
@@ -72,48 +70,98 @@
      */
     public void addSchema(Schema schema)
     {
-        //add to the namespace-keyed map of Lists of Schema objects
-        URI namespace = schema.getNamespace();
-        String ns = namespace != null ? namespace.toString() : null;
-        List schemas = (List)fSchemaMap.get(ns);
-        if(schemas == null)
-        {
-            schemas = new Vector();
-            fSchemaMap.put(ns, schemas);
+        if(schema != null) {
+            fSchemas.add(schema);
         }
-        schemas.add(schema);
     }
     
+    /*
+     * @see org.apache.woden.wsdl20.xml.TypesElement#removeSchema(org.apache.woden.schema.Schema)
+     */
+    public void removeSchema(Schema schema)
+    {
+        fSchemas.remove(schema);
+    }
     
-    //TODO what if id is null and there is more than one inline schema for this namespace?
-
     /*
-     * @see org.apache.woden.wsdl20.xml.TypesElement#removeSchema(java.net.URI, java.lang.String)
+     * @see org.apache.woden.wsdl20.xml.TypesElement#getSchemas()
      */
-    public void removeSchema(URI namespace, String id)
+    public Schema[] getSchemas()
     {
-        //TODO remove the Schema
-        //update the list of in-scope schemas
+        Schema[] array = new Schema[fSchemas.size()];
+        fSchemas.toArray(array);
+        return array;
+    }
+    
+    /*
+     * @see org.apache.woden.wsdl20.xml.TypesElement#getSchemas(java.net.URI)
+     */
+    public Schema[] getSchemas(URI namespace)
+    {
+        List schemas = new Vector();
+        Iterator i = fSchemas.iterator();
+        
+        if(namespace != null)
+        {
+            while(i.hasNext()) {
+                Schema s = (Schema)i.next();
+                if(namespace.equals(s.getNamespace())) {
+                    schemas.add(s);
+                }
+            }
+        } 
+        else 
+        {
+            //get schemas whose namespace is missing
+            while(i.hasNext()) {
+                Schema s = (Schema)i.next();
+                if(s.getNamespace() == null) {
+                    schemas.add(s);
+                }
+            }
+        }
+        
+        Schema[] array = new Schema[schemas.size()];
+        schemas.toArray(array);
+        return array;
     }
     
     /*
-     * @see org.apache.woden.wsdl20.xml.TypesElement#getSchema(java.net.URI, java.lang.String)
+     * @see org.apache.woden.wsdl20.xml.TypesElement#getInlinedSchemas()
      */
-    public Schema getSchema(URI namespace, String id)
+    public InlinedSchema[] getInlinedSchemas()
     {
-        //TODO tbc
-        return null;
+        List schemas = new Vector();
+        Iterator i = fSchemas.iterator();
+        while(i.hasNext()) {
+            Schema s = (Schema)i.next();
+            if(s instanceof InlinedSchema) {
+                schemas.add(s);
+            }
+        }
+        
+        InlinedSchema[] array = new InlinedSchema[schemas.size()];
+        schemas.toArray(array);
+        return array;
     }
     
     /*
-     * TODO instead of Map return value, use a type safe collection object that can return either 
-     * the entry-sequence list or the namespace-keyed map of SchemaReference objects.
-     * 
-     * @see org.apache.woden.wsdl20.xml.TypesElement#getSchemas()
+     * @see org.apache.woden.wsdl20.xml.TypesElement#getImportedSchemas()
      */
-    public Map getSchemas()
+    public ImportedSchema[] getImportedSchemas()
     {
-        return fSchemaMap;
+        List schemas = new Vector();
+        Iterator i = fSchemas.iterator();
+        while(i.hasNext()) {
+            Schema s = (Schema)i.next();
+            if(s instanceof ImportedSchema) {
+                schemas.add(s);
+            }
+        }
+        
+        ImportedSchema[] array = new ImportedSchema[schemas.size()];
+        schemas.toArray(array);
+        return array;
     }
     
     /* ************************************************************
@@ -202,65 +250,42 @@
      */
     public List getReferenceableSchemaDefs()
     {
-        List refSchemas = new Vector();
-        Collection schemaLists = fSchemaMap.values();
-        Iterator i = schemaLists.iterator();
+        List schemas = new Vector();
+        Iterator i = fSchemas.iterator();
         while(i.hasNext())
         {
-            List schemas = (List)i.next();
-            Iterator i2 = schemas.iterator();
-            while(i2.hasNext())
-            {
-                SchemaImpl schema = (SchemaImpl)i2.next();
-                if(schema.isReferenceable())
-                {
-                    refSchemas.add(schema.getSchemaDefinition());
-                }
+            SchemaImpl s = (SchemaImpl)i.next();
+            if(s.isReferenceable()) {
+                schemas.add(s.getSchemaDefinition());
             }
         }
-        return refSchemas;
+        return schemas;
     }
     
     /*
-     * Return a namespace-keyed Map of Lists of XmlSchema for all schemas that are 
-     * referenceable by the containing WSDL.
+     * 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.
      */
-    private Map getReferenceableSchemaDefsByNamespace()
+    private List getReferenceableSchemaDefs(String namespace)
     {
-        Map refSchemaMap = new HashMap();
-        Set namespaces = fSchemaMap.keySet();
-        Iterator i = namespaces.iterator();
-        while(i.hasNext())
+        
+        List schemas = new Vector();
+        if(namespace != null)
         {
-            List refSchemaList = new Vector();
-            String namespace = (String)i.next();
-            List schemas = (List)fSchemaMap.get(namespace);
-            Iterator i2 = schemas.iterator();
-            while(i2.hasNext())
+            Iterator i = fSchemas.iterator();
+            while(i.hasNext())
             {
-                SchemaImpl schema = (SchemaImpl)i2.next();
-                if(schema.isReferenceable())
-                {
-                    refSchemaList.add(schema.getSchemaDefinition());
+                SchemaImpl s = (SchemaImpl)i.next();
+                if(s.isReferenceable() && namespace.equals(s.getNamespaceAsString())) {
+                    schemas.add(s.getSchemaDefinition());
                 }
             }
-            refSchemaMap.put(namespace, refSchemaList);
         }
-        return refSchemaMap;
+        return schemas;
     }
     
     /*
-     * Return a Lists of XmlSchema for all schemas with the specified target namespace 
-     * or import namespace that are referenceable by the WSDL.
-     */
-    private List getReferenceableSchemaDefs(String namespace)
-    {
-        Map refSchemaMap = getReferenceableSchemaDefsByNamespace();
-        return (List)refSchemaMap.get(namespace);
-    }
-    
-    
-    /*
      * TODO decide if needed on API or by internally - delete if not used.
      * 
      * Indicates if the namespace represented by the specified URI
@@ -307,8 +332,16 @@
         boolean result = false;
         if(namespace != null)
         {
-            Map schemas = getReferenceableSchemaDefsByNamespace();
-            result = schemas.containsKey(namespace);
+            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/java/src/org/apache/woden/wsdl20/xml/TypesElement.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/wsdl20/xml/TypesElement.java?rev=349794&r1=349793&r2=349794&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/wsdl20/xml/TypesElement.java (original)
+++ incubator/woden/java/src/org/apache/woden/wsdl20/xml/TypesElement.java Tue Nov 29 11:01:23 2005
@@ -16,8 +16,9 @@
 package org.apache.woden.wsdl20.xml;
 
 import java.net.URI;
-import java.util.Map;
 
+import org.apache.woden.schema.ImportedSchema;
+import org.apache.woden.schema.InlinedSchema;
 import org.apache.woden.schema.Schema;
 
 /**
@@ -52,11 +53,6 @@
      */
     public String getTypeSystem();
     
-    /*
-     * All schemas, whether inlined or imported, are represented by TypesElement as 
-     * SchemaReference objects, which contain a reference to the schema definition.
-     */
-    
     /**
      * Add a Schema object for a schema inlined or imported within the <types> element.
      * 
@@ -64,29 +60,51 @@
      */
     public void addSchema(Schema schema);
     
-    //TODO what if id is null and there is more than one inline schema for this namespace?
-    //Delete all or raise an error?
+    /**
+     * Delete the specified Schema object.
+     */
+    public void removeSchema(Schema schema);
+    
+    /**
+     * Return the Schemas representing all inlined schemas or schema imports,
+     * in the order in which they occur within the <types> element.
+     * 
+     * @return an array of Schema objects
+     */
+    public Schema[] getSchemas();
     
     /**
-     * Delete the Schema object for the schema with the specified target namespace and (optionally) id.
+     * 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 <types> element.
+     * <p>
+     * A null namespace argument will return any inlined schemas missing their
+     * target namespace attribute or any schema imports missing their namespace 
+     * attribute.
+     * 
+     * @return the Schemas for the schema with the specified target namespace.
      */
-    public void removeSchema(URI targetNamespace, String id);
+    public Schema[] getSchemas(URI namespace);
     
     /**
-     * @return the Schema object for the schema with the specified target namespace and (optionally) id.
+     * Return all schemas inlined within the &lt;types&gt; element, in the order
+     * in which they occur within &lt;types&gt;.
+     * 
+     * @return an array of Schema objects.
      */
-    public Schema getSchema(URI targetNamespace, String id);
+    public InlinedSchema[] getInlinedSchemas();
     
     /**
-     * TODO create a collection object to wrap the Map in a type safe way.
+     * Return all schema imports from within the &lt;types&gt; element, in the order
+     * in which they occur within &lt;types&gt;.
      * 
-     * @return a map of Schema objects keyed by namespace.
+     * @return an array of Schema objects.
      */
-    public Map getSchemas();
+    public ImportedSchema[] getImportedSchemas();
     
-    //TODO is there a use case to get or remove all schemas for a given namespace?
+    //TODO is there a use case to remove all schemas for a given namespace?
     //E.g.
-    //public Schema[] getSchemas(String namespace);
     //public void removeSchemas(String namespace);
 
 



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