Author: bimargulies
Date: Sat Nov 15 18:57:25 2008
New Revision: 717967
URL: http://svn.apache.org/viewvc?rev=717967&view=rev
Log:
WSCOMMONS-396
Modified:
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
Modified:
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java?rev=717967&r1=717966&r2=717967&view=diff
==============================================================================
---
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
(original)
+++
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
Sat Nov 15 18:57:25 2008
@@ -210,6 +210,45 @@
return element;
}
}
+
+ protected XmlSchemaAttribute getAttributeByName(QName name, boolean deep,
Stack schemaStack) {
+ if (schemaStack != null &&
schemaStack.contains(this)) {
+ // recursive schema - just
return null
+ return null;
+ } else {
+ XmlSchemaAttribute attribute =
(XmlSchemaAttribute) attributes
+ .getItem(name);
+ if (deep) {
+ if (attribute == null)
{
+ // search the
imports
+ for (Iterator
includedItems = includes.getIterator(); includedItems
+
.hasNext();) {
+
+
XmlSchema schema = getSchema(includedItems.next());
+
+ if
(schema != null) {
+ //
create an empty stack - push the current parent in
+ // and
+ // use
the protected method to process the schema
+ if
(schemaStack == null) {
+
schemaStack = new Stack();
+ }
+
schemaStack.push(this);
+
attribute = schema.getAttributeByName(name, deep,
+
schemaStack);
+ if
(attribute != null) {
+
return attribute;
+ }
+ }
+ }
+ } else {
+ return
attribute;
+ }
+ }
+
+ return attribute;
+ }
+ }
/**
* get an element by the name in the local schema
@@ -230,6 +269,15 @@
public XmlSchemaElement getElementByName(QName name) {
return this.getElementByName(name, true, null);
}
+
+ /**
+ * Look for a global attribute by its QName. Searches through all
schemas.
+ * @param name
+ * @return
+ */
+ public XmlSchemaAttribute getAttributeByName(QName name) {
+ return this.getAttributeByName(name, true, null);
+ }
/**
* protected method that allows safe (non-recursive schema loading)
Modified:
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java?rev=717967&r1=717966&r2=717967&view=diff
==============================================================================
---
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
(original)
+++
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
Sat Nov 15 18:57:25 2008
@@ -179,7 +179,7 @@
public void init() {
/*
- * Defined in section .
+ * Defined in section 4.
*/
addSimpleType(xsd, Constants.XSD_ANYSIMPLETYPE.getLocalPart());
addSimpleType(xsd, Constants.XSD_ANYTYPE.getLocalPart());
@@ -513,6 +513,40 @@
}
return null;
}
+
+ /**
+ * Find a global attribute by QName in this collection of schemas.
+ * @param schemaAttributeName the name of the attribute.
+ * @return the attribute or null.
+ */
+ public XmlSchemaAttribute getAttributeByQName(QName schemaAttributeName) {
+ String uri = schemaAttributeName.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext();
) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaAttribute attribute = ((XmlSchema)
entry.getValue()).getAttributeByName(schemaAttributeName);
+ if (attribute != null) {
+ return attribute;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the schema from this collection for a particular targetNamespace.
+ * @param uri target namespace URI.
+ * @return
+ */
+ public XmlSchema schemaForNamespace(String uri) {
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext();
) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getNamespace().equals(uri)) {
+ return (XmlSchema) entry.getValue();
+ }
+ }
+ return null;
+ }
Map unresolvedTypes = new HashMap();