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 aj...@apache.org on 2006/07/06 17:24:07 UTC
svn commit: r419580 - in /webservices/commons/trunk/modules/XmlSchema:
src/org/apache/ws/commons/schema/SchemaBuilder.java
test-resources/twoSchemas-ref.wsdl test/tests/TwoSchemasRefTest.java
Author: ajith
Date: Thu Jul 6 08:24:07 2006
New Revision: 419580
URL: http://svn.apache.org/viewvc?rev=419580&view=rev
Log:
1. Fixed an erroneous namespace resolving logic in SchemaBuilder.java where the external in scope namespace map was ignored
2 . Added a new test case and the relevant test resource
Added:
webservices/commons/trunk/modules/XmlSchema/test-resources/twoSchemas-ref.wsdl
webservices/commons/trunk/modules/XmlSchema/test/tests/TwoSchemasRefTest.java
Modified:
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java
Modified: webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java?rev=419580&r1=419579&r2=419580&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java Thu Jul 6 08:24:07 2006
@@ -60,9 +60,9 @@
if (uri != null)
collection.systemId2Schemas.put(uri, schema);
-
+
collection.schemas.add(schema);
-
+
// only populate it if it isn't already in there
if(!collection.namespaces.containsKey(schema.targetNamespace)){
collection.namespaces.put(schema.targetNamespace, schema);
@@ -195,11 +195,11 @@
notation.name = notationEl.getAttribute("name");
}
- if (notationEl.hasAttribute("public")) {
+ if (notationEl.hasAttribute("public")) {
notation.publicNotation = notationEl.getAttribute("public");
}
- if (notationEl.hasAttribute("system")) {
+ if (notationEl.hasAttribute("system")) {
notation.system = notationEl.getAttribute("system");
}
@@ -266,7 +266,7 @@
}
void setNamespaceAttributes(XmlSchema schema, Element schemaEl) {
- // If this schema is embedded in a WSDL, we need to get the
+ // If this schema is embedded in a WSDL, we need to get the
// namespaces from the all the parent nodes first.
Node parent = schemaEl.getParentNode();
if (parent instanceof Element) setNamespaceAttributes(schema, (Element) parent);
@@ -435,8 +435,9 @@
String namespace;
if (namespaceFromEl.length > 1) {
- Object result =
- schema.namespaces.get(namespaceFromEl[0]);
+ Object result = findNamespaceForPrefix(namespaceFromEl[0],
+ schema);
+
if (result == null)
throw new XmlSchemaException("No namespace "
+ "found in given itemType");
@@ -502,7 +503,7 @@
prefix = member.substring(0, pos);
localName = member.substring(pos + 1);
}
- v.add(new QName((String) schema.namespaces.get(prefix),
+ v.add(new QName((String) findNamespaceForPrefix(prefix,schema),
localName));
}
union.memberTypesQNames = new QName[v.size()];
@@ -747,7 +748,9 @@
if (restrictionEl.hasAttribute("base")) {
String name = restrictionEl.getAttribute("base");
- Object result = schema.namespaces.get(Tokenizer.tokenize(name, ":")[0]);
+
+ Object result =findNamespaceForPrefix(Tokenizer.tokenize(name, ":")[0],
+ schema);
if (result == null)
throw new XmlSchemaException("No namespace found in "
@@ -1300,7 +1303,7 @@
String namespace;
if (type.length > 1) {
- Object result = schema.namespaces.get(type[0]);
+ Object result = findNamespaceForPrefix(type[0],schema);
if (result == null)
throw new XmlSchemaException("No namespace found"
+ " in given attribute type for " + type[0]);
@@ -1343,7 +1346,8 @@
if (namespaceFromEl.length > 1) {
Object result =
- schema.namespaces.get(namespaceFromEl[0]);
+ findNamespaceForPrefix(namespaceFromEl[0],schema);
+
if (result == null && namespaceFromEl[0].equals(Constants.XMLNS_PREFIX)) {
result = Constants.XMLNS_URI;
}
@@ -1399,7 +1403,7 @@
// there is a possiblily of some namespace mapping
String prefix = value.substring(0, value.indexOf(":"));
//String value = ( String) value.substring( value.indexOf( ":" ) + 1);
- String namespace = (String) schema.namespaces.get(prefix);
+ String namespace = (String) findNamespaceForPrefix(prefix,schema);
if (namespace != null) {
Attr nsAttr = attrEl.getOwnerDocument().createAttribute("xmlns:" + prefix);
nsAttr.setValue(namespace);
@@ -1528,7 +1532,7 @@
String[] args = Tokenizer.tokenize(refName, ":");
String namespace;
if (args.length > 1) {
- Object result = schema.namespaces.get(args[0]);
+ Object result = findNamespaceForPrefix(args[0],schema);
if (result == null)
throw new XmlSchemaException("No namespace found in"
+ "given ref");
@@ -1558,16 +1562,16 @@
handleComplexType(schema, complexTypeEl, schemaEl);
element.schemaType = complexType;
- }
-
+ }
+
if ((keyEl =
XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "key")) != null) {
XmlSchemaIdentityConstraint key =
handleConstraint(schema, keyEl, schemaEl, "Key");
element.constraints.add(key);
- }
-
+ }
+
if ((keyrefEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "keyref")) != null) {
XmlSchemaKeyref keyRef =
@@ -1581,7 +1585,7 @@
String namespace;
if (qName.length > 1) {
- Object result = schema.namespaces.get(qName[0]);
+ Object result = findNamespaceForPrefix(qName[0],schema);
namespace = result.toString();
} else
namespace = schema.targetNamespace;
@@ -1591,8 +1595,8 @@
element.constraints.add(keyRef);
- }
-
+ }
+
if ((uniqueEl =
XDOMUtil.getFirstChildElementNS(el,
XmlSchema.SCHEMA_NS, "unique")) != null) {
@@ -1625,13 +1629,13 @@
if (el.hasAttribute("nillable"))
element.isNillable =
new Boolean(el.getAttribute("nillable")).booleanValue();
-
+
if (el.hasAttribute("substitutionGroup")) {
String substitutionGroup = el.getAttribute("substitutionGroup");
String[] args = Tokenizer.tokenize(substitutionGroup, ":");
String namespace = null;
if (args.length > 1) {
- Object result = schema.namespaces.get(args[0]);
+ Object result = findNamespaceForPrefix(args[0],schema);
if (result == null) {
throw new XmlSchemaException("No namespace found in"
+ "given substitionGroup");
@@ -1679,7 +1683,8 @@
if (namespaceFromEl.length > 1) {
Object result =
- schema.namespaces.get(namespaceFromEl[0]);
+ findNamespaceForPrefix(namespaceFromEl[0],
+ schema);
if (result == null)
throw new XmlSchemaException("No namespace found in "
+ "given base simple content type");
@@ -2006,5 +2011,22 @@
collection.baseUri);
}
+
+ /**
+ * Finds the namespace URI for a given prefix
+ * @param prefix
+ * @param schema
+ * @return
+ */
+ private String findNamespaceForPrefix(String prefix,XmlSchema schema){
+ String returnPrefix = (String)schema.namespaces.get(prefix);
+ if (returnPrefix==null){
+ returnPrefix = (String)collection.inScopeNamespaces.get(prefix);
+ }
+
+ return returnPrefix;
+ }
+
+
}
Added: webservices/commons/trunk/modules/XmlSchema/test-resources/twoSchemas-ref.wsdl
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/twoSchemas-ref.wsdl?rev=419580&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/twoSchemas-ref.wsdl (added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/twoSchemas-ref.wsdl Thu Jul 6 08:24:07 2006
@@ -0,0 +1,23 @@
+<?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:sequence>
+ <xsd:element ref="ns1:elem3" minOccurs="1" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <xsd:schema targetNamespace="http://ns1.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+ <xsd:element name="elem3" type="xsd:string"/>
+ </xsd:schema>
+ </wsdl:types>
+</wsdl:definitions>
\ No newline at end of file
Added: webservices/commons/trunk/modules/XmlSchema/test/tests/TwoSchemasRefTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/TwoSchemasRefTest.java?rev=419580&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/TwoSchemasRefTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/TwoSchemasRefTest.java Thu Jul 6 08:24:07 2006
@@ -0,0 +1,54 @@
+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.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.Iterator;
+/*
+ * 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 TwoSchemasRefTest extends TestCase {
+
+ public void testTwoSchemas() throws Exception{
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse("test-resources/twoSchemas-ref.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);
+ }
+ }
+
+ XmlSchemaElement elementByQName = schemaCol.getElementByQName(new QName("http://tns.demo.org", "elem1"));
+ assertNotNull(elementByQName);
+
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org