You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/07/28 19:19:10 UTC

svn commit: r560573 - in /incubator/tuscany/java/sca/modules: contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ interface-wsdl-xml/src/test/java/org/a...

Author: rfeng
Date: Sat Jul 28 10:19:09 2007
New Revision: 560573

URL: http://svn.apache.org/viewvc?view=rev&rev=560573
Log:
Add the support to resolve and load WSDL definitions on demand

Modified:
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelper.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospectorTestCase.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationTestCase.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java (original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java Sat Jul 28 10:19:09 2007
@@ -18,10 +18,8 @@
  */
 package org.apache.tuscany.sca.contribution.resolver;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -30,46 +28,37 @@
  * @version $Rev$ $Date$
  */
 public class DefaultModelResolverExtensionPoint implements ModelResolverExtensionPoint {
-    protected final Map<Class<?>, Class<? extends ModelResolver>> resolversByModelType = new HashMap<Class<?>, Class<? extends ModelResolver>>();
-    
+    protected final Map<Class<?>, Class<? extends ModelResolver>> resolversByModelType =
+        new HashMap<Class<?>, Class<? extends ModelResolver>>();
+
     /**
      * Constructs a new model resolver registry.
      */
     public DefaultModelResolverExtensionPoint() {
     }
 
-    public void addResolver(Class<?> modelType, Class <? extends ModelResolver> resolver) {
-        
+    public void addResolver(Class<?> modelType, Class<? extends ModelResolver> resolver) {
         resolversByModelType.put(modelType, resolver);
     }
-    
+
     public void removeResolver(Class<?> modelType) {
         resolversByModelType.remove(modelType);
     }
 
-    public Class <? extends ModelResolver> getResolver(Class<?> modelType) {
+    public Class<? extends ModelResolver> getResolver(Class<?> modelType) {
         Class<?>[] classes = modelType.getInterfaces();
         for (Class<?> c : classes) {
-            Class <? extends ModelResolver> resolver = resolversByModelType.get(c);
+            Class<? extends ModelResolver> resolver = resolversByModelType.get(c);
             if (resolver != null) {
                 return resolver;
             }
         }
-        
+
         return resolversByModelType.get(modelType);
     }
 
-    @SuppressWarnings("unchecked")
     public Collection<Class<?>> getResolverTypes() {
-        Collection<Class<?>> resolverTypes = new ArrayList<Class<?>>();
-        
-        Iterator typeIterator = resolversByModelType.keySet().iterator(); 
-        while (typeIterator.hasNext()) {
-            resolverTypes.add( (Class) typeIterator.next() );
-        }
-        
-        return resolverTypes;
+        return resolversByModelType.keySet();
     }
-    
-    
+
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java Sat Jul 28 10:19:09 2007
@@ -24,11 +24,9 @@
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Hashtable;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Vector;
 
 import javax.wsdl.Binding;
 import javax.wsdl.BindingOperation;
@@ -40,13 +38,12 @@
 import javax.wsdl.Port;
 import javax.wsdl.PortType;
 import javax.wsdl.Service;
-import javax.wsdl.Types;
 import javax.wsdl.WSDLException;
-import javax.wsdl.extensions.ExtensionRegistry;
-import javax.wsdl.extensions.schema.Schema;
-import javax.wsdl.xml.WSDLLocator;
-import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -55,10 +52,7 @@
 import org.apache.tuscany.sca.contribution.service.ContributionRuntimeException;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
-import org.apache.tuscany.sca.interfacedef.wsdl.xml.XMLDocumentHelper.URIResolverImpl;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
+import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
 
 /**
  * An ArtifactProcessor for WSDL documents.
@@ -67,63 +61,13 @@
  */
 public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinition> {
 
-    private javax.wsdl.factory.WSDLFactory wsdlFactory;
-    private ExtensionRegistry wsdlExtensionRegistry;
-    private WSDLFactory factory;
-
-    private Map<String, WSDLDefinition> loadedDefinitions = new Hashtable<String, WSDLDefinition>();
-
-    /**
-     * Implementation of a WSDL locator.
-     */
-    private class WSDLLocatorImpl implements WSDLLocator {
-        private InputStream inputStream;
-        private URL base;
-        private String latestImportURI;
-
-        public WSDLLocatorImpl(URL base, InputStream is) {
-            this.base = base;
-            this.inputStream = is;
-        }
-
-        public void close() {
-            try {
-                inputStream.close();
-            } catch (IOException e) {
-                // Ignore
-            }
-        }
-
-        public InputSource getBaseInputSource() {
-            try {
-                return XMLDocumentHelper.getInputSource(base, inputStream);
-            } catch (IOException e) {
-                throw new IllegalArgumentException(e);
-            }
-        }
-
-        public String getBaseURI() {
-            return base.toString();
-        }
+    public static final QName WSDL11 = new QName("http://schemas.xmlsoap.org/wsdl/", "definitions");
+    public static final QName XSD = new QName("http://www.w3.org/2001/XMLSchema", "schema");
 
-        public InputSource getImportInputSource(String parentLocation, String importLocation) {
-            try {
-                if (importLocation == null || importLocation.startsWith("/")) {
-                    return null;
-                }
-                URL url = new URL(new URL(parentLocation), importLocation);
-                latestImportURI = url.toString();
-                return XMLDocumentHelper.getInputSource(url);
-            } catch (Exception e) {
-                throw new ContributionRuntimeException(e);
-            }
-        }
-
-        public String getLatestImportURI() {
-            return latestImportURI;
-        }
+    private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
 
-    }
+    private javax.wsdl.factory.WSDLFactory wsdlFactory;
+    private WSDLFactory factory;
 
     public WSDLDocumentProcessor(WSDLFactory factory, javax.wsdl.factory.WSDLFactory wsdlFactory) {
         this.factory = factory;
@@ -138,76 +82,12 @@
             }
         }
 
-        wsdlExtensionRegistry = this.wsdlFactory.newPopulatedExtensionRegistry();
     }
 
-    private void readInlineSchemas(Definition definition, WSDLDefinition wsdlDefinition) {
-        Types types = definition.getTypes();
-        if (types != null) {
-            wsdlDefinition.getInlinedSchemas().setSchemaResolver(new URIResolverImpl());
-            for (Object ext : types.getExtensibilityElements()) {
-                if (ext instanceof Schema) {
-                    Element element = ((Schema)ext).getElement();
-
-                    XmlSchemaCollection schemaCollection = wsdlDefinition.getInlinedSchemas();
-                    schemaCollection.setBaseUri(((Schema)ext).getDocumentBaseURI());
-
-                    wsdlDefinition.getInlinedSchemas().read(element, element.getBaseURI());
-                }
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
     public WSDLDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
         try {
-
-            // Read a WSDL document
-            InputStream is = artifactURL.openStream();
-            WSDLReader reader = wsdlFactory.newWSDLReader();
-            reader.setFeature("javax.wsdl.verbose", false);
-            reader.setFeature("javax.wsdl.importDocuments", true);
-            // FIXME: We need to decide if we should disable the import processing by WSDL4J
-            // reader.setFeature("javax.wsdl.importDocuments", false);
-            reader.setExtensionRegistry(wsdlExtensionRegistry);
-
-            WSDLLocatorImpl locator = new WSDLLocatorImpl(artifactURL, is);
-            Definition definition = reader.readWSDL(locator);
-
-            WSDLDefinition wsdlDefinition = loadedDefinitions.get(definition.getTargetNamespace());
-            if (wsdlDefinition != null) {
-                merge(wsdlDefinition.getDefinition(), definition);
-            } else {
-                wsdlDefinition = factory.createWSDLDefinition();
-                wsdlDefinition.setDefinition(definition);
-                loadedDefinitions.put(definition.getTargetNamespace(), wsdlDefinition);
-            }
-
-            //Read inline schemas 
-            readInlineSchemas(definition, wsdlDefinition);
-
-            //read the inline schemas for wsdl imports
-            if (definition.getImports().size() > 0) {
-                Iterator<Vector<Import>> importsIterator = definition.getImports().values().iterator();
-                Vector<Import> imports = null;
-                Import anImport = null;
-                while (importsIterator.hasNext()) {
-                    imports = importsIterator.next();
-                    for (int count = 0; count < imports.size(); ++count) {
-                        anImport = imports.elementAt(count);
-                        // Read inline schemas 
-                        if (anImport.getDefinition() != null) {
-                            readInlineSchemas(anImport.getDefinition(), wsdlDefinition);
-                        }
-                    }
-                }
-            }
-
-            return wsdlDefinition;
-
-        } catch (WSDLException e) {
-            throw new ContributionReadException(e);
-        } catch (IOException e) {
+            return indexRead(artifactURL);
+        } catch (Exception e) {
             throw new ContributionReadException(e);
         }
     }
@@ -223,6 +103,7 @@
                         continue;
                     }
                     if (imp.getLocationURI() == null) {
+                        // FIXME: [rfeng] By the WSDL 1.1 spec, the location attribute is required
                         // We need to resolve it by QName
                         WSDLDefinition proxy = factory.createWSDLDefinition();
                         proxy.setUnresolved(true);
@@ -275,6 +156,24 @@
     }
 
     /**
+     * Create a facade Definition which imports all the defintions
+     * 
+     * @param definitions
+     * @return
+     */
+    private Definition merge(Collection<Definition> definitions) {
+        Definition merged = wsdlFactory.newDefinition();
+        for (Definition d : definitions) {
+            Import imp = merged.createImport();
+            imp.setNamespaceURI(d.getTargetNamespace());
+            imp.setDefinition(d);
+            imp.setLocationURI(d.getDocumentBaseURI());
+            merged.addImport(imp);
+        }
+        return merged;
+    }
+
+    /**
      * Merge a set of WSDLs into a facade Definition
      * 
      * @param definitions
@@ -478,6 +377,55 @@
             return element;
         }
 
+    }
+
+    /**
+     * Read the namespace for the WSDL definition and inline schemas
+     * 
+     * @param doc
+     * @return
+     * @throws IOException
+     * @throws XMLStreamException
+     */
+    protected WSDLDefinition indexRead(URL doc) throws Exception {
+        WSDLDefinition wsdlDefinition = factory.createWSDLDefinition();
+        wsdlDefinition.setUnresolved(true);
+        wsdlDefinition.setLocation(doc.toURI());
+
+        InputStream is = doc.openStream();
+        try {
+            XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+            int eventType = reader.getEventType();
+            while (true) {
+                if (eventType == XMLStreamConstants.START_ELEMENT) {
+                    if (WSDL11.equals(reader.getName())) {
+                        String tns = reader.getAttributeValue(null, "targetNamespace");
+                        wsdlDefinition.setNamespace(tns);
+                        // The definition is marked as resolved but not loaded
+                        wsdlDefinition.setUnresolved(false);
+                        wsdlDefinition.setDefinition(null);
+                    }
+                    if (XSD.equals(reader.getName())) {
+                        String tns = reader.getAttributeValue(null, "targetNamespace");
+                        XSDefinition xsd = factory.createXSDefinition();
+                        xsd.setUnresolved(true);
+                        xsd.setNamespace(tns);
+                        // The definition is marked as resolved but not loaded
+                        xsd.setUnresolved(false);
+                        xsd.setSchema(null);
+                        wsdlDefinition.getXmlSchemas().add(xsd);
+                    }
+                }
+                if (reader.hasNext()) {
+                    eventType = reader.next();
+                } else {
+                    break;
+                }
+            }
+            return wsdlDefinition;
+        } finally {
+            is.close();
+        }
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java Sat Jul 28 10:19:09 2007
@@ -19,61 +19,352 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl.xml;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Message;
+import javax.wsdl.PortType;
+import javax.wsdl.Types;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.xml.WSDLLocator;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
 import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.DeployedArtifact;
 import org.apache.tuscany.sca.contribution.Import;
 import org.apache.tuscany.sca.contribution.NamespaceImport;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionRuntimeException;
+import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.xml.XMLDocumentHelper.URIResolverImpl;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
 
 /**
  * A Model Resolver for WSDL models.
- *
+ * 
  * @version $Rev: 557916 $ $Date: 2007-07-20 01:04:40 -0700 (Fri, 20 Jul 2007) $
  */
 public class WSDLModelResolver implements ModelResolver {
     private Contribution contribution;
-    private Map<String, WSDLDefinition> map = new HashMap<String, WSDLDefinition>();
-    
+    private Map<String, List<WSDLDefinition>> map = new HashMap<String, List<WSDLDefinition>>();
+
     public WSDLModelResolver(Contribution contribution) {
         this.contribution = contribution;
+        // FIXME: [rfeng] To avoid the hard-coded factories
+        try {
+            this.factory = new DefaultWSDLFactory();
+            this.wsdlFactory = javax.wsdl.factory.WSDLFactory.newInstance();
+            wsdlExtensionRegistry = this.wsdlFactory.newPopulatedExtensionRegistry();
+        } catch (WSDLException e) {
+            throw new ContributionRuntimeException(e);
+        }
     }
 
+    /**
+     * Implementation of a WSDL locator.
+     */
+    private class WSDLLocatorImpl implements WSDLLocator {
+        private InputStream inputStream;
+        private URL base;
+        private String latestImportURI;
+
+        public WSDLLocatorImpl(URL base, InputStream is) {
+            this.base = base;
+            this.inputStream = is;
+        }
+
+        public void close() {
+            try {
+                inputStream.close();
+            } catch (IOException e) {
+                // Ignore
+            }
+        }
+
+        public InputSource getBaseInputSource() {
+            try {
+                return XMLDocumentHelper.getInputSource(base, inputStream);
+            } catch (IOException e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+
+        public String getBaseURI() {
+            return base.toString();
+        }
+
+        public InputSource getImportInputSource(String parentLocation, String importLocation) {
+            try {
+                if (importLocation == null) {
+                    throw new IllegalArgumentException("Required attribute 'location' is missing.");
+                }
+
+                URL url = null;
+                if (importLocation.startsWith("/")) {
+                    // The URI is relative to the contribution
+                    String uri = importLocation.substring(1);
+                    for (DeployedArtifact a : contribution.getArtifacts()) {
+                        if (a.getURI().equals(uri)) {
+                            url = new URL(a.getLocation());
+                            break;
+                        }
+                    }
+                } else {
+                    url = new URL(new URL(parentLocation), importLocation);
+                }
+                if (url == null) {
+                    return null;
+                }
+                latestImportURI = url.toString();
+                return XMLDocumentHelper.getInputSource(url);
+            } catch (Exception e) {
+                throw new ContributionRuntimeException(e);
+            }
+        }
+
+        public String getLatestImportURI() {
+            return latestImportURI;
+        }
+
+    }
+
+    private javax.wsdl.factory.WSDLFactory wsdlFactory;
+    private ExtensionRegistry wsdlExtensionRegistry;
+    private WSDLFactory factory;
+
     public void addModel(Object resolved) {
         WSDLDefinition definition = (WSDLDefinition)resolved;
-        map.put(definition.getNamespace(), definition);
+        List<WSDLDefinition> list = map.get(definition.getNamespace());
+        if (list == null) {
+            list = new ArrayList<WSDLDefinition>();
+            map.put(definition.getNamespace(), list);
+        }
+        list.add(definition);
     }
-    
+
     public Object removeModel(Object resolved) {
-        return map.remove(((WSDLDefinition)resolved).getNamespace());
+        WSDLDefinition definition = (WSDLDefinition)resolved;
+        List<WSDLDefinition> list = map.get(definition.getNamespace());
+        if (list == null) {
+            return null;
+        } else {
+            return list.remove(definition);
+        }
+    }
+
+    /**
+     * Create a facade Definition which imports all the defintions
+     * 
+     * @param definitions A list of the WSDL definitions under the same target namespace
+     * @return The aggregated WSDL definition
+     */
+    private WSDLDefinition aggregate(List<WSDLDefinition> definitions) {
+        if (definitions == null || definitions.size() == 0) {
+            return null;
+        }
+        if (definitions.size() == 1) {
+            WSDLDefinition d = definitions.get(0);
+            loadOnDemand(d, d.getInlinedSchemas());
+            return d;
+        }
+        WSDLDefinition aggregated = factory.createWSDLDefinition();
+        for (WSDLDefinition d : definitions) {
+            loadOnDemand(d, aggregated.getInlinedSchemas());
+        }
+        Definition facade = wsdlFactory.newDefinition();
+        String ns = definitions.get(0).getNamespace();
+        facade.setQName(new QName(ns, "$aggregated$"));
+        facade.setTargetNamespace(ns);
+
+        for (WSDLDefinition d : definitions) {
+            if (d.getDefinition() != null) {
+                javax.wsdl.Import imp = facade.createImport();
+                imp.setNamespaceURI(d.getNamespace());
+                imp.setDefinition(d.getDefinition());
+                imp.setLocationURI(d.getDefinition().getDocumentBaseURI());
+                facade.addImport(imp);
+            }
+        }
+        aggregated.setDefinition(facade);
+        definitions.clear();
+        definitions.add(aggregated);
+        return aggregated;
     }
-    
+
     public <T> T resolveModel(Class<T> modelClass, T unresolved) {
-        
+
         // Lookup a definition for the given namespace
         String namespace = ((WSDLDefinition)unresolved).getNamespace();
-        WSDLDefinition resolved = (WSDLDefinition) map.get(namespace);
-        if (resolved != null) {
-            return (T)resolved;
+        List<WSDLDefinition> list = map.get(namespace);
+        WSDLDefinition resolved = aggregate(list);
+        if (resolved != null && !resolved.isUnresolved()) {
+            return modelClass.cast(resolved);
         }
-        
+
         // No definition found, delegate the resolution to the imports
         for (Import import_ : this.contribution.getImports()) {
             if (import_ instanceof NamespaceImport) {
                 NamespaceImport namespaceImport = (NamespaceImport)import_;
                 if (namespaceImport.getNamespace().equals(namespace)) {
-                    
+
                     // Delegate the resolution to the import resolver
-                    resolved = namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class, (WSDLDefinition)unresolved);
+                    resolved =
+                        namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class,
+                                                                        (WSDLDefinition)unresolved);
                     if (!resolved.isUnresolved()) {
-                        return (T)resolved;
+                        return modelClass.cast(resolved);
                     }
                 }
             }
         }
-        return (T)unresolved;
+        return modelClass.cast(unresolved);
+    }
+
+    /**
+     * Load the WSDL definition on demand
+     * @param def
+     * @param schemaCollection
+     */
+    private void loadOnDemand(WSDLDefinition def, XmlSchemaCollection schemaCollection) {
+        if (def.getDefinition() == null && def.getLocation() != null) {
+            // Load the definition on-demand
+            try {
+                loadDefinition(def, schemaCollection);
+            } catch (ContributionReadException e) {
+                throw new RuntimeException(e);
+            }
+        }
     }
-    
+
+    // private Map<String, WSDLDefinition> loadedDefinitions = new Hashtable<String, WSDLDefinition>();
+
+    /**
+     * Merge a set of WSDLs into a facade Definition
+     * 
+     * @param definitions
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    private Definition merge(Definition target, Definition source) {
+        for (Iterator j = source.getImports().values().iterator(); j.hasNext();) {
+            List list = (List)j.next();
+            for (Iterator k = list.iterator(); k.hasNext();)
+                target.addImport((javax.wsdl.Import)k.next());
+        }
+
+        for (Iterator k = source.getBindings().values().iterator(); k.hasNext();) {
+            Binding binding = (Binding)k.next();
+            if (!binding.isUndefined())
+                target.getBindings().put(binding.getQName(), binding);
+        }
+
+        target.getExtensibilityElements().addAll(source.getExtensibilityElements());
+
+        for (Iterator k = source.getMessages().values().iterator(); k.hasNext();) {
+            Message msg = (Message)k.next();
+            if (!msg.isUndefined())
+                target.getMessages().put(msg.getQName(), msg);
+        }
+
+        target.getNamespaces().putAll(source.getNamespaces());
+
+        for (Iterator k = source.getPortTypes().values().iterator(); k.hasNext();) {
+            PortType portType = (PortType)k.next();
+            if (!portType.isUndefined())
+                target.getPortTypes().put(portType.getQName(), portType);
+        }
+
+        target.getServices().putAll(source.getServices());
+
+        if (target.getTypes() == null) {
+            target.setTypes(target.createTypes());
+        }
+        if (source.getTypes() != null)
+            target.getTypes().getExtensibilityElements().addAll(source.getTypes().getExtensibilityElements());
+        return target;
+
+    }
+
+    /**
+     * Load the WSDL definition and inline schemas
+     * 
+     * @param wsdlDef
+     * @param schemaCollection
+     * @throws ContributionReadException
+     */
+    private void loadDefinition(WSDLDefinition wsdlDef, XmlSchemaCollection schemaCollection)
+        throws ContributionReadException {
+        if (wsdlDef.getDefinition() != null || wsdlDef.getLocation() == null) {
+            return;
+        }
+        try {
+            URL artifactURL = wsdlDef.getLocation().toURL();
+            // Read a WSDL document
+            InputStream is = artifactURL.openStream();
+            WSDLReader reader = wsdlFactory.newWSDLReader();
+            reader.setFeature("javax.wsdl.verbose", false);
+            reader.setFeature("javax.wsdl.importDocuments", true);
+            // FIXME: We need to decide if we should disable the import processing by WSDL4J
+            // reader.setFeature("javax.wsdl.importDocuments", false);
+            reader.setExtensionRegistry(wsdlExtensionRegistry);
+
+            WSDLLocatorImpl locator = new WSDLLocatorImpl(artifactURL, is);
+            Definition definition = reader.readWSDL(locator);
+            wsdlDef.setDefinition(definition);
+
+            //Read inline schemas 
+            readInlineSchemas(definition, schemaCollection);
+        } catch (WSDLException e) {
+            throw new ContributionReadException(e);
+        } catch (IOException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+
+    /**
+     * Populate the inline schemas including those from the imported definitions
+     * 
+     * @param definition
+     * @param schemaCollection
+     */
+    private void readInlineSchemas(Definition definition, XmlSchemaCollection schemaCollection) {
+        Types types = definition.getTypes();
+        if (types != null) {
+            schemaCollection.setSchemaResolver(new URIResolverImpl());
+            for (Object ext : types.getExtensibilityElements()) {
+                if (ext instanceof Schema) {
+                    Element element = ((Schema)ext).getElement();
+                    schemaCollection.setBaseUri(((Schema)ext).getDocumentBaseURI());
+                    schemaCollection.read(element, element.getBaseURI());
+                }
+            }
+        }
+        for (Object imports : definition.getImports().values()) {
+            List impList = (List)imports;
+            for (Object i : impList) {
+                javax.wsdl.Import anImport = (javax.wsdl.Import)i;
+                // Read inline schemas 
+                if (anImport.getDefinition() != null) {
+                    readInlineSchemas(anImport.getDefinition(), schemaCollection);
+                }
+            }
+        }
+    }
+
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelper.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelper.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelper.java Sat Jul 28 10:19:09 2007
@@ -150,8 +150,8 @@
 
     private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
 
-    public static String readTargetNamespace(URL doc, QName element, String attribute) throws IOException,
-        XMLStreamException {
+    public static String readTargetNamespace(URL doc, QName element, boolean rootOnly, String attribute)
+        throws IOException, XMLStreamException {
         if (attribute == null) {
             attribute = "targetNamespace";
         }
@@ -160,8 +160,12 @@
             XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
             int eventType = reader.getEventType();
             while (true) {
-                if (eventType == XMLStreamConstants.START_ELEMENT && element.equals(reader.getName())) {
-                    return reader.getAttributeValue(null, attribute);
+                if (eventType == XMLStreamConstants.START_ELEMENT) {
+                    if (element.equals(reader.getName())) {
+                        return reader.getAttributeValue(null, attribute);
+                    } else if (rootOnly) {
+                        return null;
+                    }
                 }
                 if (reader.hasNext()) {
                     eventType = reader.next();

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java Sat Jul 28 10:19:09 2007
@@ -25,6 +25,9 @@
 import java.net.URI;
 import java.net.URL;
 
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
 import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.contribution.service.ContributionReadException;
@@ -36,7 +39,7 @@
 
 /**
  * An ArtifactProcessor for XSD documents.
- *
+ * 
  * @version $Rev$ $Date$
  */
 public class XSDDocumentProcessor implements URLArtifactProcessor<XSDefinition> {
@@ -46,39 +49,48 @@
     public XSDDocumentProcessor(WSDLFactory factory) {
         this.factory = factory;
     }
-    
+
     public XSDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
         try {
 
             // Read an XSD document
             InputStream is = artifactURL.openStream();
             try {
-    
+
                 XmlSchemaCollection collection = new XmlSchemaCollection();
                 collection.setSchemaResolver(new XMLDocumentHelper.URIResolverImpl());
                 XmlSchema schema = collection.read(new InputStreamReader(is), null);
-    
+
                 XSDefinition xsDefinition = factory.createXSDefinition();
                 xsDefinition.setSchema(schema);
-                
+
                 return xsDefinition;
             } finally {
                 is.close();
             }
-            
+
         } catch (IOException e) {
             throw new ContributionReadException(e);
         }
     }
-    
+
     public void resolve(XSDefinition model, ModelResolver resolver) throws ContributionResolveException {
     }
-    
+
     public String getArtifactType() {
         return ".xsd";
     }
-    
+
     public Class<XSDefinition> getModelType() {
         return XSDefinition.class;
+    }
+
+    public static final QName XSD = new QName("http://www.w3.org/2001/XMLSchema", "schema");
+
+    protected XSDefinition indexRead(URL doc) throws IOException, XMLStreamException {
+        XSDefinition xsd = factory.createXSDefinition();
+        xsd.setNamespace(XMLDocumentHelper.readTargetNamespace(doc, XSD, true, "targetNamespace"));
+        xsd.setUnresolved(true);
+        return xsd;
     }
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospectorTestCase.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospectorTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospectorTestCase.java Sat Jul 28 10:19:09 2007
@@ -38,6 +38,7 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLDocumentProcessor;
+import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLModelResolver;
 
 /**
  * Test case for InterfaceWSDLIntrospectorImpl
@@ -59,7 +60,9 @@
         resolver = new TestModelResolver();
         URL url = getClass().getResource("../xml/stockquote.wsdl");
         definition = registry.read(null, new URI("stockquote.wsdl"), url);
-        portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
+        WSDLModelResolver wsdlResolver = new WSDLModelResolver(null);
+        wsdlResolver.addModel(definition);
+        definition = wsdlResolver.resolveModel(WSDLDefinition.class, definition);        portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
     }
 
     @SuppressWarnings("unchecked")

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationTestCase.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationTestCase.java Sat Jul 28 10:19:09 2007
@@ -37,6 +37,7 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLDocumentProcessor;
+import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLModelResolver;
 
 /**
  * Test case for WSDLOperation
@@ -46,6 +47,7 @@
         new QName("http://example.com/stockquote.wsdl", "StockQuotePortType");
 
     private WSDLDocumentProcessor processor;
+    private WSDLModelResolver wsdlResolver;
     private ModelResolver resolver;
     private WSDLFactory wsdlFactory;
 
@@ -55,6 +57,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         processor = new WSDLDocumentProcessor(new DefaultWSDLFactory(), null);
+        wsdlResolver = new WSDLModelResolver(null);
         resolver = new TestModelResolver();
         wsdlFactory = new DefaultWSDLFactory();
     }
@@ -63,6 +66,8 @@
     public final void testWrappedOperation() throws Exception {
         URL url = getClass().getResource("../xml/stockquote.wsdl");
         WSDLDefinition definition = processor.read(null, new URI("stockquote.wsdl"), url);
+        wsdlResolver.addModel(definition);
+        definition = wsdlResolver.resolveModel(WSDLDefinition.class, definition);
         PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
         Operation operation = portType.getOperation("getLastTradePrice", null, null);
 
@@ -91,6 +96,8 @@
     public final void testUnwrappedOperation() throws Exception {
         URL url = getClass().getResource("../xml/unwrapped-stockquote.wsdl");
         WSDLDefinition definition = processor.read(null, new URI("unwrapped-stockquote.wsdl"), url);
+        wsdlResolver.addModel(definition);
+        definition = wsdlResolver.resolveModel(WSDLDefinition.class, definition);
         PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
 
         Operation operation = portType.getOperation("getLastTradePrice1", null, null);
@@ -107,6 +114,8 @@
     public final void testInvalidWSDL() throws Exception {
         URL url = getClass().getResource("../xml/invalid-stockquote.wsdl");
         WSDLDefinition definition = processor.read(null, new URI("invalid-stockquote.wsdl"), url);
+        wsdlResolver.addModel(definition);
+        definition = wsdlResolver.resolveModel(WSDLDefinition.class, definition);
         PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
 
         Operation operation = portType.getOperation("getLastTradePrice", null, null);

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java Sat Jul 28 10:19:09 2007
@@ -34,6 +34,7 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLDocumentProcessor;
+import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLModelResolver;
 
 /**
  * Test case for WSDLOperation
@@ -44,6 +45,7 @@
     private WSDLDocumentProcessor registry;
     private ModelResolver resolver;
     private WSDLFactory wsdlFactory;
+    private WSDLModelResolver wsdlResolver;
 
     /**
      * @see junit.framework.TestCase#setUp()
@@ -53,11 +55,14 @@
         registry = new WSDLDocumentProcessor(new DefaultWSDLFactory(), null);
         resolver = new TestModelResolver();
         wsdlFactory = new DefaultWSDLFactory();
+        wsdlResolver = new WSDLModelResolver(null);
     }
 
     public final void testWrappedOperation() throws Exception {
         URL url = getClass().getResource("../xml/stockquote.wsdl");
         WSDLDefinition definition = registry.read(null, new URI("stockquote.wsdl"), url);
+        wsdlResolver.addModel(definition);
+        definition = wsdlResolver.resolveModel(WSDLDefinition.class, definition);
         PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
         Operation operation = portType.getOperation("getLastTradePrice", null, null);
         WSDLOperation op = new WSDLOperation(wsdlFactory, operation, definition.getInlinedSchemas(), "org.w3c.dom.Node", resolver);
@@ -69,6 +74,8 @@
     public final void testUnwrappedOperation() throws Exception {
         URL url = getClass().getResource("../xml/unwrapped-stockquote.wsdl");
         WSDLDefinition definition = registry.read(null, new URI("unwrapped-stockquote.wsdl"), url);
+        wsdlResolver.addModel(definition);
+        definition = wsdlResolver.resolveModel(WSDLDefinition.class, definition);
         PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME);
         Operation operation = portType.getOperation("getLastTradePrice1", null, null);
         WSDLOperation op = new WSDLOperation(wsdlFactory, operation, definition.getInlinedSchemas(), "org.w3c.dom.Node", resolver);

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java Sat Jul 28 10:19:09 2007
@@ -21,14 +21,13 @@
 
 import java.net.URI;
 import java.net.URL;
-import java.util.HashMap;
 import java.util.List;
 
 import javax.wsdl.Import;
+import javax.xml.namespace.QName;
 
 import junit.framework.Assert;
 
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.junit.After;
@@ -60,42 +59,21 @@
     public void testWSDL() throws Exception {
         URL url = getClass().getResource("/wsdl/helloworld-service.wsdl");
         WSDLDefinition definition = processor.read(null, URI.create("wsdl/helloworld-service.wsdl"), url);
-        Assert.assertNotNull(definition);
+        Assert.assertNull(definition.getDefinition());
+        Assert.assertEquals("http://helloworld", definition.getNamespace());
         URL url1 = getClass().getResource("/wsdl/helloworld-interface.wsdl");
         WSDLDefinition definition1 = processor.read(null, URI.create("wsdl/helloworld-interface.wsdl"), url1);
-        ModelResolver resolver = new MockResolver();
+        Assert.assertNull(definition1.getDefinition());
+        Assert.assertEquals("http://helloworld", definition1.getNamespace());
+        WSDLModelResolver resolver = new WSDLModelResolver(null);
         resolver.addModel(definition);
         resolver.addModel(definition1);
-        processor.resolve(definition, resolver);
+        WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, definition);
         List imports = (List)definition.getDefinition().getImports().get("http://helloworld");
         Assert.assertNotNull(imports);
         Assert.assertNotNull(((Import)imports.get(0)).getDefinition());
-    }
-
-    private static class MockResolver extends HashMap implements ModelResolver {
-
-        /**
-         * @see org.apache.tuscany.sca.contribution.resolver.ModelResolver#addModel(java.lang.Object)
-         */
-        public void addModel(Object resolved) {
-            super.put(resolved, resolved);
-        }
-
-        /**
-         * @see org.apache.tuscany.sca.contribution.resolver.ModelResolver#removeModel(java.lang.Object)
-         */
-        public Object removeModel(Object resolved) {
-            return super.remove(resolved);
-        }
-
-        /**
-         * @see org.apache.tuscany.sca.contribution.resolver.ModelResolver#resolveModel(java.lang.Class,
-         *      java.lang.Object)
-         */
-        public <T> T resolveModel(Class<T> modelClass, T unresolved) {
-            return (T)super.get(unresolved);
-        }
-
+        Assert.assertNotNull(resolved.getDefinition().getPortType(new QName("http://helloworld", "HelloWorld")));
+        Assert.assertNotNull(resolved.getDefinition().getService(new QName("http://helloworld", "HelloWorldService")));
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java Sat Jul 28 10:19:09 2007
@@ -39,9 +39,10 @@
  */
 public class WSDLTestCase extends TestCase {
 
-    XMLInputFactory inputFactory;
-    DefaultURLArtifactProcessorExtensionPoint documentProcessors;
-    ExtensibleURLArtifactProcessor documentProcessor;
+    private XMLInputFactory inputFactory;
+    private DefaultURLArtifactProcessorExtensionPoint documentProcessors;
+    private ExtensibleURLArtifactProcessor documentProcessor;
+    private WSDLModelResolver wsdlResolver;
 
     public void setUp() throws Exception {
         inputFactory = XMLInputFactory.newInstance();
@@ -50,6 +51,7 @@
 
         WSDLDocumentProcessor wsdlProcessor = new WSDLDocumentProcessor(new DefaultWSDLFactory(), null);
         documentProcessors.addArtifactProcessor(wsdlProcessor);
+        wsdlResolver = new WSDLModelResolver(null);
     }
 
     public void tearDown() throws Exception {
@@ -61,41 +63,48 @@
         URL url = getClass().getResource("example.wsdl");
         WSDLDefinition definition = documentProcessor.read(null, new URI("example.wsdl"), url, WSDLDefinition.class);
         assertNotNull(definition);
-        assertNotNull(definition.getDefinition());
+        assertNull(definition.getDefinition());
         assertEquals(definition.getNamespace(), "http://www.example.org");
     }
-    
+
     public void testReadWSDLImports() throws Exception {
         QName aBinding = new QName("http://helloworld", "HelloWorldSoapBinding");
         QName aPortType = new QName("http://helloworld", "HelloWorld");
-        
+
         URL url = getClass().getResource("test1.wsdl");
         WSDLDefinition test1Defn = documentProcessor.read(null, new URI("test1.wsdl"), url, WSDLDefinition.class);
         assertNotNull(test1Defn);
+        wsdlResolver.addModel(test1Defn);
+        test1Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test1Defn);
         //binding is a part of test1.wsdl
         assertNotNull(test1Defn.getDefinition().getBinding(aBinding));
         //porttype is part of test2.wsdl
         assertNotNull(test1Defn.getDefinition().getPortType(aPortType));
     }
-    
+
     public void testReadSameNamespaceWSDLDocument() throws Exception {
         QName aBinding = new QName("http://helloworld", "HelloWorldSoapBinding");
         QName aPortType = new QName("http://helloworld", "HelloWorld");
-        
+
         URL url = getClass().getResource("test2.wsdl");
         WSDLDefinition test2Defn = documentProcessor.read(null, new URI("test2.wsdl"), url, WSDLDefinition.class);
         assertNotNull(test2Defn);
+        wsdlResolver.addModel(test2Defn);
+        test2Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test2Defn);
+
         //bindigs are a part of test1.wsdl so should not be found
         assertNull(test2Defn.getDefinition().getBinding(aBinding));
         assertNotNull(test2Defn.getDefinition().getPortType(aPortType));
-        
+
         url = getClass().getResource("test1.wsdl");
         WSDLDefinition test1Defn = documentProcessor.read(null, new URI("test1.wsdl"), url, WSDLDefinition.class);
         assertNotNull(test1Defn);
-        assertTrue(test1Defn == test2Defn);
-        //now test2Defn should have the binding as it must be merged with what was read in test1.wsdl
-        //since they belong to the same namespace
-        assertNotNull(test2Defn.getDefinition().getBinding(aBinding));
+        wsdlResolver.addModel(test1Defn);
+
+        test1Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test1Defn);
+
+        assertNotNull(test1Defn.getDefinition().getPortType(aPortType));
+        assertNotNull(test1Defn.getDefinition().getBinding(aBinding));
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java Sat Jul 28 10:19:09 2007
@@ -44,9 +44,9 @@
 
     @Test
     public void testReadTNS() throws Exception {
-        String tns = XMLDocumentHelper.readTargetNamespace(wsdl, XMLDocumentHelper.WSDL11, "targetNamespace");
+        String tns = XMLDocumentHelper.readTargetNamespace(wsdl, XMLDocumentHelper.WSDL11, true, "targetNamespace");
         Assert.assertEquals("http://helloworld", tns);
-        String tns2 = XMLDocumentHelper.readTargetNamespace(xsd, XMLDocumentHelper.XSD, null);
+        String tns2 = XMLDocumentHelper.readTargetNamespace(xsd, XMLDocumentHelper.XSD, true, null);
         Assert.assertEquals("http://greeting", tns2);
     }
 

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl Sat Jul 28 10:19:09 2007
@@ -21,10 +21,10 @@
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="helloworld">
 
+    <wsdl:import location="helloworld-interface.wsdl" namespace="http://helloworld"></wsdl:import>
     <!-- 
-    <wsdl:import location="/wsdl/helloworld-interface.wsdl" namespace="http://helloworld"></wsdl:import>
-     -->
     <wsdl:import namespace="http://helloworld"></wsdl:import>
+     -->
 
     <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld">
         <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java Sat Jul 28 10:19:09 2007
@@ -19,6 +19,9 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl;
 
+import java.net.URI;
+import java.util.List;
+
 import javax.wsdl.Definition;
 
 import org.apache.tuscany.sca.interfacedef.Base;
@@ -61,5 +64,12 @@
      * @param namespace the namespace of this WSDL definition
      */
     void setNamespace(String namespace);
-
+    
+    /**
+     * @return
+     */
+    List<XSDefinition> getXmlSchemas();
+    
+    URI getLocation();
+    void setLocation(URI url);
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java Sat Jul 28 10:19:09 2007
@@ -19,6 +19,8 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl;
 
+import java.net.URI;
+
 import org.apache.tuscany.sca.interfacedef.Base;
 import org.apache.ws.commons.schema.XmlSchema;
 
@@ -52,5 +54,7 @@
      * @param namespace the namespace of this XmlSchema definition
      */
     void setNamespace(String namespace);
-
+    
+    URI getLocation();
+    void setLocation(URI uri);
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java Sat Jul 28 10:19:09 2007
@@ -19,9 +19,14 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl.impl;
 
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.wsdl.Definition;
 
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 
 /**
@@ -33,7 +38,9 @@
     
     private Definition definition;
     private String namespace;
+    private URI location;
     private XmlSchemaCollection inlineSchemas = new XmlSchemaCollection();
+    private List<XSDefinition> schemas = new ArrayList<XSDefinition>();
     private boolean unresolved;
     
     protected WSDLDefinitionImpl() {
@@ -65,7 +72,7 @@
         } else if (definition != null) {
             return definition.getTargetNamespace();
         } else {
-            return null;
+            return namespace;
         }
     }
     
@@ -77,6 +84,7 @@
         }
     }
     
+    /*
     @Override
     public int hashCode() {
         return String.valueOf(getNamespace()).hashCode();
@@ -87,13 +95,73 @@
         if (obj == this) {
             return true;
         } else if (obj instanceof WSDLDefinition) {
+            WSDLDefinition def = (WSDLDefinition)obj;
             if (getNamespace() != null) {
-                return getNamespace().equals(((WSDLDefinition)obj).getNamespace());
+                return getNamespace().equals(def.getNamespace());
             } else {
-                return ((WSDLDefinition)obj).getNamespace() == null;
+                return def.getNamespace() == null;
             }
         } else {
             return false;
         }
+    }
+    */
+
+    /**
+     * @see org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition#getXmlSchemas()
+     */
+    public List<XSDefinition> getXmlSchemas() {
+        return schemas;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition#getLocation()
+     */
+    public URI getLocation() {
+        return location;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition#setLocation(java.net.URI)
+     */
+    public void setLocation(URI url) {
+        this.location = url;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getLocation() == null) ? 0 : getLocation().hashCode());
+        result = prime * result + ((getNamespace() == null) ? 0 : getNamespace().hashCode());
+        return result;
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (!(obj instanceof WSDLDefinitionImpl))
+            return false;
+        final WSDLDefinitionImpl other = (WSDLDefinitionImpl)obj;
+        if (getLocation() == null) {
+            if (other.getLocation() != null)
+                return false;
+        } else if (!getLocation().equals(other.getLocation()))
+            return false;
+        if (getNamespace() == null) {
+            if (other.getNamespace() != null)
+                return false;
+        } else if (!getNamespace().equals(other.getNamespace()))
+            return false;
+        return true;
     }
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java?view=diff&rev=560573&r1=560572&r2=560573
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java Sat Jul 28 10:19:09 2007
@@ -19,6 +19,8 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl.impl;
 
+import java.net.URI;
+
 import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
 import org.apache.ws.commons.schema.XmlSchema;
 
@@ -31,6 +33,7 @@
     
     private XmlSchema definition;
     private String namespace;
+    private URI location;
     private boolean unresolved;
     
     protected XSDefinitionImpl() {
@@ -88,5 +91,19 @@
         } else {
             return false;
         }
+    }
+
+    /**
+     * @return the location
+     */
+    public URI getLocation() {
+        return location;
+    }
+
+    /**
+     * @param location the location to set
+     */
+    public void setLocation(URI location) {
+        this.location = location;
     }
 }



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