You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by di...@apache.org on 2006/01/31 21:57:10 UTC

svn commit: r373909 - in /webservices/commons/trunk/XmlSchema: src/org/apache/ws/commons/schema/SchemaBuilder.java test-resources/twoSchemas.wsdl test/tests/TwoSchemasTest.java

Author: dims
Date: Tue Jan 31 12:57:06 2006
New Revision: 373909

URL: http://svn.apache.org/viewcvs?rev=373909&view=rev
Log:
fix for AXIS2-419 - org.apache.ws.commons.schema.SchemaBuilder Method setNamespaceAttributes() overwrites Schemata already parsed

Added:
    webservices/commons/trunk/XmlSchema/test-resources/twoSchemas.wsdl
    webservices/commons/trunk/XmlSchema/test/tests/TwoSchemasTest.java
Modified:
    webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java

Modified: webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java?rev=373909&r1=373908&r2=373909&view=diff
==============================================================================
--- webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java Tue Jan 31 12:57:06 2006
@@ -249,8 +249,10 @@
         } else {
             putNamespace("", schema.targetNamespace);
         }
-
-        collection.namespaces.put(schema.targetNamespace, schema);
+        // only populate it if it isn't already in there
+        if(!collection.namespaces.containsKey(schema.targetNamespace)){
+        	collection.namespaces.put(schema.targetNamespace, schema);
+        }
     }
 
     private void putNamespace(String prefix, String namespace) {

Added: webservices/commons/trunk/XmlSchema/test-resources/twoSchemas.wsdl
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/XmlSchema/test-resources/twoSchemas.wsdl?rev=373909&view=auto
==============================================================================
--- webservices/commons/trunk/XmlSchema/test-resources/twoSchemas.wsdl (added)
+++ webservices/commons/trunk/XmlSchema/test-resources/twoSchemas.wsdl Tue Jan 31 12:57:06 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions 
+	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
+	xmlns:ns1="http://ns1.demo.org" 
+	xmlns:tns="http://tns.demo.org" 
+	xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
+	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
+	targetNamespace="http://tns.demo.org">
+  <wsdl:types>
+    <xsd:schema targetNamespace="http://tns.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+      <xsd:element name="elem1">
+        <xsd:complexType>
+            <xsd:element name="elem2" type="ns1:elem3" minOccurs="1" maxOccurs="1"/>
+        </xsd:complexType>
+      </xsd:element>
+    </xsd:schema>
+    <xsd:schema targetNamespace="http://ns1.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+      <xsd:complexType name="elem3">
+        <xsd:sequence>
+          <xsd:element name="elem4" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
+        </xsd:sequence>
+      </xsd:complexType>
+    </xsd:schema>
+  </wsdl:types>
+</wsdl:definitions>
\ No newline at end of file

Added: webservices/commons/trunk/XmlSchema/test/tests/TwoSchemasTest.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/XmlSchema/test/tests/TwoSchemasTest.java?rev=373909&view=auto
==============================================================================
--- webservices/commons/trunk/XmlSchema/test/tests/TwoSchemasTest.java (added)
+++ webservices/commons/trunk/XmlSchema/test/tests/TwoSchemasTest.java Tue Jan 31 12:57:06 2006
@@ -0,0 +1,49 @@
+package tests;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+public class TwoSchemasTest extends TestCase {
+
+    public void testTwoSchemas() throws Exception{
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        Document doc = documentBuilderFactory.newDocumentBuilder().
+                parse("test-resources/twoSchemas.wsdl");
+
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+		NodeList schemaNodes = doc.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","schema");
+        for (int j = 0; j < schemaNodes.getLength(); j++) {
+        	Node schemaNode = schemaNodes.item(j);
+        	if("schema".equals(schemaNode.getLocalName())){
+        		schemaCol.read((Element)schemaNode);
+        	}
+        }
+        
+        assertNotNull(schemaCol.getElementByQName(new QName("http://tns.demo.org","elem1")));
+
+    }
+}