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 05:10:33 UTC
svn commit: r440228 [3/3] - in
/webservices/commons/trunk/modules/XmlSchema/src:
main/java/org/apache/ws/commons/schema/
main/java/org/apache/ws/commons/schema/utils/ test/java/tests/
test/test-resources/
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=440228&r1=440227&r2=440228
==============================================================================
--- 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 Mon Sep 4 20:10:32 2006
@@ -1,250 +1,247 @@
-/*
- * 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.w3c.dom.Document;
-import org.apache.ws.commons.schema.constants.Constants;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Hashtable;
-
-
-/**
- * Contains the definition of a schema. All XML Schema definition language (XSD)
- * elements are children of the schema element. Represents the World Wide Web
- * Consortium (W3C) schema element
- */
-
-// Oct 15th - momo - initial impl
-// Oct 17th - vidyanand - add SimpleType + element
-// Oct 18th - momo - add ComplexType
-// Oct 19th - vidyanand - handle external
-// Dec 6th - Vidyanand - changed RuntimeExceptions thrown to XmlSchemaExceptions
-// Jan 15th - Vidyanand - made changes to SchemaBuilder.handleElement to look for an element ref.
-// Feb 20th - Joni - Change the getXmlSchemaFromLocation schema
-// variable to name s.
-// Feb 21th - Joni - Port to XMLDomUtil and Tranformation.
-
-public class XmlSchema extends XmlSchemaAnnotated {
- static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
- XmlSchemaForm attributeFormDefault, elementFormDefault;
-
- XmlSchemaObjectTable attributeGroups,
- attributes, elements, groups,
- notations, schemaTypes;
- XmlSchemaDerivationMethod blockDefault, finalDefault;
- XmlSchemaObjectCollection includes, items;
- boolean isCompiled;
- String targetNamespace, version;
- Hashtable namespaces;
- String schema_ns_prefix = "";
- XmlSchemaCollection parent;
-
- /**
- * Creates new XmlSchema
- */
- public XmlSchema(XmlSchemaCollection parent) {
- this.parent = parent;
- attributeFormDefault = new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
- elementFormDefault = new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
- blockDefault = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
- finalDefault = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
- items = new XmlSchemaObjectCollection();
- includes = new XmlSchemaObjectCollection();
- namespaces = new Hashtable();
- elements = new XmlSchemaObjectTable();
- attributeGroups = new XmlSchemaObjectTable();
- attributes = new XmlSchemaObjectTable();
- groups = new XmlSchemaObjectTable();
- notations = new XmlSchemaObjectTable();
- schemaTypes = new XmlSchemaObjectTable();
- }
-
- public XmlSchema(String namespace, XmlSchemaCollection parent) {
- this(parent);
- targetNamespace = namespace;
- }
-
- protected String getNamespace(String prefix) {
- String ns = (String)namespaces.get(prefix);
- if (ns == null) {
- return parent.getNamespaceForPrefix(prefix);
- }
- return ns;
- }
-
- public XmlSchemaForm getAttributeFormDefault() {
- return attributeFormDefault;
- }
-
- public void setAttributeFormDefault(XmlSchemaForm value) {
- attributeFormDefault = value;
- }
-
- public XmlSchemaObjectTable getAttributeGroups() {
- return attributeGroups;
- }
-
- public XmlSchemaObjectTable getAttributes() {
- return attributes;
- }
-
- public XmlSchemaDerivationMethod getBlockDefault() {
- return blockDefault;
- }
-
- public void setBlockDefault(XmlSchemaDerivationMethod blockDefault) {
- this.blockDefault = blockDefault;
- }
-
- public XmlSchemaForm getElementFormDefault() {
- return elementFormDefault;
- }
-
- public void setElementFormDefault(XmlSchemaForm elementFormDefault) {
- this.elementFormDefault = elementFormDefault;
- }
-
- public XmlSchemaObjectTable getElements() {
- return elements;
- }
-
- public XmlSchemaElement getElementByName(QName name) {
- return (XmlSchemaElement)elements.getItem(name);
- }
-
- public XmlSchemaType getTypeByName(QName name) {
- return (XmlSchemaType)schemaTypes.getItem(name);
- }
-
- public XmlSchemaDerivationMethod getFinalDefault() {
- return finalDefault;
- }
-
- public void setFinalDefault(XmlSchemaDerivationMethod finalDefault) {
- this.finalDefault = finalDefault;
- }
-
- public XmlSchemaObjectTable getGroups() {
- return groups;
- }
-
- public XmlSchemaObjectCollection getIncludes() {
- return includes;
- }
-
- public boolean isCompiled() {
- return isCompiled;
- }
-
- public XmlSchemaObjectCollection getItems() {
- return items;
- }
-
- public XmlSchemaObjectTable getNotations() {
- return notations;
- }
-
- public XmlSchemaObjectTable getSchemaTypes() {
- return schemaTypes;
- }
-
- public String getTargetNamespace() {
- return targetNamespace;
- }
-
- public void setTargetNamespace(String targetNamespace) {
- if (!targetNamespace.equals(""))
- this.targetNamespace = targetNamespace;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void compile(ValidationEventHandler eh) {
-
- }
-
- public void write(OutputStream out) {
- write(new OutputStreamWriter(out));
- }
-
- public void write(Writer writer) {
- serialize_internal(this, writer);
- }
-
- public Document[] getAllSchemas() {
- try {
- return XmlSchemaSerializer.serializeSchema(this, true);
- } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
- throw new XmlSchemaException(e.getMessage());
- }
- }
-
- private static void serialize_internal(XmlSchema schema, Writer out) {
- try {
- Document[] serializedSchemas = XmlSchemaSerializer.serializeSchema(schema, false);
- TransformerFactory trFac = TransformerFactory.newInstance();
- Source source = new DOMSource(serializedSchemas[0]);
- Result result = new StreamResult(out);
- javax.xml.transform.Transformer tr = trFac.newTransformer();
- tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- tr.setOutputProperty(OutputKeys.INDENT, "yes");
- tr.transform(source, result);
- out.flush();
- } catch (TransformerConfigurationException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (TransformerException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (IOException e) {
- throw new XmlSchemaException(e.getMessage());
- }
- }
-
- public Hashtable getPrefixToNamespaceMap() {
- return namespaces;
- }
-
- public void setPrefixToNamespaceMap(Hashtable map) {
- this.namespaces = map;
- }
-
- public void addType(XmlSchemaType type) {
- QName qname = type.getQName();
- if (schemaTypes.contains(qname)) {
- throw new RuntimeException("Schema for namespace '" +
- targetNamespace + "' already contains type '" +
- qname.getLocalPart());
- }
- schemaTypes.add(qname, type);
- }
-}
+/*
+ * 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.w3c.dom.Document;
+import org.apache.ws.commons.schema.constants.Constants;
+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;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+
+/**
+ * Contains the definition of a schema. All XML Schema definition language (XSD)
+ * elements are children of the schema element. Represents the World Wide Web
+ * Consortium (W3C) schema element
+ */
+
+// Oct 15th - momo - initial impl
+// Oct 17th - vidyanand - add SimpleType + element
+// Oct 18th - momo - add ComplexType
+// Oct 19th - vidyanand - handle external
+// Dec 6th - Vidyanand - changed RuntimeExceptions thrown to XmlSchemaExceptions
+// Jan 15th - Vidyanand - made changes to SchemaBuilder.handleElement to look for an element ref.
+// Feb 20th - Joni - Change the getXmlSchemaFromLocation schema
+// variable to name s.
+// Feb 21th - Joni - Port to XMLDomUtil and Tranformation.
+
+public class XmlSchema extends XmlSchemaAnnotated implements NamespaceContextOwner {
+ static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
+ XmlSchemaForm attributeFormDefault, elementFormDefault;
+
+ XmlSchemaObjectTable attributeGroups,
+ attributes, elements, groups,
+ notations, schemaTypes;
+ XmlSchemaDerivationMethod blockDefault, finalDefault;
+ XmlSchemaObjectCollection includes, items;
+ boolean isCompiled;
+ String targetNamespace, version;
+ String schema_ns_prefix = "";
+ XmlSchemaCollection parent;
+ private NamespacePrefixList namespaceContext;
+
+ /**
+ * Creates new XmlSchema
+ */
+ public XmlSchema(XmlSchemaCollection parent) {
+ this.parent = parent;
+ attributeFormDefault = new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
+ elementFormDefault = new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
+ blockDefault = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ finalDefault = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ items = new XmlSchemaObjectCollection();
+ includes = new XmlSchemaObjectCollection();
+ elements = new XmlSchemaObjectTable();
+ attributeGroups = new XmlSchemaObjectTable();
+ attributes = new XmlSchemaObjectTable();
+ groups = new XmlSchemaObjectTable();
+ notations = new XmlSchemaObjectTable();
+ schemaTypes = new XmlSchemaObjectTable();
+ }
+
+ public XmlSchema(String namespace, XmlSchemaCollection parent) {
+ this(parent);
+ targetNamespace = namespace;
+ }
+
+ public XmlSchemaForm getAttributeFormDefault() {
+ return attributeFormDefault;
+ }
+
+ public void setAttributeFormDefault(XmlSchemaForm value) {
+ attributeFormDefault = value;
+ }
+
+ public XmlSchemaObjectTable getAttributeGroups() {
+ return attributeGroups;
+ }
+
+ public XmlSchemaObjectTable getAttributes() {
+ return attributes;
+ }
+
+ public XmlSchemaDerivationMethod getBlockDefault() {
+ return blockDefault;
+ }
+
+ public void setBlockDefault(XmlSchemaDerivationMethod blockDefault) {
+ this.blockDefault = blockDefault;
+ }
+
+ public XmlSchemaForm getElementFormDefault() {
+ return elementFormDefault;
+ }
+
+ public void setElementFormDefault(XmlSchemaForm elementFormDefault) {
+ this.elementFormDefault = elementFormDefault;
+ }
+
+ public XmlSchemaObjectTable getElements() {
+ return elements;
+ }
+
+ public XmlSchemaElement getElementByName(QName name) {
+ return (XmlSchemaElement)elements.getItem(name);
+ }
+
+ public XmlSchemaType getTypeByName(QName name) {
+ return (XmlSchemaType)schemaTypes.getItem(name);
+ }
+
+ public XmlSchemaDerivationMethod getFinalDefault() {
+ return finalDefault;
+ }
+
+ public void setFinalDefault(XmlSchemaDerivationMethod finalDefault) {
+ this.finalDefault = finalDefault;
+ }
+
+ public XmlSchemaObjectTable getGroups() {
+ return groups;
+ }
+
+ public XmlSchemaObjectCollection getIncludes() {
+ return includes;
+ }
+
+ public boolean isCompiled() {
+ return isCompiled;
+ }
+
+ public XmlSchemaObjectCollection getItems() {
+ return items;
+ }
+
+ public XmlSchemaObjectTable getNotations() {
+ return notations;
+ }
+
+ public XmlSchemaObjectTable getSchemaTypes() {
+ return schemaTypes;
+ }
+
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+
+ public void setTargetNamespace(String targetNamespace) {
+ if (!targetNamespace.equals(""))
+ this.targetNamespace = targetNamespace;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void compile(ValidationEventHandler eh) {
+
+ }
+
+ public void write(OutputStream out) {
+ write(new OutputStreamWriter(out));
+ }
+
+ public void write(Writer writer) {
+ serialize_internal(this, writer);
+ }
+
+ public Document[] getAllSchemas() {
+ try {
+ return XmlSchemaSerializer.serializeSchema(this, true);
+ } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ private static void serialize_internal(XmlSchema schema, Writer out) {
+ try {
+ Document[] serializedSchemas = XmlSchemaSerializer.serializeSchema(schema, false);
+ TransformerFactory trFac = TransformerFactory.newInstance();
+ Source source = new DOMSource(serializedSchemas[0]);
+ Result result = new StreamResult(out);
+ javax.xml.transform.Transformer tr = trFac.newTransformer();
+ tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ tr.setOutputProperty(OutputKeys.INDENT, "yes");
+ tr.transform(source, result);
+ out.flush();
+ } catch (TransformerConfigurationException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (TransformerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (IOException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ public void addType(XmlSchemaType type) {
+ QName qname = type.getQName();
+ if (schemaTypes.contains(qname)) {
+ throw new RuntimeException("Schema for namespace '" +
+ targetNamespace + "' already contains type '" +
+ qname.getLocalPart());
+ }
+ schemaTypes.add(qname, type);
+ }
+
+ public NamespacePrefixList getNamespaceContext() {
+ return namespaceContext;
+ }
+
+ /**
+ * Sets the schema elements namespace context. This may be used for schema
+ * serialization, until a better mechanism was found.
+ */
+ public void setNamespaceContext(NamespacePrefixList namespaceContext) {
+ this.namespaceContext = namespaceContext;
+ }
+}
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=440228&r1=440227&r2=440228
==============================================================================
--- 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 Mon Sep 4 20:10:32 2006
@@ -1,343 +1,335 @@
-/*
- * 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 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.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-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 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.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- * Contains a cache of XML Schema definition language (XSD).
- *
- */
-public final class XmlSchemaCollection {
- /**
- * Namespaces we know about. Each one has an equivalent XmlSchema.
- */
- Map namespaces = new HashMap();
- /**
- * base URI is used as the base for loading the
- * imports
- */
- String baseUri = null;
- /**
- * In-scope namespaces for XML processing
- */
- 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
- */
- URIResolver schemaResolver = new DefaultURIResolver();
-
- 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
- */
- public void setBaseUri(String baseUri){
- this.baseUri = baseUri;
- }
-
- /**
- * Register a custom URI resolver
- * @param schemaResolver
- */
- public void setSchemaResolver(URIResolver schemaResolver) {
- this.schemaResolver = schemaResolver;
- }
-
- /**
- * This section should comply to the XMLSchema specification; see
- * <a href="http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes">
- * http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes</a>.
- * This needs to be inspected by another pair of eyes
- */
- public void init() {
- /*
- Primitive types
-
- 3.2.1 string
- 3.2.2 boolean
- 3.2.3 decimal
- 3.2.4 float
- 3.2.5 double
- 3.2.6 duration
- 3.2.7 dateTime
- 3.2.8 time
- 3.2.9 date
- 3.2.10 gYearMonth
- 3.2.11 gYear
- 3.2.12 gMonthDay
- 3.2.13 gDay
- 3.2.14 gMonth
- 3.2.15 hexBinary
- 3.2.16 base64Binary
- 3.2.17 anyURI
- 3.2.18 QName
- 3.2.19 NOTATION
- */
- addSimpleType(xsd, Constants.XSD_STRING.getLocalPart());
- addSimpleType(xsd, Constants.XSD_BOOLEAN.getLocalPart());
- addSimpleType(xsd, Constants.XSD_FLOAT.getLocalPart());
- addSimpleType(xsd, Constants.XSD_DOUBLE.getLocalPart());
- addSimpleType(xsd, Constants.XSD_QNAME.getLocalPart());
- addSimpleType(xsd, Constants.XSD_DECIMAL.getLocalPart());
- addSimpleType(xsd, Constants.XSD_DURATION.getLocalPart());
- addSimpleType(xsd, Constants.XSD_DATE.getLocalPart());
- addSimpleType(xsd, Constants.XSD_TIME.getLocalPart());
- addSimpleType(xsd, Constants.XSD_DATETIME.getLocalPart());
- addSimpleType(xsd, Constants.XSD_DAY.getLocalPart());
- addSimpleType(xsd, Constants.XSD_MONTH.getLocalPart());
- addSimpleType(xsd, Constants.XSD_MONTHDAY.getLocalPart());
- addSimpleType(xsd, Constants.XSD_YEAR.getLocalPart());
- addSimpleType(xsd, Constants.XSD_YEARMONTH.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NOTATION.getLocalPart());
- addSimpleType(xsd, Constants.XSD_HEXBIN.getLocalPart());
- addSimpleType(xsd, Constants.XSD_BASE64.getLocalPart());
- addSimpleType(xsd, Constants.XSD_ANYURI.getLocalPart());
-
-
- /*
- 3.3.1 normalizedString
- 3.3.2 token
- 3.3.3 language
- 3.3.4 NMTOKEN
- 3.3.5 NMTOKENS
- 3.3.6 Name
- 3.3.7 NCName
- 3.3.8 ID
- 3.3.9 IDREF
- 3.3.10 IDREFS
- 3.3.11 ENTITY
- 3.3.12 ENTITIES
- 3.3.13 integer
- 3.3.14 nonPositiveInteger
- 3.3.15 negativeInteger
- 3.3.16 long
- 3.3.17 int
- 3.3.18 short
- 3.3.19 byte
- 3.3.20 nonNegativeInteger
- 3.3.21 unsignedLong
- 3.3.22 unsignedInt
- 3.3.23 unsignedShort
- 3.3.24 unsignedByte
- 3.3.25 positiveInteger
- */
-
- //derived types from decimal
- addSimpleType(xsd, Constants.XSD_LONG.getLocalPart());
- addSimpleType(xsd, Constants.XSD_SHORT.getLocalPart());
- addSimpleType(xsd, Constants.XSD_BYTE.getLocalPart());
- addSimpleType(xsd, Constants.XSD_INTEGER.getLocalPart());
- addSimpleType(xsd, Constants.XSD_INT.getLocalPart());
- addSimpleType(xsd, Constants.XSD_POSITIVEINTEGER.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NEGATIVEINTEGER.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NONPOSITIVEINTEGER.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NONNEGATIVEINTEGER.getLocalPart());
- addSimpleType(xsd, Constants.XSD_UNSIGNEDBYTE.getLocalPart());
- addSimpleType(xsd, Constants.XSD_UNSIGNEDINT.getLocalPart());
- addSimpleType(xsd, Constants.XSD_UNSIGNEDLONG.getLocalPart());
- addSimpleType(xsd, Constants.XSD_UNSIGNEDSHORT.getLocalPart());
-
- //derived types from string
- addSimpleType(xsd, Constants.XSD_NAME.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NORMALIZEDSTRING.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NCNAME.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NMTOKEN.getLocalPart());
- addSimpleType(xsd, Constants.XSD_NMTOKENS.getLocalPart());
- addSimpleType(xsd, Constants.XSD_ENTITY.getLocalPart());
- addSimpleType(xsd, Constants.XSD_ENTITIES.getLocalPart());
- addSimpleType(xsd, Constants.XSD_ID.getLocalPart());
- addSimpleType(xsd, Constants.XSD_IDREF.getLocalPart());
- addSimpleType(xsd, Constants.XSD_IDREFS.getLocalPart());
- addSimpleType(xsd, Constants.XSD_LANGUAGE.getLocalPart());
- addSimpleType(xsd, Constants.XSD_TOKEN.getLocalPart());
-
- namespaces.put(XmlSchema.SCHEMA_NS, xsd);
- }
-
- private void addSimpleType(XmlSchema schema,String typeName){
- XmlSchemaSimpleType type;
- type = new XmlSchemaSimpleType(schema);
- type.setName(typeName);
- schema.addType(type);
- }
- public XmlSchema read(Reader r, ValidationEventHandler veh) {
- return read(new InputSource(r), veh);
- }
-
- public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) {
- try {
- DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
- docFac.setNamespaceAware(true);
- DocumentBuilder builder = docFac.newDocumentBuilder();
- Document doc = builder.parse(inputSource);
- return read(doc, inputSource.getSystemId(), veh);
- } catch (ParserConfigurationException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (IOException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (SAXException e) {
- throw new XmlSchemaException(e.getMessage());
- }
- }
-
- 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);
- } catch (TransformerException e) {
- throw new XmlSchemaException(e.getMessage());
- }
- }
-
- public XmlSchema read(Document doc, ValidationEventHandler veh) {
- SchemaBuilder builder = new SchemaBuilder(this);
- return builder.build(doc, null, veh);
- }
-
- public XmlSchema read(Element elem) {
- SchemaBuilder builder = new SchemaBuilder(this);
- return builder.handleXmlSchemaElement(elem, null);
- }
-
- public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) {
- SchemaBuilder builder = new SchemaBuilder(this);
- return builder.build(doc, uri, veh);
- }
-
- public XmlSchema read(Element elem, String uri) {
- SchemaBuilder builder = new SchemaBuilder(this);
- return builder.handleXmlSchemaElement(elem, uri);
- }
-
- /**
- * Creates new XmlSchemaCollection
- */
- public XmlSchemaCollection() {
- init();
- }
-
- /**
- * Retreive an XmlSchema from the collection by its system ID.
- * @param systemId
- */
- public XmlSchema getXmlSchema(String systemId) {
- return (XmlSchema) systemId2Schemas.get(systemId);
- }
-
- /**
- * Return a Set of all the XmlSchemas in this collection.
- */
- public Set getXmlSchemas() {
- return Collections.unmodifiableSet(schemas);
- }
-
- public XmlSchemaElement getElementByQName(QName qname) {
- XmlSchema schema = (XmlSchema)namespaces.get(qname.getNamespaceURI());
- if (schema == null) {
- return null;
- }
- return schema.getElementByName(qname);
- }
-
- public XmlSchemaType getTypeByQName(QName schemaTypeName) {
- XmlSchema schema = (XmlSchema)namespaces.get(schemaTypeName.getNamespaceURI());
- if (schema == null) {
- return null;
- }
- return schema.getTypeByName(schemaTypeName);
- }
-
- Map unresolvedTypes = new HashMap();
-
- void addUnresolvedType(QName type, TypeReceiver receiver) {
- ArrayList receivers = (ArrayList)unresolvedTypes.get(type);
- if (receivers == null) {
- receivers = new ArrayList();
- unresolvedTypes.put(type, receivers);
- }
- receivers.add(receiver);
- }
-
- void resolveType(QName typeName, XmlSchemaType type) {
- ArrayList receivers = (ArrayList)unresolvedTypes.get(typeName);
- if (receivers == null)
- return;
- for (Iterator i = receivers.iterator(); i.hasNext();) {
- TypeReceiver receiver = (TypeReceiver) i.next();
- receiver.setType(type);
- }
- unresolvedTypes.remove(typeName);
- }
-
- public String getNamespaceForPrefix(String prefix) {
- return (String)inScopeNamespaces.get(prefix);
- }
-
- public void mapNamespace(String prefix, String namespaceURI) {
- inScopeNamespaces.put(prefix, namespaceURI);
- }
-}
+/*
+ * 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 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.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+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 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.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Contains a cache of XML Schema definition language (XSD).
+ *
+ */
+public final class XmlSchemaCollection {
+ /**
+ * Namespaces we know about. Each one has an equivalent XmlSchema.
+ */
+ Map namespaces = new HashMap();
+ /**
+ * base URI is used as the base for loading the
+ * imports
+ */
+ String baseUri = null;
+ /**
+ * In-scope namespaces for XML processing
+ */
+ 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
+ */
+ URIResolver schemaResolver = new DefaultURIResolver();
+
+ 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
+ */
+ public void setBaseUri(String baseUri){
+ this.baseUri = baseUri;
+ }
+
+ /**
+ * Register a custom URI resolver
+ * @param schemaResolver
+ */
+ public void setSchemaResolver(URIResolver schemaResolver) {
+ this.schemaResolver = schemaResolver;
+ }
+
+ /**
+ * This section should comply to the XMLSchema specification; see
+ * <a href="http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes">
+ * http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes</a>.
+ * This needs to be inspected by another pair of eyes
+ */
+ public void init() {
+ /*
+ Primitive types
+
+ 3.2.1 string
+ 3.2.2 boolean
+ 3.2.3 decimal
+ 3.2.4 float
+ 3.2.5 double
+ 3.2.6 duration
+ 3.2.7 dateTime
+ 3.2.8 time
+ 3.2.9 date
+ 3.2.10 gYearMonth
+ 3.2.11 gYear
+ 3.2.12 gMonthDay
+ 3.2.13 gDay
+ 3.2.14 gMonth
+ 3.2.15 hexBinary
+ 3.2.16 base64Binary
+ 3.2.17 anyURI
+ 3.2.18 QName
+ 3.2.19 NOTATION
+ */
+ addSimpleType(xsd, Constants.XSD_STRING.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BOOLEAN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_FLOAT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DOUBLE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_QNAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DECIMAL.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DURATION.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DATE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_TIME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DATETIME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DAY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_MONTH.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_MONTHDAY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_YEAR.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_YEARMONTH.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NOTATION.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_HEXBIN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BASE64.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ANYURI.getLocalPart());
+
+
+ /*
+ 3.3.1 normalizedString
+ 3.3.2 token
+ 3.3.3 language
+ 3.3.4 NMTOKEN
+ 3.3.5 NMTOKENS
+ 3.3.6 Name
+ 3.3.7 NCName
+ 3.3.8 ID
+ 3.3.9 IDREF
+ 3.3.10 IDREFS
+ 3.3.11 ENTITY
+ 3.3.12 ENTITIES
+ 3.3.13 integer
+ 3.3.14 nonPositiveInteger
+ 3.3.15 negativeInteger
+ 3.3.16 long
+ 3.3.17 int
+ 3.3.18 short
+ 3.3.19 byte
+ 3.3.20 nonNegativeInteger
+ 3.3.21 unsignedLong
+ 3.3.22 unsignedInt
+ 3.3.23 unsignedShort
+ 3.3.24 unsignedByte
+ 3.3.25 positiveInteger
+ */
+
+ //derived types from decimal
+ addSimpleType(xsd, Constants.XSD_LONG.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_SHORT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BYTE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_INTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_INT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_POSITIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NEGATIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NONPOSITIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NONNEGATIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDBYTE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDINT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDLONG.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDSHORT.getLocalPart());
+
+ //derived types from string
+ addSimpleType(xsd, Constants.XSD_NAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NORMALIZEDSTRING.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NCNAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NMTOKEN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NMTOKENS.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ENTITY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ENTITIES.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ID.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_IDREF.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_IDREFS.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_LANGUAGE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_TOKEN.getLocalPart());
+
+ namespaces.put(XmlSchema.SCHEMA_NS, xsd);
+ }
+
+ private void addSimpleType(XmlSchema schema,String typeName){
+ XmlSchemaSimpleType type;
+ type = new XmlSchemaSimpleType(schema);
+ type.setName(typeName);
+ schema.addType(type);
+ }
+ public XmlSchema read(Reader r, ValidationEventHandler veh) {
+ return read(new InputSource(r), veh);
+ }
+
+ public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) {
+ try {
+ DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
+ docFac.setNamespaceAware(true);
+ DocumentBuilder builder = docFac.newDocumentBuilder();
+ Document doc = builder.parse(inputSource);
+ return read(doc, inputSource.getSystemId(), veh);
+ } catch (ParserConfigurationException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (IOException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (SAXException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ 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);
+ } catch (TransformerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ public XmlSchema read(Document doc, ValidationEventHandler veh) {
+ SchemaBuilder builder = new SchemaBuilder(this);
+ return builder.build(doc, null, veh);
+ }
+
+ public XmlSchema read(Element elem) {
+ SchemaBuilder builder = new SchemaBuilder(this);
+ return builder.handleXmlSchemaElement(elem, null);
+ }
+
+ public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) {
+ SchemaBuilder builder = new SchemaBuilder(this);
+ return builder.build(doc, uri, veh);
+ }
+
+ public XmlSchema read(Element elem, String uri) {
+ SchemaBuilder builder = new SchemaBuilder(this);
+ return builder.handleXmlSchemaElement(elem, uri);
+ }
+
+ /**
+ * Creates new XmlSchemaCollection
+ */
+ public XmlSchemaCollection() {
+ init();
+ }
+
+ /**
+ * Retreive an XmlSchema from the collection by its system ID.
+ * @param systemId
+ */
+ public XmlSchema getXmlSchema(String systemId) {
+ return (XmlSchema) systemId2Schemas.get(systemId);
+ }
+
+ /**
+ * Return a Set of all the XmlSchemas in this collection.
+ */
+ public Set getXmlSchemas() {
+ return Collections.unmodifiableSet(schemas);
+ }
+
+ public XmlSchemaElement getElementByQName(QName qname) {
+ XmlSchema schema = (XmlSchema)namespaces.get(qname.getNamespaceURI());
+ if (schema == null) {
+ return null;
+ }
+ return schema.getElementByName(qname);
+ }
+
+ public XmlSchemaType getTypeByQName(QName schemaTypeName) {
+ XmlSchema schema = (XmlSchema)namespaces.get(schemaTypeName.getNamespaceURI());
+ if (schema == null) {
+ return null;
+ }
+ return schema.getTypeByName(schemaTypeName);
+ }
+
+ Map unresolvedTypes = new HashMap();
+
+ void addUnresolvedType(QName type, TypeReceiver receiver) {
+ ArrayList receivers = (ArrayList)unresolvedTypes.get(type);
+ if (receivers == null) {
+ receivers = new ArrayList();
+ unresolvedTypes.put(type, receivers);
+ }
+ receivers.add(receiver);
+ }
+
+ void resolveType(QName typeName, XmlSchemaType type) {
+ ArrayList receivers = (ArrayList)unresolvedTypes.get(typeName);
+ if (receivers == null)
+ return;
+ for (Iterator i = receivers.iterator(); i.hasNext();) {
+ TypeReceiver receiver = (TypeReceiver) i.next();
+ receiver.setType(type);
+ }
+ unresolvedTypes.remove(typeName);
+ }
+}
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=440228&r1=440227&r2=440228
==============================================================================
--- 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 Mon Sep 4 20:10:32 2006
@@ -23,11 +23,15 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
+import org.xml.sax.helpers.NamespaceSupport;
import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -154,22 +158,20 @@
}
//add the extra namespace decalarations if any are available
- Hashtable prefixToNamespaceMap = schemaObj.getPrefixToNamespaceMap();
- if (null!=prefixToNamespaceMap && !prefixToNamespaceMap.isEmpty()){
- Iterator iterator = prefixToNamespaceMap.keySet().iterator();
- while (iterator.hasNext()) {
- String key = (String)iterator.next();
- if (!"".equals(key)){
- serializedSchema.setAttributeNS(XMLNS_NAMESPACE_URI,
- "xmlns:"+key,
- (String)prefixToNamespaceMap.get(key));
- }
-
+ NamespacePrefixList ctx = schemaObj.getNamespaceContext();
+ String[] prefixes = ctx.getDeclaredPrefixes();
+ for (int i = 0; i < prefixes.length; i++) {
+ String prefix = prefixes[i];
+ String uri = ctx.getNamespaceURI(prefix);
+ if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
+// serializedSchema.setAttributeNS(XMLConstants.NULL_NS_URI,
+// XMLConstants.XMLNS_ATTRIBUTE, uri);
+ } else {
+ serializedSchema.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
+ XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, uri);
}
-
}
-
//after serialize the schema add into documentation
//and add to document collection array which at the end
//returned
@@ -259,29 +261,16 @@
* into specified element
*/
private Element setupNamespaces(Document schemaDocs, XmlSchema schemaObj) {
- Enumeration prefixs = schemaObj.namespaces.keys();
- Enumeration values = schemaObj.namespaces.elements();
-
- /**
- * check all namespace added and register all namespace in
- * hashtable. When finish then set namespace to schema
- * element appropriatelly.
- */
- for (; prefixs.hasMoreElements() && values.hasMoreElements();) {
- String namespace = values.nextElement().toString();
- String prefix = prefixs.nextElement().toString();
- /*
- * if the prefix is there
- * check whether it is an xsd schema namespace
- * set prefix and namespace to the default attribute
- * then register the prefix on hashtable
- */
- if (/*prefix.trim().length()<1 &&*/ namespace.equals(xsdNamespace)) {
- xsdPrefix = prefix;
- schemaObj.schema_ns_prefix = xsdPrefix;
- }
-
- schema_ns.put(namespace, prefix);
+ NamespacePrefixList ctx = schemaObj.getNamespaceContext();
+ schemaObj.schema_ns_prefix = xsdPrefix = ctx.getPrefix(xsdNamespace);
+ if(xsdPrefix == null) {
+ schemaObj.schema_ns_prefix = xsdPrefix = "";
+ }
+ String[] prefixes = ctx.getDeclaredPrefixes();
+ for (int i = 0; i < prefixes.length; i++) {
+ String prefix = prefixes[i];
+ String uri = ctx.getNamespaceURI(prefix);
+ schema_ns.put(uri, prefix);
}
//for schema that not set the xmlns attrib member
if (schema_ns.get(xsdNamespace) == null) {
@@ -1115,13 +1104,14 @@
String oldNamespace = null;
if ((oldNamespace = (String) namespaces.get(prefix)) != null) {
value = value.substring(value.indexOf(":") + 1);
- Hashtable realNamespaces = schema.getPrefixToNamespaceMap();
- java.util.Iterator iter = realNamespaces.keySet().iterator();
- while (iter.hasNext()) {
- prefix = (String) iter.next();
- String namespace = (String) realNamespaces.get(prefix);
- if (namespace.equals(oldNamespace))
+ NamespacePrefixList ctx = schema.getNamespaceContext();
+ String[] prefixes = ctx.getDeclaredPrefixes();
+ for (int j = 0; j < prefixes.length; j++) {
+ String pref = prefixes[j];
+ String uri = ctx.getNamespaceURI(pref);
+ if (uri.equals(oldNamespace)) {
value = prefix + ":" + value;
+ }
}
}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java Mon Sep 4 20:10:32 2006
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 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.utils;
+
+/**
+ * Interface of an object, which is able to provide a namespace
+ * context.
+ */
+public interface NamespaceContextOwner {
+ /**
+ * Returns the objects namespace context.
+ */
+ NamespacePrefixList getNamespaceContext();
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java Mon Sep 4 20:10:32 2006
@@ -0,0 +1,230 @@
+package org.apache.ws.commons.schema.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+public class NamespaceMap extends HashMap implements NamespacePrefixList {
+
+ public NamespaceMap() {
+ }
+
+ public NamespaceMap(Map map) {
+ super(map);
+ }
+
+ public void add(String prefix, String namespaceURI) {
+ put(prefix, namespaceURI);
+ }
+
+ public String[] getDeclaredPrefixes() {
+ Set keys = keySet();
+ return (String[]) keys.toArray(new String[keys.size()]);
+ }
+
+ /**
+ * <p>Get Namespace URI bound to a prefix in the current scope.</p>
+ * <p/>
+ * <p>When requesting a Namespace URI by prefix, the following
+ * table describes the returned Namespace URI value for all
+ * possible prefix values:</p>
+ * <p/>
+ * <table border="2" rules="all" cellpadding="4">
+ * <thead>
+ * <tr>
+ * <td align="center" colspan="2">
+ * <code>getNamespaceURI(prefix)</code>
+ * return value for specified prefixes
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>prefix parameter</td>
+ * <td>Namespace URI return value</td>
+ * </tr>
+ * </thead>
+ * <tbody>
+ * <tr>
+ * <td><code>DEFAULT_NS_PREFIX</code> ("")</td>
+ * <td>default Namespace URI in the current scope or
+ * <code>{@link javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}</code>
+ * when there is no default Namespace URI in the current scope</td>
+ * </tr>
+ * <tr>
+ * <td>bound prefix</td>
+ * <td>Namespace URI bound to prefix in current scope</td>
+ * </tr>
+ * <tr>
+ * <td>unbound prefix</td>
+ * <td><code>{@link javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}</code> </td>
+ * </tr>
+ * <tr>
+ * <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
+ * <td><code>XMLConstants.XML_NS_URI</code>
+ * ("http://www.w3.org/XML/1998/namespace")</td>
+ * </tr>
+ * <tr>
+ * <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
+ * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
+ * ("http://www.w3.org/2000/xmlns/")</td>
+ * </tr>
+ * <tr>
+ * <td><code>null</code></td>
+ * <td><code>IllegalArgumentException</code> is thrown</td>
+ * </tr>
+ * </tbody>
+ * </table>
+ *
+ * @param prefix prefix to look up
+ * @return Namespace URI bound to prefix in the current scope
+ */
+ public String getNamespaceURI(String prefix) {
+ return (String) get(prefix);
+ }
+
+ /**
+ * <p>Get prefix bound to Namespace URI in the current scope.</p>
+ * <p/>
+ * <p>To get all prefixes bound to a Namespace URI in the current
+ * scope, use {@link #getPrefixes(String namespaceURI)}.</p>
+ * <p/>
+ * <p>When requesting a prefix by Namespace URI, the following
+ * table describes the returned prefix value for all Namespace URI
+ * values:</p>
+ * <p/>
+ * <table border="2" rules="all" cellpadding="4">
+ * <thead>
+ * <tr>
+ * <td align="center" colspan="2">
+ * <code>getPrefix(namespaceURI)</code> return value for
+ * specified Namespace URIs
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>Namespace URI parameter</td>
+ * <td>prefix value returned</td>
+ * </tr>
+ * </thead>
+ * <tbody>
+ * <tr>
+ * <td><default Namespace URI></td>
+ * <td><code>XMLConstants.DEFAULT_NS_PREFIX</code> ("")
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>bound Namespace URI</td>
+ * <td>prefix bound to Namespace URI in the current scope,
+ * if multiple prefixes are bound to the Namespace URI in
+ * the current scope, a single arbitrary prefix, whose
+ * choice is implementation dependent, is returned</td>
+ * </tr>
+ * <tr>
+ * <td>unbound Namespace URI</td>
+ * <td><code>null</code></td>
+ * </tr>
+ * <tr>
+ * <td><code>XMLConstants.XML_NS_URI</code>
+ * ("http://www.w3.org/XML/1998/namespace")</td>
+ * <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
+ * </tr>
+ * <tr>
+ * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
+ * ("http://www.w3.org/2000/xmlns/")</td>
+ * <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
+ * </tr>
+ * <tr>
+ * <td><code>null</code></td>
+ * <td><code>IllegalArgumentException</code> is thrown</td>
+ * </tr>
+ * </tbody>
+ * </table>
+ *
+ * @param namespaceURI URI of Namespace to lookup
+ * @return prefix bound to Namespace URI in current context
+ */
+ public String getPrefix(String namespaceURI) {
+ Iterator iterator = entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ if (entry.getValue().equals(namespaceURI)) {
+ return (String) entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * <p>Get all prefixes bound to a Namespace URI in the current
+ * scope.</p>
+ * <p/>
+ * <p>An Iterator over String elements is returned in an arbitrary, <strong>implementation dependent</strong>, order.</p>
+ * <p/>
+ * <p><strong>The <code>Iterator</code> is
+ * <em>not</em> modifiable. e.g. the
+ * <code>remove()</code> method will throw
+ * <code>UnsupportedOperationException</code>.</strong></p>
+ * <p/>
+ * <p>When requesting prefixes by Namespace URI, the following
+ * table describes the returned prefixes value for all Namespace
+ * URI values:</p>
+ * <p/>
+ * <table border="2" rules="all" cellpadding="4">
+ * <thead>
+ * <tr>
+ * <td align="center" colspan="2"><code>
+ * getPrefixes(namespaceURI)</code> return value for
+ * specified Namespace URIs</td>
+ * </tr>
+ * <tr>
+ * <td>Namespace URI parameter</td>
+ * <td>prefixes value returned</td>
+ * </tr>
+ * </thead>
+ * <tbody>
+ * <tr>
+ * <td>bound Namespace URI,
+ * including the <default Namespace URI></td>
+ * <td><code>Iterator</code> over prefixes bound to Namespace URI in
+ * the current scope in an arbitrary, <strong>implementation dependent</strong>,
+ * order</td>
+ * </tr>
+ * <tr>
+ * <td>unbound Namespace URI</td>
+ * <td>empty <code>Iterator</code></td>
+ * </tr>
+ * <tr>
+ * <td><code>XMLConstants.XML_NS_URI</code>
+ * ("http://www.w3.org/XML/1998/namespace")</td>
+ * <td><code>Iterator</code> with one element set to
+ * <code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
+ * </tr>
+ * <tr>
+ * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
+ * ("http://www.w3.org/2000/xmlns/")</td>
+ * <td><code>Iterator</code> with one element set to
+ * <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
+ * </tr>
+ * <tr>
+ * <td><code>null</code></td>
+ * <td><code>IllegalArgumentException</code> is thrown</td>
+ * </tr>
+ * </tbody>
+ * </table>
+ *
+ * @param namespaceURI URI of Namespace to lookup
+ * @return <code>Iterator</code> for all prefixes bound to the
+ * Namespace URI in the current scope
+ */
+ public Iterator getPrefixes(String namespaceURI) {
+ ArrayList list = new ArrayList();
+ Iterator iterator = entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ if (entry.getValue().equals(namespaceURI)) {
+ list.add(entry.getKey());
+ }
+ }
+ return list.iterator();
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java Mon Sep 4 20:10:32 2006
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2006 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.utils;
+
+import javax.xml.namespace.NamespaceContext;
+
+
+/**
+ * Interface of an object, which is able to provide a list of currently
+ * defined namespace prefixes.
+ */
+public interface NamespacePrefixList extends NamespaceContext {
+ /**
+ * Returns the list of currently defined namespace prefixes.
+ */
+ public String[] getDeclaredPrefixes();
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java Mon Sep 4 20:10:32 2006
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2006 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.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+import org.w3c.dom.Node;
+
+
+/**
+ * Implementation of {@link NamespaceContext}, which is based on a DOM node.
+ */
+public class NodeNamespaceContext implements NamespacePrefixList {
+ private static final Collection XML_NS_PREFIX_COLLECTION = Collections.singletonList(XMLConstants.XML_NS_PREFIX);
+ private static final Collection XMLNS_ATTRIBUTE_COLLECTION = Collections.singletonList(XMLConstants.XMLNS_ATTRIBUTE);
+ private Node node;
+ private Map declarations;
+ private String[] prefixes;
+
+ /**
+ * Creates a new instance with the given nodes context.
+ */
+ public NodeNamespaceContext(Node pNode) {
+ node = pNode;
+ }
+
+ private Map getDeclarations() {
+ if (declarations == null) {
+ declarations = new HashMap();
+ declarations.put(XMLConstants.DEFAULT_NS_PREFIX, XMLConstants.NULL_NS_URI);
+ new PrefixCollector(){
+ protected void declare(String pPrefix, String pNamespaceURI) {
+ declarations.put(pPrefix, pNamespaceURI);
+ }
+ }.searchAllPrefixDeclarations(node);
+ Collection keys = declarations.keySet();
+ prefixes = (String[]) keys.toArray(new String[keys.size()]);
+ }
+ return declarations;
+ }
+
+ public String getNamespaceURI(String pPrefix) {
+ if (pPrefix == null) {
+ throw new IllegalArgumentException("The prefix must not be null.");
+ }
+ if (XMLConstants.XML_NS_PREFIX.equals(pPrefix)) {
+ return XMLConstants.XML_NS_URI;
+ }
+ if (XMLConstants.XMLNS_ATTRIBUTE.equals(pPrefix)) {
+ return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+ }
+ final String uri = (String) getDeclarations().get(pPrefix);
+ return uri == null ? XMLConstants.NULL_NS_URI : uri;
+ }
+
+ public String getPrefix(String pNamespaceURI) {
+ if (pNamespaceURI == null) {
+ throw new IllegalArgumentException("The namespace URI must not be null.");
+ }
+ if (XMLConstants.XML_NS_URI.equals(pNamespaceURI)) {
+ return XMLConstants.XML_NS_PREFIX;
+ }
+ if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(pNamespaceURI)) {
+ return XMLConstants.XMLNS_ATTRIBUTE;
+ }
+ Map decl = getDeclarations();
+ for (Iterator iter = decl.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (pNamespaceURI.equals(entry.getValue())) {
+ return (String) entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String pNamespaceURI) {
+ if (pNamespaceURI == null) {
+ throw new IllegalArgumentException("The namespace URI must not be null.");
+ }
+ if (XMLConstants.XML_NS_URI.equals(pNamespaceURI)) {
+ return XML_NS_PREFIX_COLLECTION.iterator();
+ }
+ if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(pNamespaceURI)) {
+ return XMLNS_ATTRIBUTE_COLLECTION.iterator();
+ }
+ final List list = new ArrayList();
+ for (Iterator iter = getDeclarations().entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (pNamespaceURI.equals(entry.getValue())) {
+ list.add(entry.getKey());
+ }
+ }
+ return list.iterator();
+ }
+
+ public String[] getDeclaredPrefixes() {
+ getDeclarations(); // Make sure, that the prefixes array is valid
+ return prefixes;
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java Mon Sep 4 20:10:32 2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 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.utils;
+
+import javax.xml.XMLConstants;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+
+/**
+ * Searches for namespace prefix declarations.
+ */
+public abstract class PrefixCollector {
+ /**
+ * Records a single namespace prefix declaration.
+ */
+ protected abstract void declare(String pPrefix, String pNamespaceURI);
+
+ /**
+ * Searches for namespace prefix declarations in the given node.
+ * For any prefix declaration, it invokes {@link #declare(String, String)}.
+ * This method doesn't work recursively: The parent nodes prefix
+ * declarations are ignored.
+ */
+ public void searchLocalPrefixDeclarations(Node pNode) {
+ if (pNode.getNodeType() == Node.ELEMENT_NODE) {
+ NamedNodeMap map = pNode.getAttributes();
+ for (int i = 0; i < map.getLength(); i++) {
+ Node attr = map.item(i);
+ final String uri = attr.getNamespaceURI();
+ if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri)) {
+ String localName = attr.getLocalName();
+ String prefix = XMLConstants.XMLNS_ATTRIBUTE.equals(localName) ? XMLConstants.DEFAULT_NS_PREFIX : localName;
+ declare(prefix, attr.getNodeValue());
+ }
+ }
+ }
+ }
+
+ /**
+ * Searches for namespace prefix declarations in the given node.
+ * For any prefix declaration, it invokes {@link #declare(String, String)}.
+ * This method works recursively: The parent nodes prefix
+ * declarations are collected before the current nodes.
+ */
+ public void searchAllPrefixDeclarations(Node pNode) {
+ Node parent = pNode.getParentNode();
+ if (parent != null) {
+ searchAllPrefixDeclarations(parent);
+ }
+ searchLocalPrefixDeclarations(pNode);
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java Mon Sep 4 20:10:32 2006
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 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.utils;
+
+import org.apache.ws.commons.schema.XmlSchema;
+
+/**
+ * Interface of an object, which may validate a schemas target namespace.
+ */
+public interface TargetNamespaceValidator {
+ /**
+ * Called for validating the given schemas target namespace.
+ */
+ void validate(XmlSchema pSchema);
+}
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=440228&r1=440227&r2=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/IncludeTest.java Mon Sep 4 20:10:32 2006
@@ -121,4 +121,15 @@
}
+
+ /**
+ * Test importing a schema without namespace into a schema
+ * with namespace.
+ */
+ 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);
+ }
+
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestSimpleRestriction.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestSimpleRestriction.java?view=diff&rev=440228&r1=440227&r2=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestSimpleRestriction.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestSimpleRestriction.java Mon Sep 4 20:10:32 2006
@@ -1,54 +1,62 @@
-package tests;
-
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaType;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
-import org.apache.ws.commons.schema.XmlSchema;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.stream.StreamSource;
-import java.io.InputStream;
-import java.io.FileInputStream;
-/*
- * 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.
- */
-import junit.framework.TestCase;
-
-public class TestSimpleRestriction extends TestCase {
- public void testSimpleRestriction() throws Exception {
- QName TYPE_QNAME = new QName("http://soapinterop.org/types",
- "layoutComponentType");
- QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
- "foo");
-
- InputStream is = new FileInputStream(Resources.asURI("SimpleContentRestriction.xsd"));
- XmlSchemaCollection schema = new XmlSchemaCollection();
- XmlSchema s = schema.read(new StreamSource(is), null);
-
- XmlSchemaType simpleType = schema.getTypeByQName(TYPE_QNAME);
- assertNotNull(simpleType);
-
- XmlSchemaElement elem = schema.getElementByQName(ELEMENT_QNAME);
- assertNotNull(elem);
-
- XmlSchemaType type = elem.getSchemaType();
- assertNotNull(type);
-
-
-
- }
-}
+package tests;
+
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.InputStream;
+import java.io.FileInputStream;
+/*
+ * 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.
+ */
+import junit.framework.TestCase;
+
+public class TestSimpleRestriction extends TestCase {
+ public void testSimpleRestriction() throws Exception {
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "layoutComponentType");
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "foo");
+
+ InputStream is = new FileInputStream(Resources.asURI("SimpleContentRestriction.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ XmlSchema s = schema.read(new StreamSource(is), null);
+
+ XmlSchemaType simpleType = schema.getTypeByQName(TYPE_QNAME);
+ assertNotNull(simpleType);
+
+ XmlSchemaElement elem = schema.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+
+ XmlSchemaType type = elem.getSchemaType();
+ assertNotNull(type);
+ }
+
+ public void testSimpleTypeRestrictionWithoutNamespace() throws Exception {
+ InputStream is = new FileInputStream(Resources.asURI("includedWithoutNamespace.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ XmlSchema s = schema.read(new StreamSource(is), null);
+ XmlSchemaType principalId = schema.getTypeByQName(new QName("", "XdwsPrincipalId"));
+ assertNotNull(principalId);
+ XmlSchemaType groupId = schema.getTypeByQName(new QName("", "XdwsGroupId"));
+ assertNotNull(groupId);
+ assertEquals(groupId.getBaseSchemaType(), principalId);
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd Mon Sep 4 20:10:32 2006
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified">
+ <xs:simpleType name="XdwsPrincipalId">
+ <xs:restriction base="xs:string"/>
+ </xs:simpleType>
+
+ <xs:simpleType name="XdwsGroupId">
+ <xs:restriction base="XdwsPrincipalId"/>
+ </xs:simpleType>
+</xs:schema>
Added: webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includingWithNamespace.xsd
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includingWithNamespace.xsd?view=auto&rev=440228
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includingWithNamespace.xsd (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/includingWithNamespace.xsd Mon Sep 4 20:10:32 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://tns.demo.org"
+ targetNamespace="http://tns.demo.org"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified">
+ <xs:include schemaLocation="src/test/test-resources/includedWithoutNamespace.xsd"/>
+
+ <xs:element name="foo" type="tns:XdwsGroupId"/>
+</xs:schema>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org