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/09/05 18:25:39 UTC
svn commit: r440386 - in /webservices/commons/trunk/modules/XmlSchema/src:
main/java/org/apache/ws/commons/schema/ test/java/tests/
Author: dims
Date: Tue Sep 5 09:25:37 2006
New Revision: 440386
URL: http://svn.apache.org/viewvc?view=rev&rev=440386
Log:
Fix for WSCOMMONS-78 - Including a schema without namespace into a schema with namespace is not possible
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/CircularSchemaTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java Tue Sep 5 09:25:37 2006
@@ -22,12 +22,15 @@
import java.util.StringTokenizer;
import java.util.Vector;
+import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.ws.commons.schema.XmlSchemaCollection.SchemaKey;
import org.apache.ws.commons.schema.constants.Constants;
import org.apache.ws.commons.schema.utils.NodeNamespaceContext;
+import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
import org.apache.ws.commons.schema.utils.XDOMUtil;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -41,16 +44,16 @@
Document doc;
XmlSchema schema;
XmlSchemaCollection collection;
-
+ private final TargetNamespaceValidator validator;
DocumentBuilderFactory docFac;
- public static final String XMLNS_PREFIX = "xmlns";
/**
* Schema builder constructor
* @param collection
*/
- SchemaBuilder(XmlSchemaCollection collection) {
+ SchemaBuilder(XmlSchemaCollection collection, TargetNamespaceValidator validator) {
this.collection = collection;
+ this.validator = validator;
schema = new XmlSchema(collection);
}
@@ -75,14 +78,9 @@
schema.setNamespaceContext(new NodeNamespaceContext(schemaEl));
setNamespaceAttributes(schema, schemaEl);
- 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);
+ XmlSchemaCollection.SchemaKey schemaKey = new XmlSchemaCollection.SchemaKey(schema.logicalTargetNamespace, uri);
+ if (!collection.containsSchema(schemaKey)) {
+ collection.addSchema(schemaKey, schema);
}
schema.setElementFormDefault(this.getFormDefault(schemaEl,
@@ -230,9 +228,9 @@
XmlSchemaRedefine redefine = new XmlSchemaRedefine();
redefine.schemaLocation =
redefineEl.getAttribute("schemaLocation");
- //redefine has no such thing called a namespace!
+ final TargetNamespaceValidator validator = newIncludeValidator(schema);
redefine.schema =
- resolveXmlSchema(null,redefine.schemaLocation);
+ resolveXmlSchema(schema.logicalTargetNamespace, redefine.schemaLocation, validator);
for (Element el = XDOMUtil.getFirstChildElementNS(redefineEl,
XmlSchema.SCHEMA_NS)
@@ -278,12 +276,13 @@
//no targetnamespace found !
if (schemaEl.getAttributeNode("targetNamespace") != null) {
String contain = schemaEl.getAttribute("targetNamespace");
-
- if (!contain.equals(""))
- schema.targetNamespace = contain;
+ schema.setTargetNamespace(contain);
} else {
//do nothing here
}
+ if (validator != null) {
+ validator.validate(schema);
+ }
}
/**
@@ -504,7 +503,7 @@
if (offset == -1) {
uri = pContext.getNamespaceURI(Constants.DEFAULT_NS_PREFIX);
if (Constants.NULL_NS_URI.equals(uri)) {
- return new QName(schema.targetNamespace, pName);
+ return new QName(schema.logicalTargetNamespace, pName);
}
localName = pName;
prefix = Constants.DEFAULT_NS_PREFIX;
@@ -1202,6 +1201,14 @@
return group;
}
+ private QName newLocalQName(String pLocalName) {
+ String uri = schema.logicalTargetNamespace;
+ if (uri == null) {
+ uri = XMLConstants.NULL_NS_URI;
+ }
+ return new QName(uri, pLocalName);
+ }
+
private XmlSchemaAttribute handleAttribute(XmlSchema schema,
Element attrEl, Element schemaEl) {
//todo: need to implement different rule of attribute such as
@@ -1215,7 +1222,7 @@
// "" :schema.targetNamespace;
attr.name = name;
- attr.qualifiedName = new QName(schema.targetNamespace, name);
+ attr.qualifiedName = newLocalQName(name);
}
if (attrEl.hasAttribute("type")) {
@@ -1361,11 +1368,9 @@
isQualified = formDef.equals(XmlSchemaForm.QUALIFIED);
}
- String ns = (isQualified || isGlobal) ? schema.targetNamespace :
- null;
-
- if(element.name != null) {
- element.qualifiedName = new QName(ns, element.name);
+ if (element.name != null) {
+ final String name = element.name;
+ element.qualifiedName = (isQualified || isGlobal) ? newLocalQName(name) : new QName(XMLConstants.NULL_NS_URI, name);
}
Element annotationEl =
@@ -1566,22 +1571,42 @@
schemaImport.setAnnotation(importAnnotation);
}
- schemaImport.namespace = importEl.getAttribute("namespace");
+ final String uri = schemaImport.namespace = importEl.getAttribute("namespace");
schemaImport.schemaLocation =
importEl.getAttribute("schemaLocation");
+ TargetNamespaceValidator validator = new TargetNamespaceValidator(){
+ private boolean isEmpty(String pValue) {
+ return pValue == null || XMLConstants.NULL_NS_URI.equals(pValue);
+ }
+ public void validate(XmlSchema pSchema) {
+ final boolean valid;
+ if (isEmpty(uri)) {
+ valid = isEmpty(pSchema.syntacticalTargetNamespace);
+ } else {
+ valid = pSchema.syntacticalTargetNamespace.equals(uri);
+ }
+ if (!valid) {
+ throw new XmlSchemaException("An imported schema was announced to have the namespace "
+ + uri + ", but has the namespace " +
+ pSchema.syntacticalTargetNamespace);
+ }
+ }
+ };
if ((schemaImport.schemaLocation != null) && (!schemaImport.schemaLocation.equals(""))) {
if(schema.getSourceURI()!=null) {
schemaImport.schema =
resolveXmlSchema(
- schemaImport.namespace,
+ uri,
schemaImport.schemaLocation,
- schema.getSourceURI());
+ schema.getSourceURI(),
+ validator);
} else {
schemaImport.schema =
resolveXmlSchema(
schemaImport.namespace,
- schemaImport.schemaLocation);
+ schemaImport.schemaLocation,
+ validator);
}
}
return schemaImport;
@@ -1593,7 +1618,7 @@
* @param includeEl
* @param schemaEl
*/
- XmlSchemaInclude handleInclude(XmlSchema schema,
+ XmlSchemaInclude handleInclude(final XmlSchema schema,
Element includeEl, Element schemaEl) {
XmlSchemaInclude include = new XmlSchemaInclude();
@@ -1615,23 +1640,48 @@
// we should be passing in a null in place of the target
//namespace
+ final TargetNamespaceValidator validator = newIncludeValidator(schema);
if(schema.getSourceURI()!=null) {
include.schema =
resolveXmlSchema(
- null,
+ schema.logicalTargetNamespace,
include.schemaLocation,
- schema.getSourceURI());
+ schema.getSourceURI(),
+ validator);
} else {
include.schema =
resolveXmlSchema(
- null,
- include.schemaLocation);
+ schema.logicalTargetNamespace,
+ include.schemaLocation,
+ validator);
}
//process extra attributes and elements
processExtensibilityComponents(include,schemaEl);
return include;
}
+ private TargetNamespaceValidator newIncludeValidator(final XmlSchema schema) {
+ return new TargetNamespaceValidator(){
+ private boolean isEmpty(String pValue) {
+ return pValue == null || XMLConstants.NULL_NS_URI.equals(pValue);
+ }
+ public void validate(XmlSchema pSchema) {
+ if (isEmpty(pSchema.syntacticalTargetNamespace)) {
+ pSchema.logicalTargetNamespace = schema.logicalTargetNamespace;
+ } else {
+ if (!pSchema.syntacticalTargetNamespace.equals(schema.logicalTargetNamespace)) {
+ String msg = "An included schema was announced to have the default target namespace";
+ if (!isEmpty(schema.logicalTargetNamespace)) {
+ msg += " or the target namespace " + schema.logicalTargetNamespace;
+ }
+ throw new XmlSchemaException(msg + ", but has the target namespace "
+ + pSchema.logicalTargetNamespace);
+ }
+ }
+ }
+ };
+ }
+
/**
* Handles the annotation
* Traversing if encounter appinfo or documentation
@@ -1793,36 +1843,35 @@
*/
XmlSchema resolveXmlSchema(String targetNamespace,
String schemaLocation,
- String baseUri) {
+ String baseUri,
+ TargetNamespaceValidator validator) {
//use the entity resolver provided
- XmlSchema schema = null;
InputSource source = collection.schemaResolver.
resolveEntity(targetNamespace,schemaLocation,baseUri);
- if (source.getSystemId() != null) {
- schema = collection.getXmlSchema(source.getSystemId());
+ final String systemId = source.getSystemId() == null ? schemaLocation : source.getSystemId();
+ final SchemaKey key = new XmlSchemaCollection.SchemaKey(targetNamespace, systemId);
+ XmlSchema schema = collection.getSchema(key);
+ if (schema != null) {
+ return schema;
}
-
- if (schema == null) {
try {
- return collection.read(source, null);
+ return collection.read(source, null, validator);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- return schema;
- }
-
/**
* Resolve the schemas
* @param targetNamespace
* @param schemaLocation
*/
XmlSchema resolveXmlSchema(String targetNamespace,
- String schemaLocation) {
- return resolveXmlSchema(targetNamespace,schemaLocation,
- collection.baseUri);
+ String schemaLocation,
+ TargetNamespaceValidator validator) {
+ return resolveXmlSchema(targetNamespace, schemaLocation,
+ collection.baseUri, validator);
}
@@ -1846,7 +1895,7 @@
if (namespaceURI!= null &&
!"".equals(namespaceURI) && //ignore unqualified attributes
- !name.startsWith(XMLNS_PREFIX) && //ignore namespaces
+ !name.startsWith(XMLConstants.XMLNS_ATTRIBUTE) && //ignore namespaces
!Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI)){
attribMap.put(new QName(namespaceURI,name),
attribute.getValue());
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java Tue Sep 5 09:25:37 2006
@@ -21,7 +21,6 @@
import org.apache.ws.commons.schema.utils.NamespaceContextOwner;
import org.apache.ws.commons.schema.utils.NamespacePrefixList;
-import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
@@ -63,7 +62,7 @@
XmlSchemaDerivationMethod blockDefault, finalDefault;
XmlSchemaObjectCollection includes, items;
boolean isCompiled;
- String targetNamespace, version;
+ String syntacticalTargetNamespace, logicalTargetNamespace, version;
String schema_ns_prefix = "";
XmlSchemaCollection parent;
private NamespacePrefixList namespaceContext;
@@ -89,7 +88,7 @@
public XmlSchema(String namespace, XmlSchemaCollection parent) {
this(parent);
- targetNamespace = namespace;
+ syntacticalTargetNamespace = logicalTargetNamespace = namespace;
}
public XmlSchemaForm getAttributeFormDefault() {
@@ -169,12 +168,13 @@
}
public String getTargetNamespace() {
- return targetNamespace;
+ return syntacticalTargetNamespace;
}
public void setTargetNamespace(String targetNamespace) {
- if (!targetNamespace.equals(""))
- this.targetNamespace = targetNamespace;
+ if (!targetNamespace.equals("")) {
+ syntacticalTargetNamespace = logicalTargetNamespace = targetNamespace;
+ }
}
public String getVersion() {
@@ -227,7 +227,7 @@
QName qname = type.getQName();
if (schemaTypes.contains(qname)) {
throw new RuntimeException("Schema for namespace '" +
- targetNamespace + "' already contains type '" +
+ syntacticalTargetNamespace + "' already contains type '" +
qname.getLocalPart());
}
schemaTypes.add(qname, type);
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java Tue Sep 5 09:25:37 2006
@@ -16,31 +16,29 @@
package org.apache.ws.commons.schema;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
+import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.dom.DOMResult;
import org.apache.ws.commons.schema.constants.Constants;
import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
@@ -51,10 +49,41 @@
*
*/
public final class XmlSchemaCollection {
+ static class SchemaKey {
+ private final String namespace;
+ private final String systemId;
+ SchemaKey(String pNamespace, String pSystemId) {
+ namespace = pNamespace == null ? XMLConstants.NULL_NS_URI : pNamespace;
+ systemId = pSystemId == null ? "" : pSystemId;
+ }
+ String getNamespace() { return namespace; }
+ String getSystemId() { return systemId; }
+ public int hashCode() {
+ final int PRIME = 31;
+ return (PRIME + namespace.hashCode()) * PRIME + systemId.hashCode();
+ }
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SchemaKey other = (SchemaKey) obj;
+ return namespace.equals(other.namespace) && systemId.equals(other.systemId);
+ }
+ public String toString() {
+ return XMLConstants.NULL_NS_URI.equals(namespace) ?
+ systemId : ("{" + namespace + "}" + systemId);
+ }
+ }
+
/**
- * Namespaces we know about. Each one has an equivalent XmlSchema.
+ * Map of included schemas.
*/
- Map namespaces = new HashMap();
+ private Map schemas = new HashMap();
+
+
/**
* base URI is used as the base for loading the
* imports
@@ -66,11 +95,6 @@
Map inScopeNamespaces = new HashMap();
/**
- * Schemas in this colelction sorted by system id.
- */
- Map systemId2Schemas = new HashMap();
-
- /**
* An org.xml.sax.EntityResolver that is used to
* resolve the imports/includes
*/
@@ -79,11 +103,6 @@
XmlSchema xsd = new XmlSchema(XmlSchema.SCHEMA_NS, this);
/**
- * A Set of all the scehmas in this collection.
- */
- Set schemas = new HashSet();
-
- /**
* Set the base URI. This is used when schemas need to be
* loaded from relative locations
* @param baseUri
@@ -208,7 +227,25 @@
addSimpleType(xsd, Constants.XSD_LANGUAGE.getLocalPart());
addSimpleType(xsd, Constants.XSD_TOKEN.getLocalPart());
- namespaces.put(XmlSchema.SCHEMA_NS, xsd);
+ SchemaKey key = new SchemaKey(XmlSchema.SCHEMA_NS, null);
+ addSchema(key, xsd);
+ }
+
+ boolean containsSchema(SchemaKey pKey) {
+ return schemas.containsKey(pKey);
+ }
+
+ XmlSchema getSchema(SchemaKey pKey) {
+ return (XmlSchema) schemas.get(pKey);
+ }
+
+ void addSchema(SchemaKey pKey, XmlSchema pSchema) {
+ if (schemas.containsKey(pKey)) {
+ throw new IllegalStateException("A schema with target namespace "
+ + pKey.getNamespace() + " and system ID " + pKey.getSystemId()
+ + " is already present.");
+ }
+ schemas.put(pKey, pSchema);
}
private void addSimpleType(XmlSchema schema,String typeName){
@@ -221,13 +258,14 @@
return read(new InputSource(r), veh);
}
- public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) {
+ XmlSchema read(InputSource inputSource, ValidationEventHandler veh,
+ TargetNamespaceValidator namespaceValidator) {
try {
DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
docFac.setNamespaceAware(true);
DocumentBuilder builder = docFac.newDocumentBuilder();
Document doc = builder.parse(inputSource);
- return read(doc, inputSource.getSystemId(), veh);
+ return read(doc, inputSource.getSystemId(), veh, namespaceValidator);
} catch (ParserConfigurationException e) {
throw new XmlSchemaException(e.getMessage());
} catch (IOException e) {
@@ -237,39 +275,43 @@
}
}
+ public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) {
+ return read(inputSource, veh, null);
+ }
+
public XmlSchema read(Source source, ValidationEventHandler veh) {
try {
TransformerFactory trFac = TransformerFactory.newInstance();
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- StreamResult result = new StreamResult(out);
- javax.xml.transform.Transformer tr = trFac.newTransformer();
- tr.setOutputProperty(OutputKeys.METHOD, "xml");
- tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- tr.transform(source, result);
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- return read(new InputSource(in), veh);
+ DOMResult result = new DOMResult();
+ trFac.newTransformer().transform(source, result);
+ return read((Document) result.getNode(), veh);
} catch (TransformerException e) {
- throw new XmlSchemaException(e.getMessage());
+ throw new XmlSchemaException(e.getMessage(), e);
}
}
public XmlSchema read(Document doc, ValidationEventHandler veh) {
- SchemaBuilder builder = new SchemaBuilder(this);
+ SchemaBuilder builder = new SchemaBuilder(this, null);
return builder.build(doc, null, veh);
}
public XmlSchema read(Element elem) {
- SchemaBuilder builder = new SchemaBuilder(this);
+ SchemaBuilder builder = new SchemaBuilder(this, null);
return builder.handleXmlSchemaElement(elem, null);
}
public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) {
- SchemaBuilder builder = new SchemaBuilder(this);
+ return read(doc, uri, veh, null);
+ }
+
+ public XmlSchema read(Document doc, String uri, ValidationEventHandler veh,
+ TargetNamespaceValidator validator) {
+ SchemaBuilder builder = new SchemaBuilder(this, validator);
return builder.build(doc, uri, veh);
}
public XmlSchema read(Element elem, String uri) {
- SchemaBuilder builder = new SchemaBuilder(this);
+ SchemaBuilder builder = new SchemaBuilder(this, null);
return builder.handleXmlSchemaElement(elem, uri);
}
@@ -281,34 +323,62 @@
}
/**
- * Retreive an XmlSchema from the collection by its system ID.
+ * Retrieve a set of XmlSchema instances with the given its system ID.
+ * In general, this will return a single instance, or none. However,
+ * if the schema has no targetNamespace attribute and was included
+ * from schemata with different target namespaces, then it may
+ * occur, that multiple schema instances with different logical
+ * target namespaces may be returned.
* @param systemId
*/
- public XmlSchema getXmlSchema(String systemId) {
- return (XmlSchema) systemId2Schemas.get(systemId);
+ public XmlSchema[] getXmlSchema(String systemId) {
+ if (systemId == null) {
+ systemId = "";
+ }
+ final List result = new ArrayList();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getSystemId().equals(systemId)) {
+ result.add(entry.getValue());
+ }
+ }
+ return (XmlSchema[]) result.toArray(new XmlSchema[result.size()]);
}
/**
- * Return a Set of all the XmlSchemas in this collection.
+ * Returns an array of all the XmlSchemas in this collection.
*/
- public Set getXmlSchemas() {
- return Collections.unmodifiableSet(schemas);
+ public XmlSchema[] getXmlSchemas() {
+ Collection c = schemas.values();
+ return (XmlSchema[]) c.toArray(new XmlSchema[c.size()]);
}
public XmlSchemaElement getElementByQName(QName qname) {
- XmlSchema schema = (XmlSchema)namespaces.get(qname.getNamespaceURI());
- if (schema == null) {
- return null;
+ String uri = qname.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaElement element = ((XmlSchema) entry.getValue()).getElementByName(qname);
+ if (element != null) {
+ return element;
+ }
}
- return schema.getElementByName(qname);
+ }
+ return null;
}
public XmlSchemaType getTypeByQName(QName schemaTypeName) {
- XmlSchema schema = (XmlSchema)namespaces.get(schemaTypeName.getNamespaceURI());
- if (schema == null) {
- return null;
+ String uri = schemaTypeName.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaType type = ((XmlSchema) entry.getValue()).getTypeByName(schemaTypeName);
+ if (type != null) {
+ return type;
+ }
+ }
}
- return schema.getTypeByName(schemaTypeName);
+ return null;
}
Map unresolvedTypes = new HashMap();
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java Tue Sep 5 09:25:37 2006
@@ -1,52 +1,56 @@
-/*
- * 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.
- */
-
-package org.apache.ws.commons.schema;
-
-
-/**
- * Returns detailed information about the schema exception.
- */
-
-public class XmlSchemaException extends RuntimeException {
-
- /**
- * Creates new XmlSchemaException
- */
- public XmlSchemaException() {
- }
-
- public XmlSchemaException(String message) {
- super(message);
- }
-
- // TODO :implement
- public int getLineNumer() {
- return 1;
- }
-
- public int getLinePosition() {
- return 1;
- }
-
- public XmlSchemaObject getSourceSchemaObject() {
- return null;
- }
-
- public String getSourceUri() {
- return null;
- }
-}
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+
+/**
+ * Returns detailed information about the schema exception.
+ */
+
+public class XmlSchemaException extends RuntimeException {
+
+ /**
+ * Creates new XmlSchemaException
+ */
+ public XmlSchemaException() {
+ }
+
+ public XmlSchemaException(String message) {
+ super(message);
+ }
+
+ public XmlSchemaException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ // TODO :implement
+ public int getLineNumer() {
+ return 1;
+ }
+
+ public int getLinePosition() {
+ return 1;
+ }
+
+ public XmlSchemaObject getSourceSchemaObject() {
+ return null;
+ }
+
+ public String getSourceUri() {
+ return null;
+ }
+}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Tue Sep 5 09:25:37 2006
@@ -93,18 +93,18 @@
serializedSchema = setupNamespaces(serializedSchemaDocs, schemaObj);
schemaElement = serializedSchema;
- if (schemaObj.targetNamespace != null) {
- serializedSchema.setAttribute("targetNamespace", schemaObj.targetNamespace);
+ if (schemaObj.syntacticalTargetNamespace != null) {
+ serializedSchema.setAttribute("targetNamespace", schemaObj.syntacticalTargetNamespace);
Object targetNS =
- schema_ns.get(schemaObj.targetNamespace);
+ schema_ns.get(schemaObj.syntacticalTargetNamespace);
//if the namespace is not entered then add
//the targetNamespace as its
if (targetNS == null) {
serializedSchema.setAttributeNS(XMLNS_NAMESPACE_URI,
- "xmlns", schemaObj.targetNamespace);
- schema_ns.put(schemaObj.targetNamespace, "");
+ "xmlns", schemaObj.syntacticalTargetNamespace);
+ schema_ns.put(schemaObj.syntacticalTargetNamespace, "");
}
}
@@ -753,7 +753,6 @@
XmlSchema schema) throws XmlSchemaSerializerException {
Element serializedFacet;
- String facetName = facetObj.getClass().getName();
if (facetObj instanceof XmlSchemaMinExclusiveFacet)
serializedFacet = constructFacet(facetObj, doc, schema,
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java Tue Sep 5 09:25:37 2006
@@ -1,94 +1,94 @@
-/*
- * 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.
- */
-
-package org.apache.ws.commons.schema;
-
-import org.apache.ws.commons.schema.constants.Constants;
-
-import javax.xml.namespace.QName;
-
-
-/**
- * The base class for all simple types and complex types.
- */
-
-public class XmlSchemaType extends XmlSchemaAnnotated {
-
- Object baseSchemaType;
- XmlSchemaDatatype dataType;
- XmlSchemaDerivationMethod deriveBy, finalDerivation, finalResolved;
- boolean isMixed;
-
- // name of the type
- String name;
-
- XmlSchema schema;
-
- /**
- * Creates new XmlSchemaType
- */
- public XmlSchemaType(XmlSchema schema) {
- this.schema = schema;
- finalDerivation = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
- }
-
- public Object getBaseSchemaType() {
- return baseSchemaType;
- }
-
- public XmlSchemaDatatype getDataType() {
- return dataType;
- }
-
- public XmlSchemaDerivationMethod getDeriveBy() {
- return deriveBy;
- }
-
- public XmlSchemaDerivationMethod getFinal() {
- return finalDerivation;
- }
-
- public void setFinal(XmlSchemaDerivationMethod finalDerivation) {
- this.finalDerivation = finalDerivation;
- }
-
- public XmlSchemaDerivationMethod getFinalResolved() {
- return finalResolved;
- }
-
- public boolean isMixed() {
- return isMixed;
- }
-
- public void setMixed(boolean isMixed) {
- this.isMixed = isMixed;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public QName getQName() {
- if(name == null) {
- return null;
- }
- return new QName(schema.targetNamespace, name);
- }
-}
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * The base class for all simple types and complex types.
+ */
+
+public class XmlSchemaType extends XmlSchemaAnnotated {
+
+ Object baseSchemaType;
+ XmlSchemaDatatype dataType;
+ XmlSchemaDerivationMethod deriveBy, finalDerivation, finalResolved;
+ boolean isMixed;
+
+ // name of the type
+ String name;
+
+ XmlSchema schema;
+
+ /**
+ * Creates new XmlSchemaType
+ */
+ public XmlSchemaType(XmlSchema schema) {
+ this.schema = schema;
+ finalDerivation = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ }
+
+ public Object getBaseSchemaType() {
+ return baseSchemaType;
+ }
+
+ public XmlSchemaDatatype getDataType() {
+ return dataType;
+ }
+
+ public XmlSchemaDerivationMethod getDeriveBy() {
+ return deriveBy;
+ }
+
+ public XmlSchemaDerivationMethod getFinal() {
+ return finalDerivation;
+ }
+
+ public void setFinal(XmlSchemaDerivationMethod finalDerivation) {
+ this.finalDerivation = finalDerivation;
+ }
+
+ public XmlSchemaDerivationMethod getFinalResolved() {
+ return finalResolved;
+ }
+
+ public boolean isMixed() {
+ return isMixed;
+ }
+
+ public void setMixed(boolean isMixed) {
+ this.isMixed = isMixed;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public QName getQName() {
+ if(name == null) {
+ return null;
+ }
+ return new QName(schema.logicalTargetNamespace, name);
+ }
+}
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/CircularSchemaTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/CircularSchemaTest.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/CircularSchemaTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/CircularSchemaTest.java Tue Sep 5 09:25:37 2006
@@ -1,27 +1,26 @@
-package tests;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.xml.sax.InputSource;
-
-public class CircularSchemaTest extends TestCase
-{
- public void testCircular() throws Exception {
- XmlSchemaCollection schemas = new XmlSchemaCollection();
- File file = new File(Resources.asURI("circular/a.xsd"));
- InputSource source = new InputSource(new FileInputStream(file));
- source.setSystemId(file.toURL().toString());
-
- XmlSchema schema = schemas.read(source, null);
-
- Set xmlSchemas = schemas.getXmlSchemas();
- assertNotNull(xmlSchemas);
- assertEquals(2, xmlSchemas.size());
- }
+package tests;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.xml.sax.InputSource;
+
+public class CircularSchemaTest extends TestCase
+{
+ public void testCircular() throws Exception {
+ XmlSchemaCollection schemas = new XmlSchemaCollection();
+ File file = new File(Resources.asURI("circular/a.xsd"));
+ InputSource source = new InputSource(new FileInputStream(file));
+ source.setSystemId(file.toURL().toString());
+
+ schemas.read(source, null);
+
+ XmlSchema[] xmlSchemas = schemas.getXmlSchemas();
+ assertNotNull(xmlSchemas);
+ assertEquals(3, xmlSchemas.length);
+ }
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java?view=diff&rev=440386&r1=440385&r2=440386
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java Tue Sep 5 09:25:37 2006
@@ -3,7 +3,6 @@
import java.io.FileInputStream;
import java.io.InputStream;
-import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
@@ -121,7 +120,6 @@
}
-
/**
* Test importing a schema without namespace into a schema
* with namespace.
@@ -129,7 +127,9 @@
public void testImportSchemaWithoutNamespace() throws Exception {
InputStream is = new FileInputStream(Resources.asURI("includingWithNamespace.xsd"));
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
- XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+ schemaCol.read(new StreamSource(is), null);
+
+ assertNotNull(schemaCol.getTypeByQName(new QName("http://tns.demo.org", "XdwsGroupId")));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org