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/30 22:43:23 UTC

svn commit: r561110 - in /incubator/tuscany/java/sca/modules: interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/ interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ interface-wsdl-xml/src/te...

Author: rfeng
Date: Mon Jul 30 13:43:22 2007
New Revision: 561110

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

Added:
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/modules/interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/WSDLInterfaceRuntimeModuleActivator.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/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDModelResolver.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/interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/WSDLInterfaceRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/WSDLInterfaceRuntimeModuleActivator.java?view=diff&rev=561110&r1=561109&r2=561110
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/WSDLInterfaceRuntimeModuleActivator.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/WSDLInterfaceRuntimeModuleActivator.java Mon Jul 30 13:43:22 2007
@@ -61,7 +61,7 @@
         // Register .wsdl document processor  and .xsd document processor
         URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
         documentProcessors.addArtifactProcessor(new WSDLDocumentProcessor(wsdlFactory, null));
-        //documentProcessors.addArtifactProcessor(new XSDDocumentProcessor(wsdlFactory));
+        documentProcessors.addArtifactProcessor(new XSDDocumentProcessor(wsdlFactory));
         
         ModelResolverExtensionPoint resolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
         resolvers.addResolver(WSDLDefinition.class, WSDLModelResolver.class);

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=561110&r1=561109&r2=561110
==============================================================================
--- 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 Mon Jul 30 13:43:22 2007
@@ -50,7 +50,6 @@
 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;
@@ -346,7 +345,7 @@
     private void readInlineSchemas(Definition definition, XmlSchemaCollection schemaCollection) {
         Types types = definition.getTypes();
         if (types != null) {
-            schemaCollection.setSchemaResolver(new URIResolverImpl());
+            schemaCollection.setSchemaResolver(new XSDModelResolver.URIResolverImpl(contribution));
             for (Object ext : types.getExtensibilityElements()) {
                 if (ext instanceof Schema) {
                     Element element = ((Schema)ext).getElement();

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=561110&r1=561109&r2=561110
==============================================================================
--- 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 Mon Jul 30 13:43:22 2007
@@ -31,7 +31,6 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.ws.commons.schema.resolver.URIResolver;
 import org.xml.sax.InputSource;
 
 /**
@@ -176,26 +175,6 @@
             return null;
         } finally {
             is.close();
-        }
-    }
-
-    /**
-     * URI resolver implementation for xml schema
-     */
-    public static class URIResolverImpl implements URIResolver {
-
-        public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace,
-                                                     java.lang.String schemaLocation,
-                                                     java.lang.String baseUri) {
-            try {
-                if (schemaLocation == null || schemaLocation.startsWith("/")) {
-                    return null;
-                }
-                URL url = new URL(new URL(baseUri), schemaLocation);
-                return getInputSource(url);
-            } catch (IOException e) {
-                return null;
-            }
         }
     }
 

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=561110&r1=561109&r2=561110
==============================================================================
--- 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 Mon Jul 30 13:43:22 2007
@@ -19,14 +19,10 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl.xml;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 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;
@@ -34,8 +30,6 @@
 import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
 
 /**
  * An ArtifactProcessor for XSD documents.
@@ -52,24 +46,8 @@
 
     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) {
+            return indexRead(artifactURL);
+        } catch (Exception e) {
             throw new ContributionReadException(e);
         }
     }
@@ -87,10 +65,12 @@
 
     public static final QName XSD = new QName("http://www.w3.org/2001/XMLSchema", "schema");
 
-    protected XSDefinition indexRead(URL doc) throws IOException, XMLStreamException {
+    protected XSDefinition indexRead(URL doc) throws Exception {
         XSDefinition xsd = factory.createXSDefinition();
-        xsd.setNamespace(XMLDocumentHelper.readTargetNamespace(doc, XSD, true, "targetNamespace"));
         xsd.setUnresolved(true);
+        xsd.setNamespace(XMLDocumentHelper.readTargetNamespace(doc, XSD, true, "targetNamespace"));
+        xsd.setLocation(doc.toURI());
+        xsd.setUnresolved(false);
         return xsd;
     }
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDModelResolver.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/XSDModelResolver.java?view=diff&rev=561110&r1=561109&r2=561110
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDModelResolver.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDModelResolver.java Mon Jul 30 13:43:22 2007
@@ -19,61 +19,187 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl.xml;
 
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 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.ContributionRuntimeException;
+import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaInclude;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.xml.sax.InputSource;
 
 /**
  * A Model Resolver for XSD models.
- *
+ * 
  * @version $Rev: 557916 $ $Date: 2007-07-20 01:04:40 -0700 (Fri, 20 Jul 2007) $
  */
 public class XSDModelResolver implements ModelResolver {
+    private WSDLFactory factory;
     private Contribution contribution;
-    private Map<String, XSDefinition> map = new HashMap<String, XSDefinition>();
-    
+    private Map<String, List<XSDefinition>> map = new HashMap<String, List<XSDefinition>>();
+    private XmlSchemaCollection schemaCollection;
+
     public XSDModelResolver(Contribution contribution) {
         this.contribution = contribution;
+        this.schemaCollection = new XmlSchemaCollection();
+        schemaCollection.setSchemaResolver(new URIResolverImpl(contribution));
+        this.factory = new DefaultWSDLFactory();
     }
 
     public void addModel(Object resolved) {
         XSDefinition definition = (XSDefinition)resolved;
-        map.put(definition.getNamespace(), definition);
+        List<XSDefinition> list = map.get(definition.getNamespace());
+        if (list == null) {
+            list = new ArrayList<XSDefinition>();
+            map.put(definition.getNamespace(), list);
+        }
+        list.add(definition);
     }
-    
+
     public Object removeModel(Object resolved) {
-        return map.remove(((XSDefinition)resolved).getNamespace());
+        XSDefinition definition = (XSDefinition)resolved;
+        List<XSDefinition> list = map.get(definition.getNamespace());
+        if (list == null) {
+            return null;
+        } else {
+            return list.remove(definition);
+        }
     }
-    
+
     public <T> T resolveModel(Class<T> modelClass, T unresolved) {
-        
+
         // Lookup a definition for the given namespace
         String namespace = ((XSDefinition)unresolved).getNamespace();
-        XSDefinition resolved = (XSDefinition) map.get(namespace);
-        if (resolved != null) {
-            return (T)resolved;
+        List<XSDefinition> list = map.get(namespace);
+        XSDefinition resolved;
+        try {
+            resolved = aggregate(list);
+        } catch (IOException e) {
+            throw new ContributionRuntimeException(e);
         }
-        
+        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(XSDefinition.class, (XSDefinition)unresolved);
+                    resolved =
+                        namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved);
                     if (!resolved.isUnresolved()) {
-                        return (T)resolved;
+                        return modelClass.cast(resolved);
                     }
                 }
             }
         }
-        return (T)unresolved;
+        return modelClass.cast(unresolved);
     }
-    
+
+    private void loadOnDemand(XSDefinition definition) throws IOException {
+        if (definition.getSchema() == null && definition.getLocation() != null) {
+            // Read an XSD document
+            InputSource xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+            XmlSchema schema = schemaCollection.read(xsd, null);
+            definition.setSchema(schema);
+        }
+    }
+
+    /**
+     * Create a facade XmlSchema which includes all the defintions
+     * 
+     * @param definitions A list of the XmlSchema under the same target
+     *                namespace
+     * @return The aggregated XmlSchema
+     */
+    private XSDefinition aggregate(List<XSDefinition> definitions) throws IOException {
+        if (definitions == null || definitions.size() == 0) {
+            return null;
+        }
+        if (definitions.size() == 1) {
+            XSDefinition d = definitions.get(0);
+            loadOnDemand(d);
+            return d;
+        }
+        XSDefinition aggregated = factory.createXSDefinition();
+        for (XSDefinition d : definitions) {
+            loadOnDemand(d);
+        }
+        String ns = definitions.get(0).getNamespace();
+        XmlSchema facade = new XmlSchema(ns, schemaCollection);
+
+        for (XmlSchema d : schemaCollection.getXmlSchemas()) {
+            if (ns.equals(d.getTargetNamespace())) {
+                XmlSchemaInclude include = new XmlSchemaInclude();
+                include.setSchema(d);
+                include.setSourceURI(d.getSourceURI());
+                include.setSchemaLocation(d.getSourceURI());
+                facade.getIncludes().add(include);
+                facade.getItems().add(include);
+            }
+        }
+        aggregated.setUnresolved(true);
+        aggregated.setSchema(facade);
+        aggregated.setNamespace(ns);
+        aggregated.setUnresolved(false);
+        
+        // FIXME: [rfeng] This is hacky
+        definitions.clear();
+        definitions.add(aggregated);
+        return aggregated;
+    }
+
+    /**
+     * URI resolver implementation for xml schema
+     */
+    public static class URIResolverImpl implements URIResolver {
+        private Contribution contribution;
+        
+        public URIResolverImpl(Contribution contribution) {
+            this.contribution = contribution;
+        }
+
+        public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace,
+                                                     java.lang.String schemaLocation,
+                                                     java.lang.String baseUri) {
+            try {
+                if (schemaLocation == null || schemaLocation.startsWith("/")) {
+                    return null;
+                }
+                URL url = null;
+                if (schemaLocation.startsWith("/")) {
+                    // The URI is relative to the contribution
+                    String uri = schemaLocation.substring(1);
+                    for (DeployedArtifact a : contribution.getArtifacts()) {
+                        if (a.getURI().equals(uri)) {
+                            url = new URL(a.getLocation());
+                            break;
+                        }
+                    }
+                } else {
+                    url = new URL(new URL(baseUri), schemaLocation);
+                }
+                return XMLDocumentHelper.getInputSource(url);
+            } catch (IOException e) {
+                return null;
+            }
+        }
+    }
+
 }

Added: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.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/XSDDocumentProcessorTestCase.java?view=auto&rev=561110
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.java Mon Jul 30 13:43:22 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.interfacedef.wsdl.xml;
+
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
+import org.apache.ws.commons.schema.XmlSchemaInclude;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XSDDocumentProcessorTestCase {
+    private XSDDocumentProcessor processor;
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {
+        processor = new XSDDocumentProcessor(new DefaultWSDLFactory());
+    }
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @Test
+    public void testXSD() throws Exception {
+        URL url = getClass().getResource("/xsd/greeting.xsd");
+        XSDefinition definition = processor.read(null, URI.create("xsd/greeting.xsd"), url);
+        Assert.assertNull(definition.getSchema());
+        Assert.assertEquals("http://greeting", definition.getNamespace());
+        URL url1 = getClass().getResource("/xsd/name.xsd");
+        XSDefinition definition1 = processor.read(null, URI.create("xsd/name.xsd"), url1);
+        Assert.assertNull(definition1.getSchema());
+        Assert.assertEquals("http://greeting", definition1.getNamespace());
+        XSDModelResolver resolver = new XSDModelResolver(null);
+        resolver.addModel(definition);
+        XSDefinition resolved = resolver.resolveModel(XSDefinition.class, definition);
+        XmlSchemaObjectCollection collection = resolved.getSchema().getIncludes();
+        Assert.assertTrue(collection.getCount() == 1);
+        XmlSchemaType type =
+            ((XmlSchemaInclude)collection.getItem(0)).getSchema().getTypeByName(new QName("http://greeting", "Name"));
+        Assert.assertNotNull(type);
+        resolver.addModel(definition1);
+        resolved = resolver.resolveModel(XSDefinition.class, definition);
+        collection = resolved.getSchema().getIncludes();
+        Assert.assertTrue(collection.getCount() == 2);
+        type =
+            ((XmlSchemaInclude)collection.getItem(1)).getSchema().getTypeByName(new QName("http://greeting", "Name"));
+        Assert.assertNotNull(type);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=561110&r1=561109&r2=561110
==============================================================================
--- 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 Mon Jul 30 13:43:22 2007
@@ -61,7 +61,7 @@
         } else if (definition != null) {
             return definition.getTargetNamespace();
         } else {
-            return null;
+            return namespace;
         }
     }
     
@@ -73,24 +73,41 @@
         }
     }
     
+    /**
+     * @see java.lang.Object#hashCode()
+     */
     @Override
     public int hashCode() {
-        return String.valueOf(getNamespace()).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 (obj == this) {
+        if (this == obj)
             return true;
-        } else if (obj instanceof XSDefinition) {
-            if (getNamespace() != null) {
-                return getNamespace().equals(((XSDefinition)obj).getNamespace());
-            } else {
-                return ((XSDefinition)obj).getNamespace() == null;
-            }
-        } else {
+        if (obj == null)
             return false;
-        }
+        if (!(obj instanceof XSDefinitionImpl))
+            return false;
+        final XSDefinitionImpl other = (XSDefinitionImpl)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;
     }
 
     /**



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