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 da...@apache.org on 2007/11/02 01:34:17 UTC
svn commit: r591175 - in
/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema:
XmlSchema.java XmlSchemaAnnotated.java XmlSchemaCollection.java
XmlSchemaElement.java XmlSchemaObjectCollection.java XmlSchemaType.java
Author: dandiep
Date: Thu Nov 1 17:34:16 2007
New Revision: 591175
URL: http://svn.apache.org/viewvc?rev=591175&view=rev
Log:
WSCOMMONS-270: add some toSting() methods
Modified:
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/XmlSchemaAnnotated.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/XmlSchemaElement.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java
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?rev=591175&r1=591174&r2=591175&view=diff
==============================================================================
--- 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 Thu Nov 1 17:34:16 2007
@@ -1,451 +1,455 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ws.commons.schema;
-
-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 org.w3c.dom.Document;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.*;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.*;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-
-
-/**
- * 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 syntacticalTargetNamespace, logicalTargetNamespace, version;
- String schema_ns_prefix = "";
- XmlSchemaCollection parent;
-
- private NamespacePrefixList namespaceContext;
- //keep the encoding of the input
- private String inputEncoding;
-
- public void setInputEncoding(String encoding){
- this.inputEncoding = encoding;
- }
-
- /**
- * Create a new XmlSchema within an XmlSchemaCollection
- *
- * @param parent the parent XmlSchemaCollection
- */
- 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);
- syntacticalTargetNamespace = logicalTargetNamespace = 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) {
- XmlSchemaElement element = (XmlSchemaElement) elements.getItem(name);
- if (element == null) {
- //search the imports
- for (Iterator includedItems = includes.getIterator(); includedItems.hasNext();) {
- Object includeOrImport = includedItems.next();
- XmlSchema schema;
- if (includeOrImport instanceof XmlSchemaImport) {
- schema = ((XmlSchemaImport) includeOrImport).getSchema();
- } else if (includeOrImport instanceof XmlSchemaInclude) {
- schema = ((XmlSchemaInclude) includeOrImport).getSchema();
- } else {
- //skip ?
- continue;
- }
- if (schema != null && schema.getElementByName(name) != null) {
- return schema.getElementByName(name);
- }
- }
- } else {
- return element;
- }
-
- return null;
- }
-
- public XmlSchemaType getTypeByName(QName name) {
- XmlSchemaType type = (XmlSchemaType) schemaTypes.getItem(name);
- if (type == null) {
- //search the imports
- for (Iterator includedItems = includes.getIterator(); includedItems.hasNext();) {
- Object includeOrImport = includedItems.next();
- XmlSchema schema;
- if (includeOrImport instanceof XmlSchemaImport) {
- schema = ((XmlSchemaImport) includeOrImport).getSchema();
- } else if (includeOrImport instanceof XmlSchemaInclude) {
- schema = ((XmlSchemaInclude) includeOrImport).getSchema();
- } else {
- //skip ?
- continue;
- }
-
- if (schema != null && schema.getTypeByName(name) != null) {
- return schema.getTypeByName(name);
- }
- }
- } else {
- return type;
- }
-
- return null;
- }
-
- 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 syntacticalTargetNamespace;
- }
-
- public void setTargetNamespace(String targetNamespace) {
- if (!targetNamespace.equals("")) {
- syntacticalTargetNamespace = logicalTargetNamespace = targetNamespace;
- }
- }
-
- public String getVersion() {
- return version;
- }
-
- /**
- * Serialize the schema into the given output stream
- * @param out - the output stream to write to
- */
- public void write(OutputStream out) {
- if (this.inputEncoding!= null &&
- !"".equals(this.inputEncoding)){
- try {
- write(new OutputStreamWriter(out, this.inputEncoding));
- } catch (UnsupportedEncodingException e) {
- //log the error and just write it without the encoding
-
- write(new OutputStreamWriter(out));
- }
- }else{
- write(new OutputStreamWriter(out));
- }
-
- }
-
- /**
- * Serialize the schema into the given output stream
- * @param out - the output stream to write to
- * @param options - a map of options
- */
- public void write(OutputStream out, Map options) {
- if (this.inputEncoding!= null &&
- !"".equals(this.inputEncoding)){
- try {
- write(new OutputStreamWriter(out, this.inputEncoding), options);
- } catch (UnsupportedEncodingException e) {
- //log the error and just write it without the encoding
- write(new OutputStreamWriter(out));
- }
- }else{
- write(new OutputStreamWriter(out),options);
- }
-
- }
-
- /**
- * Serialize the schema
- *
- * @param writer a Writer to serialize to
- * @param options a way to pass arbitrary options to the internal serializer
- */
- public void write(Writer writer, Map options) {
- serialize_internal(this, writer, options);
- }
-
- /**
- * Serialize the schema
- *
- * @param writer a Writer to serialize to
- */
- public void write(Writer writer) {
- serialize_internal(this, writer, null);
- }
-
- public Document[] getAllSchemas() {
- try {
-
- XmlSchemaSerializer xser = new XmlSchemaSerializer();
- xser.setExtReg(this.parent.getExtReg());
- return xser.serializeSchema(this, true);
-
- } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
- throw new XmlSchemaException(e.getMessage());
- }
- }
-
- /**
- * serialize the schema - this is the method that does the work
- * @param schema XmlSchema to serialize
- * @param out the Writer we'll write to
- * @param options options to customize the serialization
- */
- private void serialize_internal(XmlSchema schema, Writer out, Map options) {
-
- try {
- XmlSchemaSerializer xser = new XmlSchemaSerializer();
- xser.setExtReg(this.parent.getExtReg());
- Document[] serializedSchemas = xser.serializeSchema(schema, false);
- TransformerFactory trFac = TransformerFactory.newInstance();
-
- try {
- trFac.setAttribute("indent-number", "4");
- } catch (IllegalArgumentException e) {
- //do nothing - we'll just silently let this pass if it
- //was not compatible
- }
-
- Source source = new DOMSource(serializedSchemas[0]);
- Result result = new StreamResult(out);
- javax.xml.transform.Transformer tr = trFac.newTransformer();
-
- //use the input encoding if there is one
- if (schema.inputEncoding!= null && !"".equals(schema.inputEncoding)) {
- tr.setOutputProperty(OutputKeys.ENCODING, schema.inputEncoding);
- }
-
- // If options were passed, we'll use them to figure out encoding, etc.
- // If not, we load the default ones.
-
- if (options == null) {
- options = new HashMap();
- loadDefaultOptions(options);
- }
-
- Iterator keys = options.keySet().iterator();
- while (keys.hasNext()) {
- Object key = keys.next();
- tr.setOutputProperty((String)key, (String)options.get(key));
- }
-
- 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());
- }
- }
-
- /**
- * Load the default options
- * @param options - the map of
- */
- private void loadDefaultOptions(Map options) {
- options.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
- options.put(OutputKeys.INDENT, "yes");
- }
-
- public void addType(XmlSchemaType type) {
- QName qname = type.getQName();
- if (schemaTypes.contains(qname)) {
- throw new RuntimeException("Schema for namespace '" +
- syntacticalTargetNamespace + "' already contains type '" +
- qname.getLocalPart());
- }
- schemaTypes.add(qname, type);
- }
-
- public NamespacePrefixList getNamespaceContext() {
- return namespaceContext;
- }
-
- /**
- * Sets the schema element's namespace context. This may be used for schema
- * serialization, until a better mechanism is found.
- *
- * @param namespaceContext representation of the currently defined namespace prefixes
- */
- public void setNamespaceContext(NamespacePrefixList namespaceContext) {
- this.namespaceContext = namespaceContext;
- }
-
- /**
- * Override the equals(Object) method with equivalence checking
- * that is specific to this class.
- */
- public boolean equals(Object what) {
-
- //Note: this method may no longer be required when line number/position are used correctly in XmlSchemaObject.
- //Currently they are simply initialized to zero, but they are used in XmlSchemaObject.equals
- //which can result in a false positive (e.g. if a WSDL contains 2 inlined schemas).
-
- if (what == this) {
- return true;
- }
-
- //If the inherited behaviour determines that the objects are NOT equal, return false.
- //Otherwise, do some further equivalence checking.
-
- if(!super.equals(what)) {
- return false;
- }
-
- if (!(what instanceof XmlSchema)) {
- return false;
- }
-
- XmlSchema xs = (XmlSchema) what;
-
- if (this.id != null) {
- if (!this.id.equals(xs.id)) {
- return false;
- }
- } else {
- if (xs.id != null) {
- return false;
- }
- }
-
- if (this.syntacticalTargetNamespace != null) {
- if (!this.syntacticalTargetNamespace.equals(xs.syntacticalTargetNamespace)) {
- return false;
- }
- } else {
- if (xs.syntacticalTargetNamespace != null) {
- return false;
- }
- }
-
- //TODO decide if further schema content should be checked for equivalence.
-
- return true;
- }
- public String getInputEncoding() {
- return inputEncoding;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ws.commons.schema;
+
+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 org.w3c.dom.Document;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.*;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+
+/**
+ * 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 syntacticalTargetNamespace, logicalTargetNamespace, version;
+ String schema_ns_prefix = "";
+ XmlSchemaCollection parent;
+
+ private NamespacePrefixList namespaceContext;
+ //keep the encoding of the input
+ private String inputEncoding;
+
+ public void setInputEncoding(String encoding){
+ this.inputEncoding = encoding;
+ }
+
+ /**
+ * Create a new XmlSchema within an XmlSchemaCollection
+ *
+ * @param parent the parent XmlSchemaCollection
+ */
+ 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);
+ syntacticalTargetNamespace = logicalTargetNamespace = 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) {
+ XmlSchemaElement element = (XmlSchemaElement) elements.getItem(name);
+ if (element == null) {
+ //search the imports
+ for (Iterator includedItems = includes.getIterator(); includedItems.hasNext();) {
+ Object includeOrImport = includedItems.next();
+ XmlSchema schema;
+ if (includeOrImport instanceof XmlSchemaImport) {
+ schema = ((XmlSchemaImport) includeOrImport).getSchema();
+ } else if (includeOrImport instanceof XmlSchemaInclude) {
+ schema = ((XmlSchemaInclude) includeOrImport).getSchema();
+ } else {
+ //skip ?
+ continue;
+ }
+ if (schema != null && schema.getElementByName(name) != null) {
+ return schema.getElementByName(name);
+ }
+ }
+ } else {
+ return element;
+ }
+
+ return null;
+ }
+
+ public XmlSchemaType getTypeByName(QName name) {
+ XmlSchemaType type = (XmlSchemaType) schemaTypes.getItem(name);
+ if (type == null) {
+ //search the imports
+ for (Iterator includedItems = includes.getIterator(); includedItems.hasNext();) {
+ Object includeOrImport = includedItems.next();
+ XmlSchema schema;
+ if (includeOrImport instanceof XmlSchemaImport) {
+ schema = ((XmlSchemaImport) includeOrImport).getSchema();
+ } else if (includeOrImport instanceof XmlSchemaInclude) {
+ schema = ((XmlSchemaInclude) includeOrImport).getSchema();
+ } else {
+ //skip ?
+ continue;
+ }
+
+ if (schema != null && schema.getTypeByName(name) != null) {
+ return schema.getTypeByName(name);
+ }
+ }
+ } else {
+ return type;
+ }
+
+ return null;
+ }
+
+ 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 syntacticalTargetNamespace;
+ }
+
+ public void setTargetNamespace(String targetNamespace) {
+ if (!targetNamespace.equals("")) {
+ syntacticalTargetNamespace = logicalTargetNamespace = targetNamespace;
+ }
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Serialize the schema into the given output stream
+ * @param out - the output stream to write to
+ */
+ public void write(OutputStream out) {
+ if (this.inputEncoding!= null &&
+ !"".equals(this.inputEncoding)){
+ try {
+ write(new OutputStreamWriter(out, this.inputEncoding));
+ } catch (UnsupportedEncodingException e) {
+ //log the error and just write it without the encoding
+
+ write(new OutputStreamWriter(out));
+ }
+ }else{
+ write(new OutputStreamWriter(out));
+ }
+
+ }
+
+ /**
+ * Serialize the schema into the given output stream
+ * @param out - the output stream to write to
+ * @param options - a map of options
+ */
+ public void write(OutputStream out, Map options) {
+ if (this.inputEncoding!= null &&
+ !"".equals(this.inputEncoding)){
+ try {
+ write(new OutputStreamWriter(out, this.inputEncoding), options);
+ } catch (UnsupportedEncodingException e) {
+ //log the error and just write it without the encoding
+ write(new OutputStreamWriter(out));
+ }
+ }else{
+ write(new OutputStreamWriter(out),options);
+ }
+
+ }
+
+ /**
+ * Serialize the schema
+ *
+ * @param writer a Writer to serialize to
+ * @param options a way to pass arbitrary options to the internal serializer
+ */
+ public void write(Writer writer, Map options) {
+ serialize_internal(this, writer, options);
+ }
+
+ /**
+ * Serialize the schema
+ *
+ * @param writer a Writer to serialize to
+ */
+ public void write(Writer writer) {
+ serialize_internal(this, writer, null);
+ }
+
+ public Document[] getAllSchemas() {
+ try {
+
+ XmlSchemaSerializer xser = new XmlSchemaSerializer();
+ xser.setExtReg(this.parent.getExtReg());
+ return xser.serializeSchema(this, true);
+
+ } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ /**
+ * serialize the schema - this is the method that does the work
+ * @param schema XmlSchema to serialize
+ * @param out the Writer we'll write to
+ * @param options options to customize the serialization
+ */
+ private void serialize_internal(XmlSchema schema, Writer out, Map options) {
+
+ try {
+ XmlSchemaSerializer xser = new XmlSchemaSerializer();
+ xser.setExtReg(this.parent.getExtReg());
+ Document[] serializedSchemas = xser.serializeSchema(schema, false);
+ TransformerFactory trFac = TransformerFactory.newInstance();
+
+ try {
+ trFac.setAttribute("indent-number", "4");
+ } catch (IllegalArgumentException e) {
+ //do nothing - we'll just silently let this pass if it
+ //was not compatible
+ }
+
+ Source source = new DOMSource(serializedSchemas[0]);
+ Result result = new StreamResult(out);
+ javax.xml.transform.Transformer tr = trFac.newTransformer();
+
+ //use the input encoding if there is one
+ if (schema.inputEncoding!= null && !"".equals(schema.inputEncoding)) {
+ tr.setOutputProperty(OutputKeys.ENCODING, schema.inputEncoding);
+ }
+
+ // If options were passed, we'll use them to figure out encoding, etc.
+ // If not, we load the default ones.
+
+ if (options == null) {
+ options = new HashMap();
+ loadDefaultOptions(options);
+ }
+
+ Iterator keys = options.keySet().iterator();
+ while (keys.hasNext()) {
+ Object key = keys.next();
+ tr.setOutputProperty((String)key, (String)options.get(key));
+ }
+
+ 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());
+ }
+ }
+
+ /**
+ * Load the default options
+ * @param options - the map of
+ */
+ private void loadDefaultOptions(Map options) {
+ options.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ options.put(OutputKeys.INDENT, "yes");
+ }
+
+ public void addType(XmlSchemaType type) {
+ QName qname = type.getQName();
+ if (schemaTypes.contains(qname)) {
+ throw new RuntimeException("Schema for namespace '" +
+ syntacticalTargetNamespace + "' already contains type '" +
+ qname.getLocalPart());
+ }
+ schemaTypes.add(qname, type);
+ }
+
+ public NamespacePrefixList getNamespaceContext() {
+ return namespaceContext;
+ }
+
+ /**
+ * Sets the schema element's namespace context. This may be used for schema
+ * serialization, until a better mechanism is found.
+ *
+ * @param namespaceContext representation of the currently defined namespace prefixes
+ */
+ public void setNamespaceContext(NamespacePrefixList namespaceContext) {
+ this.namespaceContext = namespaceContext;
+ }
+
+ /**
+ * Override the equals(Object) method with equivalence checking
+ * that is specific to this class.
+ */
+ public boolean equals(Object what) {
+
+ //Note: this method may no longer be required when line number/position are used correctly in XmlSchemaObject.
+ //Currently they are simply initialized to zero, but they are used in XmlSchemaObject.equals
+ //which can result in a false positive (e.g. if a WSDL contains 2 inlined schemas).
+
+ if (what == this) {
+ return true;
+ }
+
+ //If the inherited behaviour determines that the objects are NOT equal, return false.
+ //Otherwise, do some further equivalence checking.
+
+ if(!super.equals(what)) {
+ return false;
+ }
+
+ if (!(what instanceof XmlSchema)) {
+ return false;
+ }
+
+ XmlSchema xs = (XmlSchema) what;
+
+ if (this.id != null) {
+ if (!this.id.equals(xs.id)) {
+ return false;
+ }
+ } else {
+ if (xs.id != null) {
+ return false;
+ }
+ }
+
+ if (this.syntacticalTargetNamespace != null) {
+ if (!this.syntacticalTargetNamespace.equals(xs.syntacticalTargetNamespace)) {
+ return false;
+ }
+ } else {
+ if (xs.syntacticalTargetNamespace != null) {
+ return false;
+ }
+ }
+
+ //TODO decide if further schema content should be checked for equivalence.
+
+ return true;
+ }
+ public String getInputEncoding() {
+ return inputEncoding;
+ }
+
+ public String toString() {
+ return super.toString() + "[" + logicalTargetNamespace + "]";
+ }
+}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java?rev=591175&r1=591174&r2=591175&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java Thu Nov 1 17:34:16 2007
@@ -67,6 +67,13 @@
public void setUnhandledAttributes(Attr[] unhandledAttributes) {
this.unhandledAttributes = unhandledAttributes;
}
+
+ public String toString() {
+ if (id == null)
+ return super.toString();
+ else
+ return super.toString() + " [id:" + id + "]";
+ }
}
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?rev=591175&r1=591174&r2=591175&view=diff
==============================================================================
--- 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 Thu Nov 1 17:34:16 2007
@@ -1,522 +1,525 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ws.commons.schema;
-
-import org.apache.ws.commons.schema.constants.Constants;
-import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
-import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
-import org.apache.ws.commons.schema.resolver.URIResolver;
-import org.apache.ws.commons.schema.utils.NamespacePrefixList;
-import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
-import org.apache.ws.commons.schema.utils.DOMUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.*;
-
-/**
- * Contains a cache of XML Schema definition language (XSD).
- *
- */
-public final class XmlSchemaCollection {
-
- // the default extension registry
- private ExtensionRegistry extReg = new ExtensionRegistry();
-
- public ExtensionRegistry getExtReg() {
- return extReg;
- }
-
- public void setExtReg(ExtensionRegistry extReg) {
- this.extReg = extReg;
- }
-
- /**
- * This map contains a list of Schema objects keyed in by their namespaces
- * When resolving schemas, this map will be checked for the presence of the schema
- * first
- */
- private Map knownNamespaceMap = new HashMap();
-
- /**
- * get the namespace map
- * @return a map of previously known XMLSchema objects keyed by their namespace (String)
- */
- public Map getKnownNamespaceMap() {
- return knownNamespaceMap;
- }
-
- /**
- * sets the known namespace map
- * @param knownNamespaceMap a map of previously known XMLSchema objects keyed by their namespace (String)
- */
- public void setKnownNamespaceMap(Map knownNamespaceMap) {
- this.knownNamespaceMap = knownNamespaceMap;
- }
-
-
-
- static class SchemaKey {
- private final String namespace;
- private final String systemId;
- SchemaKey(String pNamespace, String pSystemId) {
- namespace = pNamespace == null ? Constants.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 Constants.NULL_NS_URI.equals(namespace) ?
- systemId : ("{" + namespace + "}" + systemId);
- }
- }
-
- /**
- * Map of included schemas.
- */
- private Map schemas = new HashMap();
-
-
- /**
- * base URI is used as the base for loading the
- * imports
- */
- String baseUri = null;
- /**
- * In-scope namespaces for XML processing
- */
- private NamespacePrefixList namespaceContext;
-
- /**
- * 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);
-
- /**
- * stack to track imports (to prevent recursion)
- */
- Stack stack = new Stack();
-
- /**
- * Set the base URI. This is used when schemas need to be
- * loaded from relative locations
- * @param baseUri baseUri for this
- */
- public void setBaseUri(String baseUri){
- this.baseUri = baseUri;
- }
-
- /**
- * Register a custom URI resolver
- * @param schemaResolver resolver
- */
- 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());
-
- SchemaKey key = new SchemaKey(XmlSchema.SCHEMA_NS, null);
- addSchema(key, xsd);
-
- // look for a system property to see whether we have a registered
- // extension registry class. if so we'll instantiate a new one
- // and set it as the extension registry
- //if there is an error, we'll just print out a message and move on.
-
- if (System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY)!= null){
- try {
- Class clazz = Class.forName(System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY));
- this.extReg = (ExtensionRegistry)clazz.newInstance();
- } catch (ClassNotFoundException e) {
- System.err.println("The specified extension registry class cannot be found!");
- } catch (InstantiationException e) {
- System.err.println("The specified extension registry class cannot be instantiated!");
- } catch (IllegalAccessException e) {
- System.err.println("The specified extension registry class cannot be accessed!");
- }
- }
- }
-
- boolean containsSchema(SchemaKey pKey) {
- return schemas.containsKey(pKey);
- }
-
-
- /**
- * gets a schema from the external namespace map
- * @param namespace
- * @return
- */
- XmlSchema getKnownSchema(String namespace) {
- return (XmlSchema) knownNamespaceMap.get(namespace);
- }
-
- /**
- * Get a schema given a SchemaKey
- * @param pKey
- * @return
- */
- 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){
- 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);
- }
-
- 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, namespaceValidator);
- } 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(InputSource inputSource, ValidationEventHandler veh) {
- return read(inputSource, veh, null);
- }
-
- public XmlSchema read(Source source, ValidationEventHandler veh) {
- if (source instanceof SAXSource) {
- return read(((SAXSource) source).getInputSource(), veh);
- } else if (source instanceof DOMSource) {
- Node node = ((DOMSource) source).getNode();
- if (node instanceof Document) {
- node = ((Document) node).getDocumentElement();
- }
- return read((Document) node, veh);
- } else if (source instanceof StreamSource) {
- StreamSource ss = (StreamSource) source;
- InputSource isource = new InputSource(ss.getSystemId());
- isource.setByteStream(ss.getInputStream());
- isource.setCharacterStream(ss.getReader());
- isource.setPublicId(ss.getPublicId());
- return read(isource, veh);
- } else {
- InputSource isource = new InputSource(source.getSystemId());
- return read(isource, veh);
- }
- }
-
- public XmlSchema read(Document doc, ValidationEventHandler veh) {
- SchemaBuilder builder = new SchemaBuilder(this, null);
- return builder.build(doc, null, veh);
- }
-
-
- public XmlSchema read(Element elem) {
- SchemaBuilder builder = new SchemaBuilder(this, null);
- XmlSchema xmlSchema = builder.handleXmlSchemaElement(elem, null);
- xmlSchema.setInputEncoding(DOMUtil.getXmlEncoding(elem.getOwnerDocument()));
- return xmlSchema;
- }
-
- public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) {
- return read(doc, uri, veh, null);
- }
-
- public XmlSchema read(Document doc, String uri, ValidationEventHandler veh,
- TargetNamespaceValidator validator) {
- SchemaBuilder builder = new SchemaBuilder(this, validator);
- XmlSchema schema = builder.build(doc, uri, veh);
- schema.setInputEncoding(doc.getInputEncoding());
- return schema;
- }
-
- public XmlSchema read(Element elem, String uri) {
- SchemaBuilder builder = new SchemaBuilder(this, null);
- XmlSchema xmlSchema = builder.handleXmlSchemaElement(elem, uri);
- xmlSchema.setInputEncoding(DOMUtil.getInputEncoding(elem.getOwnerDocument()));
- return xmlSchema;
- }
-
- /**
- * Creates new XmlSchemaCollection
- */
- public XmlSchemaCollection() {
- init();
- }
-
- /**
- * 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 the system id for this schema
- * @return array of XmlSchema objects
- */
- 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()]);
- }
-
- /**
- * Returns an array of all the XmlSchemas in this collection.
- * @return the list of XmlSchema objects
- */
- public XmlSchema[] getXmlSchemas() {
- Collection c = schemas.values();
- return (XmlSchema[]) c.toArray(new XmlSchema[c.size()]);
- }
-
- public XmlSchemaElement getElementByQName(QName qname) {
- 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 null;
- }
-
- public XmlSchemaType getTypeByQName(QName schemaTypeName) {
- 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 null;
- }
-
- 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 NamespacePrefixList getNamespaceContext() {
- return namespaceContext;
- }
-
- public void setNamespaceContext(NamespacePrefixList namespaceContext) {
- this.namespaceContext = namespaceContext;
- }
-
- public void push(SchemaKey pKey){
- stack.push(pKey);
- }
-
- public void pop(){
- stack.pop();
- }
-
- public boolean check(SchemaKey pKey){
- return (stack.indexOf(pKey)==-1);
- }
-
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
+import org.apache.ws.commons.schema.utils.DOMUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.*;
+
+/**
+ * Contains a cache of XML Schema definition language (XSD).
+ *
+ */
+public final class XmlSchemaCollection {
+
+ // the default extension registry
+ private ExtensionRegistry extReg = new ExtensionRegistry();
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
+ /**
+ * This map contains a list of Schema objects keyed in by their namespaces
+ * When resolving schemas, this map will be checked for the presence of the schema
+ * first
+ */
+ private Map knownNamespaceMap = new HashMap();
+
+ /**
+ * get the namespace map
+ * @return a map of previously known XMLSchema objects keyed by their namespace (String)
+ */
+ public Map getKnownNamespaceMap() {
+ return knownNamespaceMap;
+ }
+
+ /**
+ * sets the known namespace map
+ * @param knownNamespaceMap a map of previously known XMLSchema objects keyed by their namespace (String)
+ */
+ public void setKnownNamespaceMap(Map knownNamespaceMap) {
+ this.knownNamespaceMap = knownNamespaceMap;
+ }
+
+
+
+ static class SchemaKey {
+ private final String namespace;
+ private final String systemId;
+ SchemaKey(String pNamespace, String pSystemId) {
+ namespace = pNamespace == null ? Constants.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 Constants.NULL_NS_URI.equals(namespace) ?
+ systemId : ("{" + namespace + "}" + systemId);
+ }
+ }
+
+ /**
+ * Map of included schemas.
+ */
+ private Map schemas = new HashMap();
+
+
+ /**
+ * base URI is used as the base for loading the
+ * imports
+ */
+ String baseUri = null;
+ /**
+ * In-scope namespaces for XML processing
+ */
+ private NamespacePrefixList namespaceContext;
+
+ /**
+ * 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);
+
+ /**
+ * stack to track imports (to prevent recursion)
+ */
+ Stack stack = new Stack();
+
+ /**
+ * Set the base URI. This is used when schemas need to be
+ * loaded from relative locations
+ * @param baseUri baseUri for this
+ */
+ public void setBaseUri(String baseUri){
+ this.baseUri = baseUri;
+ }
+
+ /**
+ * Register a custom URI resolver
+ * @param schemaResolver resolver
+ */
+ 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());
+
+ SchemaKey key = new SchemaKey(XmlSchema.SCHEMA_NS, null);
+ addSchema(key, xsd);
+
+ // look for a system property to see whether we have a registered
+ // extension registry class. if so we'll instantiate a new one
+ // and set it as the extension registry
+ //if there is an error, we'll just print out a message and move on.
+
+ if (System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY)!= null){
+ try {
+ Class clazz = Class.forName(System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY));
+ this.extReg = (ExtensionRegistry)clazz.newInstance();
+ } catch (ClassNotFoundException e) {
+ System.err.println("The specified extension registry class cannot be found!");
+ } catch (InstantiationException e) {
+ System.err.println("The specified extension registry class cannot be instantiated!");
+ } catch (IllegalAccessException e) {
+ System.err.println("The specified extension registry class cannot be accessed!");
+ }
+ }
+ }
+
+ boolean containsSchema(SchemaKey pKey) {
+ return schemas.containsKey(pKey);
+ }
+
+
+ /**
+ * gets a schema from the external namespace map
+ * @param namespace
+ * @return
+ */
+ XmlSchema getKnownSchema(String namespace) {
+ return (XmlSchema) knownNamespaceMap.get(namespace);
+ }
+
+ /**
+ * Get a schema given a SchemaKey
+ * @param pKey
+ * @return
+ */
+ 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){
+ 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);
+ }
+
+ 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, namespaceValidator);
+ } 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(InputSource inputSource, ValidationEventHandler veh) {
+ return read(inputSource, veh, null);
+ }
+
+ public XmlSchema read(Source source, ValidationEventHandler veh) {
+ if (source instanceof SAXSource) {
+ return read(((SAXSource) source).getInputSource(), veh);
+ } else if (source instanceof DOMSource) {
+ Node node = ((DOMSource) source).getNode();
+ if (node instanceof Document) {
+ node = ((Document) node).getDocumentElement();
+ }
+ return read((Document) node, veh);
+ } else if (source instanceof StreamSource) {
+ StreamSource ss = (StreamSource) source;
+ InputSource isource = new InputSource(ss.getSystemId());
+ isource.setByteStream(ss.getInputStream());
+ isource.setCharacterStream(ss.getReader());
+ isource.setPublicId(ss.getPublicId());
+ return read(isource, veh);
+ } else {
+ InputSource isource = new InputSource(source.getSystemId());
+ return read(isource, veh);
+ }
+ }
+
+ public XmlSchema read(Document doc, ValidationEventHandler veh) {
+ SchemaBuilder builder = new SchemaBuilder(this, null);
+ return builder.build(doc, null, veh);
+ }
+
+
+ public XmlSchema read(Element elem) {
+ SchemaBuilder builder = new SchemaBuilder(this, null);
+ XmlSchema xmlSchema = builder.handleXmlSchemaElement(elem, null);
+ xmlSchema.setInputEncoding(DOMUtil.getXmlEncoding(elem.getOwnerDocument()));
+ return xmlSchema;
+ }
+
+ public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) {
+ return read(doc, uri, veh, null);
+ }
+
+ public XmlSchema read(Document doc, String uri, ValidationEventHandler veh,
+ TargetNamespaceValidator validator) {
+ SchemaBuilder builder = new SchemaBuilder(this, validator);
+ XmlSchema schema = builder.build(doc, uri, veh);
+ schema.setInputEncoding(doc.getInputEncoding());
+ return schema;
+ }
+
+ public XmlSchema read(Element elem, String uri) {
+ SchemaBuilder builder = new SchemaBuilder(this, null);
+ XmlSchema xmlSchema = builder.handleXmlSchemaElement(elem, uri);
+ xmlSchema.setInputEncoding(DOMUtil.getInputEncoding(elem.getOwnerDocument()));
+ return xmlSchema;
+ }
+
+ /**
+ * Creates new XmlSchemaCollection
+ */
+ public XmlSchemaCollection() {
+ init();
+ }
+
+ /**
+ * 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 the system id for this schema
+ * @return array of XmlSchema objects
+ */
+ 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()]);
+ }
+
+ /**
+ * Returns an array of all the XmlSchemas in this collection.
+ * @return the list of XmlSchema objects
+ */
+ public XmlSchema[] getXmlSchemas() {
+ Collection c = schemas.values();
+ return (XmlSchema[]) c.toArray(new XmlSchema[c.size()]);
+ }
+
+ public XmlSchemaElement getElementByQName(QName qname) {
+ 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 null;
+ }
+
+ public XmlSchemaType getTypeByQName(QName schemaTypeName) {
+ 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 null;
+ }
+
+ 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 NamespacePrefixList getNamespaceContext() {
+ return namespaceContext;
+ }
+
+ public void setNamespaceContext(NamespacePrefixList namespaceContext) {
+ this.namespaceContext = namespaceContext;
+ }
+
+ public void push(SchemaKey pKey){
+ stack.push(pKey);
+ }
+
+ public void pop(){
+ stack.pop();
+ }
+
+ public boolean check(SchemaKey pKey){
+ return (stack.indexOf(pKey)==-1);
+ }
+
+ public String toString() {
+ return super.toString() + "[" + schemas.toString() + "]";
+ }
+
+}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java?rev=591175&r1=591174&r2=591175&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java Thu Nov 1 17:34:16 2007
@@ -265,4 +265,8 @@
public void setType(XmlSchemaType type) {
this.schemaType = type;
}
+
+ public String toString() {
+ return super.toString() + "[" + qualifiedName.toString() + "]";
+ }
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java?rev=591175&r1=591174&r2=591175&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java Thu Nov 1 17:34:16 2007
@@ -84,4 +84,8 @@
return xml;
}
+
+ public String toString() {
+ return super.toString() + "[" + objects.toString() + "]";
+ }
}
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?rev=591175&r1=591174&r2=591175&view=diff
==============================================================================
--- 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 Thu Nov 1 17:34:16 2007
@@ -1,97 +1,108 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.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);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.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);
+ }
+
+ public String toString() {
+ if(name == null) {
+ return super.toString() + "[anonymous]";
+ } else if (schema.logicalTargetNamespace == null) {
+ return super.toString() + "[{}" + name + "]";
+
+ } else {
+ return super.toString() + "[{" + schema.logicalTargetNamespace + "}" + name + "]";
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org