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 bi...@apache.org on 2009/01/07 19:31:10 UTC
svn commit: r732417 - 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/
Author: bimargulies
Date: Wed Jan 7 10:31:09 2009
New Revision: 732417
URL: http://svn.apache.org/viewvc?rev=732417&view=rev
Log:
More work on things-with-names. Distinguish the 'name on the wire' of attributes and elements from the 'QName in the collection'.
Added:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java (with props)
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java (with props)
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java (with props)
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.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/XmlSchemaParticle.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/GroupTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestElementForm.java
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java Wed Jan 7 10:31:09 2009
@@ -376,10 +376,10 @@
*/
XmlSchemaElement handleElement(XmlSchema schema, Element el, Element schemaEl, boolean isGlobal) {
- XmlSchemaElement element = new XmlSchemaElement();
+ XmlSchemaElement element = new XmlSchemaElement(schema, isGlobal);
if (el.getAttributeNode("name") != null) {
- element.name = el.getAttribute("name");
+ element.setName(el.getAttribute("name"));
}
// String namespace = (schema.targetNamespace==null)?
@@ -401,19 +401,19 @@
if (simpleTypeEl != null) {
XmlSchemaSimpleType simpleType = handleSimpleType(schema, simpleTypeEl, schemaEl);
- element.schemaType = simpleType;
- element.schemaTypeName = simpleType.getQName();
+ element.setSchemaType(simpleType);
+ element.setSchemaTypeName(simpleType.getQName());
} else {
complexTypeEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "complexType");
if (complexTypeEl != null) {
- element.schemaType = handleComplexType(schema, complexTypeEl, schemaEl);
+ element.setSchemaType(handleComplexType(schema, complexTypeEl, schemaEl));
}
}
keyEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "key");
if (keyEl != null) {
while (keyEl != null) {
- element.constraints.add(handleConstraint(keyEl, XmlSchemaKey.class));
+ element.getConstraints().add(handleConstraint(keyEl, XmlSchemaKey.class));
keyEl = XDOMUtil.getNextSiblingElement(keyEl, "key");
}
}
@@ -426,7 +426,7 @@
String name = keyrefEl.getAttribute("refer");
keyRef.refer = getRefQName(name, el);
}
- element.constraints.add(keyRef);
+ element.getConstraints().add(keyRef);
keyrefEl = XDOMUtil.getNextSiblingElement(keyrefEl, "keyref");
}
}
@@ -434,29 +434,29 @@
uniqueEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "unique");
if (uniqueEl != null) {
while (uniqueEl != null) {
- element.constraints.add(handleConstraint(uniqueEl, XmlSchemaUnique.class));
+ element.getConstraints().add(handleConstraint(uniqueEl, XmlSchemaUnique.class));
uniqueEl = XDOMUtil.getNextSiblingElement(uniqueEl, "unique");
}
}
if (el.hasAttribute("abstract")) {
- element.abstractElement = Boolean.valueOf(el.getAttribute("abstract")).booleanValue();
+ element.setAbstractElement(Boolean.valueOf(el.getAttribute("abstract")).booleanValue());
}
if (el.hasAttribute("block")) {
- element.block = getDerivation(el, "block");
+ element.setBlock(getDerivation(el, "block"));
}
if (el.hasAttribute("default")) {
- element.defaultValue = el.getAttribute("default");
+ element.setDefaultValue(el.getAttribute("default"));
}
if (el.hasAttribute("final")) {
- element.finalDerivation = getDerivation(el, "final");
+ element.setFinalDerivation(getDerivation(el, "final"));
}
if (el.hasAttribute("fixed")) {
- element.fixedValue = el.getAttribute("fixed");
+ element.setFixedValue(el.getAttribute("fixed"));
}
if (el.hasAttribute("id")) {
@@ -464,7 +464,7 @@
}
if (el.hasAttribute("nillable")) {
- element.nillable = Boolean.valueOf(el.getAttribute("nillable")).booleanValue();
+ element.setNillable(Boolean.valueOf(el.getAttribute("nillable")).booleanValue());
}
if (el.hasAttribute("substitutionGroup")) {
@@ -472,8 +472,8 @@
element.setSubstitutionGroup(getRefQName(substitutionGroup, el));
}
- element.minOccurs = getMinOccurs(el);
- element.maxOccurs = getMaxOccurs(el);
+ element.setMinOccurs(getMinOccurs(el));
+ element.setMaxOccurs(getMaxOccurs(el));
// process extra attributes and elements
processExtensibilityComponents(element, el);
@@ -484,20 +484,20 @@
private void handleElementGlobalType(Element el, XmlSchemaElement element) {
if (el.getAttributeNode("type") != null) {
String typeName = el.getAttribute("type");
- element.schemaTypeName = getRefQName(typeName, el);
- QName typeQName = element.schemaTypeName;
+ element.setSchemaTypeName(getRefQName(typeName, el));
+ QName typeQName = element.getSchemaTypeName();
XmlSchemaType type = collection.getTypeByQName(typeQName);
if (type == null) {
// Could be a forward reference...
collection.addUnresolvedType(typeQName, element);
}
- element.schemaType = type;
+ element.setSchemaType(type);
} else if (el.getAttributeNode("ref") != null) {
String refName = el.getAttribute("ref");
QName refQName = getRefQName(refName, el);
element.setRefName(refQName);
- element.name = refQName.getLocalPart();
+ element.setName(refQName.getLocalPart());
}
}
@@ -512,19 +512,15 @@
}
private void handleElementName(boolean isGlobal, XmlSchemaElement element, boolean isQualified) {
- if (element.name != null) {
- final String name = element.name;
- element.qualifiedName = isQualified || isGlobal
- ? newLocalQName(name) : new QName(Constants.NULL_NS_URI, name);
- }
}
private boolean handleElementForm(Element el, XmlSchemaElement element, boolean isQualified) {
if (el.hasAttribute("form")) {
String formDef = el.getAttribute("form");
- element.form = XmlSchemaForm.schemaValueOf(formDef);
- isQualified = element.form == XmlSchemaForm.QUALIFIED;
+ element.setForm(XmlSchemaForm.schemaValueOf(formDef));
}
+ isQualified = element.getForm() == XmlSchemaForm.QUALIFIED;
+
return isQualified;
}
@@ -853,10 +849,10 @@
collection.resolveType(type.getQName(), type);
} else if (el.getLocalName().equals("element")) {
XmlSchemaElement element = handleElement(currentSchema, el, schemaEl, true);
- if (element.qualifiedName != null) {
- currentSchema.elements.collection.put(element.qualifiedName, element);
- } else if (element.refName != null) {
- currentSchema.elements.collection.put(element.refName, element);
+ if (element.isTopLevel()) {
+ currentSchema.elements.collection.put(element.getQName(), element);
+ } else if (element.getRefName() != null) {
+ currentSchema.elements.collection.put(element.getRefName(), element);
}
currentSchema.items.add(element);
} else if (el.getLocalName().equals("include")) {
@@ -1072,8 +1068,8 @@
XmlSchemaAll all = new XmlSchemaAll();
// handle min and max occurences
- all.minOccurs = getMinOccurs(allEl);
- all.maxOccurs = getMaxOccurs(allEl);
+ all.setMinOccurs(getMinOccurs(allEl));
+ all.setMaxOccurs(getMaxOccurs(allEl));
for (Element el = XDOMUtil.getFirstChildElementNS(allEl, XmlSchema.SCHEMA_NS);
el != null;
@@ -1111,8 +1107,8 @@
XmlSchemaAnnotation annotation = handleAnnotation(annotationEl);
any.setAnnotation(annotation);
}
- any.minOccurs = getMinOccurs(anyEl);
- any.maxOccurs = getMaxOccurs(anyEl);
+ any.setMinOccurs(getMinOccurs(anyEl));
+ any.setMaxOccurs(getMaxOccurs(anyEl));
return any;
}
@@ -1331,8 +1327,8 @@
choice.setId(choiceEl.getAttribute("id"));
}
- choice.minOccurs = getMinOccurs(choiceEl);
- choice.maxOccurs = getMaxOccurs(choiceEl);
+ choice.setMinOccurs(getMinOccurs(choiceEl));
+ choice.setMaxOccurs(getMaxOccurs(choiceEl));
for (Element el = XDOMUtil.getFirstChildElementNS(choiceEl, XmlSchema.SCHEMA_NS);
el != null;
@@ -1548,8 +1544,8 @@
XmlSchemaGroupRef group = new XmlSchemaGroupRef();
- group.maxOccurs = getMaxOccurs(groupEl);
- group.minOccurs = getMinOccurs(groupEl);
+ group.setMaxOccurs(getMaxOccurs(groupEl));
+ group.setMinOccurs(getMinOccurs(groupEl));
Element annotationEl = XDOMUtil.getFirstChildElementNS(groupEl, XmlSchema.SCHEMA_NS, "annotation");
@@ -1677,8 +1673,8 @@
XmlSchemaSequence sequence = new XmlSchemaSequence();
// handle min and max occurences
- sequence.minOccurs = getMinOccurs(sequenceEl);
- sequence.maxOccurs = getMaxOccurs(sequenceEl);
+ sequence.setMinOccurs(getMinOccurs(sequenceEl));
+ sequence.setMaxOccurs(getMaxOccurs(sequenceEl));
for (Element el = XDOMUtil.getFirstChildElementNS(sequenceEl, XmlSchema.SCHEMA_NS);
el != null;
@@ -1822,14 +1818,6 @@
};
}
- private QName newLocalQName(String pLocalName) {
- String uri = currentSchema.logicalTargetNamespace;
- if (uri == null) {
- uri = Constants.NULL_NS_URI;
- }
- return new QName(uri, pLocalName);
- }
-
/**
* A generic method to process the extra attributes and the the extra elements present within the schema.
* What are considered extensions are child elements with non schema namespace and child attributes with
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=732417&r1=732416&r2=732417&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 Wed Jan 7 10:31:09 2009
@@ -216,6 +216,42 @@
}
return element;
}
+
+ protected XmlSchemaAttributeGroup getAttributeGroupByName(QName name,
+ boolean deep, Stack<XmlSchema> schemaStack) {
+ if (schemaStack != null && schemaStack.contains(this)) {
+ // recursive schema - just return null
+ return null;
+ }
+
+ XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)attributeGroups.getItem(name);
+ if (deep) {
+ if (group == 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<XmlSchema>();
+ }
+ schemaStack.push(this);
+ group = schema.getAttributeGroupByName(name, deep, schemaStack);
+ if (group != null) {
+ return group;
+ }
+ }
+ }
+ } else {
+ return group;
+ }
+ }
+ return group;
+ }
protected XmlSchemaAttribute getAttributeByName(QName name, boolean deep, Stack<XmlSchema> schemaStack) {
if (schemaStack != null && schemaStack.contains(this)) {
@@ -252,6 +288,78 @@
return attribute;
}
+
+ protected XmlSchemaGroup getGroupByName(QName name, boolean deep, Stack<XmlSchema> schemaStack) {
+ if (schemaStack != null && schemaStack.contains(this)) {
+ // recursive schema - just return null
+ return null;
+ }
+ XmlSchemaGroup group = (XmlSchemaGroup)groups.getItem(name);
+ if (deep) {
+ if (group == 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<XmlSchema>();
+ }
+ schemaStack.push(this);
+ group = schema.getGroupByName(name, deep, schemaStack);
+ if (group != null) {
+ return group;
+ }
+ }
+ }
+ } else {
+ return group;
+ }
+ }
+
+ return group;
+
+ }
+
+ protected XmlSchemaNotation getNotationByName(QName name, boolean deep, Stack<XmlSchema> schemaStack) {
+ if (schemaStack != null && schemaStack.contains(this)) {
+ // recursive schema - just return null
+ return null;
+ }
+ XmlSchemaNotation notation = (XmlSchemaNotation)notations.getItem(name);
+ if (deep) {
+ if (notation == 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<XmlSchema>();
+ }
+ schemaStack.push(this);
+ notation = schema.getNotationByName(name, deep, schemaStack);
+ if (notation != null) {
+ return notation;
+ }
+ }
+ }
+ } else {
+ return notation;
+ }
+ }
+
+ return notation;
+
+ }
/**
* get an element by the name in the local schema
@@ -338,7 +446,7 @@
}
/**
- * Search this schema for a type by qname.
+ * Retrieve a type by QName.
*
* @param name
* @return the type.
@@ -347,7 +455,35 @@
QName nameToSearchFor = new QName(this.getTargetNamespace(), name);
return getTypeByName(nameToSearchFor, false, null);
}
+
+ /**
+ * Retrieve an attribute group by QName.
+ * @param name
+ * @return
+ */
+ public XmlSchemaAttributeGroup getAttributeGroupByName(QName name) {
+ return getAttributeGroupByName(name, true, null);
+ }
+
+ /**
+ * Retrieve a group by QName.
+ * @param name
+ * @return
+ */
+ public XmlSchemaGroup getGroupByName(QName name) {
+ return getGroupByName(name, true, null);
+ }
+
+ /**
+ * Retrieve a notation by QName.
+ * @param name
+ * @return
+ */
+ public XmlSchemaNotation getNotationByName(QName name) {
+ return getNotationByName(name, true, null);
+ }
+
/**
* Get a schema from an import
*
@@ -660,5 +796,9 @@
return super.toString() + "[" + logicalTargetNamespace + "]";
}
+ public XmlSchemaCollection getParent() {
+ return parent;
+ }
+
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java Wed Jan 7 10:31:09 2009
@@ -21,24 +21,21 @@
import javax.xml.namespace.QName;
-import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
-import org.apache.ws.commons.schema.utils.XmlSchemaNamedImpl;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamedWithForm;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamedWithFormImpl;
/**
* Class for attribute types. Represents the World Wide Web Consortium (W3C) attribute element.
*/
-
-// October 15th - momo - initial implementation
-public class XmlSchemaAttribute extends XmlSchemaAnnotated implements XmlSchemaNamed {
+public class XmlSchemaAttribute extends XmlSchemaAnnotated implements XmlSchemaNamedWithForm {
private String defaultValue;
private String fixedValue;
- private XmlSchemaForm form;
private XmlSchemaSimpleType schemaType;
private QName schemaTypeName;
private QName refName;
private XmlSchemaUse use;
- private XmlSchemaNamed namedDelegate;
+ private XmlSchemaNamedWithForm namedDelegate;
/**
* Create a new attribute.
@@ -46,8 +43,7 @@
* @param topLevel true if a global attribute.
*/
public XmlSchemaAttribute(XmlSchema schema, boolean topLevel) {
- namedDelegate = new XmlSchemaNamedImpl(schema, topLevel);
- form = XmlSchemaForm.NONE;
+ namedDelegate = new XmlSchemaNamedWithFormImpl(schema, topLevel, false);
use = XmlSchemaUse.NONE;
}
@@ -67,14 +63,6 @@
this.fixedValue = fixedValue;
}
- public XmlSchemaForm getForm() {
- return form;
- }
-
- public void setSchemaForm(XmlSchemaForm formValue) {
- this.form = formValue;
- }
-
public QName getRefName() {
return refName;
}
@@ -155,7 +143,19 @@
namedDelegate.setName(name);
}
+ public boolean isFormSpecified() {
+ return namedDelegate.isFormSpecified();
+ }
+
+ public XmlSchemaForm getForm() {
+ return namedDelegate.getForm();
+ }
+
public void setForm(XmlSchemaForm form) {
- this.form = form;
+ namedDelegate.setForm(form);
+ }
+
+ public QName getWireName() {
+ return namedDelegate.getWireName();
}
}
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=732417&r1=732416&r2=732417&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 Wed Jan 7 10:31:09 2009
@@ -178,47 +178,6 @@
return stack.indexOf(pKey) == -1;
}
- /**
- * 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;
- }
-
- /**
- * Retrieve a global element from the schema collection.
- *
- * @param qname the element QName.
- * @return the element object, or null.
- */
- 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 ExtensionRegistry getExtReg() {
return extReg;
}
@@ -713,4 +672,92 @@
}
return doc;
}
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Retrieve a global element from the schema collection.
+ *
+ * @param qname the element QName.
+ * @return the element object, or null.
+ */
+ 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 XmlSchemaAttributeGroup getAttributeGroupByQName(QName name) {
+ String uri = name.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ if (((SchemaKey)entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaAttributeGroup group = ((XmlSchema)entry.getValue())
+ .getAttributeGroupByName(name);
+ if (group != null) {
+ return group;
+ }
+ }
+ }
+ return null;
+ }
+
+ public XmlSchemaGroup getGroupByQName(QName name) {
+ String uri = name.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ if (((SchemaKey)entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaGroup group = ((XmlSchema)entry.getValue())
+ .getGroupByName(name);
+ if (group != null) {
+ return group;
+ }
+ }
+ }
+ return null;
+ }
+
+ public XmlSchemaNotation getNotationByQName(QName name) {
+ String uri = name.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ if (((SchemaKey)entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaNotation notation = ((XmlSchema)entry.getValue())
+ .getNotationByName(name);
+ if (notation != null) {
+ return notation;
+ }
+ }
+ }
+ return null;
+ }
+
}
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=732417&r1=732416&r2=732417&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 Wed Jan 7 10:31:09 2009
@@ -21,74 +21,68 @@
import javax.xml.namespace.QName;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamedWithForm;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamedWithFormImpl;
+
/**
* Class for elements. Represents the World Wide Web Consortium (W3C) element element.
*/
-public class XmlSchemaElement extends XmlSchemaParticle implements TypeReceiver {
+public class XmlSchemaElement extends XmlSchemaParticle implements TypeReceiver, XmlSchemaNamedWithForm {
/**
* Attribute used to block a type derivation.
*/
- XmlSchemaDerivationMethod block;
+ private XmlSchemaDerivationMethod block;
/**
- * The value after an element has been compiled to post-schema infoset. This value is either from the type
+ * The value after an element has been compiled to post-schema infoset.
+ * This value is either from the type
* itself or, if not defined on the type, taken from the schema element.
*/
- XmlSchemaDerivationMethod blockResolved;
- XmlSchemaObjectCollection constraints;
+ private XmlSchemaDerivationMethod blockResolved;
+ private XmlSchemaObjectCollection constraints;
/**
* Provides the default value of the element if its content is a simple type or the element's content is
* textOnly.
*/
- String defaultValue;
- String fixedValue;
-
- /**
- * Returns the correct common runtime library object based upon the SchemaType for the element.
- */
- Object elementType;
+ private String defaultValue;
+ private String fixedValue;
- XmlSchemaDerivationMethod finalDerivation;
- XmlSchemaDerivationMethod finalDerivationResolved;
+ private XmlSchemaDerivationMethod finalDerivation;
+ private XmlSchemaDerivationMethod finalDerivationResolved;
- /**
- * The default value is the value of the elementFormDefault attribute for the schema element containing
- * the attribute. The default is Unqualified.
- */
- XmlSchemaForm form;
- boolean abstractElement;
- boolean nillable;
- String name;
- QName qualifiedName;
- QName refName;
+ private boolean abstractElement;
+ private boolean nillable;
+ private QName refName;
/**
* Returns the type of the element. This can either be a complex type or a simple type.
*/
- XmlSchemaType schemaType;
+ private XmlSchemaType schemaType;
/**
* QName of a built-in data type defined in this schema or another schema indicated by the specified
* namespace.
*/
- QName schemaTypeName;
+ private QName schemaTypeName;
/**
* QName of an element that can be a substitute for this element.
*/
- QName substitutionGroup;
+ private QName substitutionGroup;
+
+ private XmlSchemaNamedWithFormImpl namedDelegate;
/**
* Creates new XmlSchemaElement
*/
- public XmlSchemaElement() {
+ public XmlSchemaElement(XmlSchema parentSchema, boolean topLevel) {
+ namedDelegate = new XmlSchemaNamedWithFormImpl(parentSchema, topLevel, true);
constraints = new XmlSchemaObjectCollection();
abstractElement = false;
nillable = false;
- form = XmlSchemaForm.NONE;
finalDerivation = XmlSchemaDerivationMethod.NONE;
block = XmlSchemaDerivationMethod.NONE;
}
@@ -136,18 +130,6 @@
this.fixedValue = fixedValue;
}
- public Object getElementType() {
- return elementType;
- }
-
- public XmlSchemaForm getForm() {
- return form;
- }
-
- public void setForm(XmlSchemaForm form) {
- this.form = form;
- }
-
public boolean isAbstract() {
return abstractElement;
}
@@ -164,14 +146,6 @@
this.nillable = isNillable;
}
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
public QName getRefName() {
return refName;
}
@@ -180,14 +154,6 @@
this.refName = refName;
}
- public QName getQName() {
- return qualifiedName;
- }
-
- public void setQName(QName qname) {
- this.qualifiedName = qname;
- }
-
public XmlSchemaType getSchemaType() {
return schemaType;
}
@@ -225,8 +191,8 @@
xml += "<" + prefix + "element ";
- if (!"".equals(name)) {
- xml += "name=\"" + name + "\" ";
+ if (!isAnonymous()) {
+ xml += "name=\"" + getName() + "\" ";
}
if (schemaTypeName != null) {
@@ -237,12 +203,12 @@
xml += "ref=\"" + refName + "\" ";
}
- if (minOccurs != 1) {
- xml += "minOccurs=\"" + minOccurs + "\" ";
+ if (getMinOccurs() != 1) {
+ xml += "minOccurs=\"" + getMinOccurs() + "\" ";
}
- if (maxOccurs != 1) {
- xml += "maxOccurs=\"" + maxOccurs + "\" ";
+ if (getMaxOccurs() != 1) {
+ xml += "maxOccurs=\"" + getMaxOccurs() + "\" ";
}
if (nillable) {
@@ -270,4 +236,103 @@
public void setType(XmlSchemaType type) {
this.schemaType = type;
}
+
+
+ public String getName() {
+ return namedDelegate.getName();
+ }
+
+
+ public XmlSchema getParent() {
+ return namedDelegate.getParent();
+ }
+
+
+ public QName getQName() {
+ return namedDelegate.getQName();
+ }
+
+
+ public boolean isAnonymous() {
+ return namedDelegate.isAnonymous();
+ }
+
+
+ public boolean isTopLevel() {
+ return namedDelegate.isTopLevel();
+ }
+
+
+ public void setName(String name) {
+ namedDelegate.setName(name);
+ }
+
+ public XmlSchemaForm getForm() {
+ return namedDelegate.getForm();
+ }
+
+ public boolean isFormSpecified() {
+ return namedDelegate.isFormSpecified();
+ }
+
+ public void setForm(XmlSchemaForm form) {
+ namedDelegate.setForm(form);
+ }
+
+ public QName getWireName() {
+ return namedDelegate.getWireName();
+ }
+
+ /**
+ * @param blockResolved The blockResolved to set.
+ */
+ public void setBlockResolved(XmlSchemaDerivationMethod blockResolved) {
+ this.blockResolved = blockResolved;
+ }
+
+ /**
+ * @param constraints The constraints to set.
+ */
+ public void setConstraints(XmlSchemaObjectCollection constraints) {
+ this.constraints = constraints;
+ }
+
+ /**
+ * @param finalDerivation The finalDerivation to set.
+ */
+ public void setFinalDerivation(XmlSchemaDerivationMethod finalDerivation) {
+ this.finalDerivation = finalDerivation;
+ }
+
+ /** * @return Returns the finalDerivation.
+ */
+ public XmlSchemaDerivationMethod getFinalDerivation() {
+ return finalDerivation;
+ }
+
+ /**
+ * @param abstractElement The abstractElement to set.
+ */
+ public void setAbstractElement(boolean abstractElement) {
+ this.abstractElement = abstractElement;
+ }
+
+ /** * @return Returns the abstractElement.
+ */
+ public boolean isAbstractElement() {
+ return abstractElement;
+ }
+
+ /**
+ * @param finalDerivationResolved The finalDerivationResolved to set.
+ */
+ public void setFinalDerivationResolved(XmlSchemaDerivationMethod finalDerivationResolved) {
+ this.finalDerivationResolved = finalDerivationResolved;
+ }
+
+ /** * @return Returns the finalDerivationResolved.
+ */
+ public XmlSchemaDerivationMethod getFinalDerivationResolved() {
+ return finalDerivationResolved;
+ }
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java Wed Jan 7 10:31:09 2009
@@ -20,23 +20,16 @@
package org.apache.ws.commons.schema;
/**
- * Base class for all particle types.
+ * Schema particles. A local element declaration or
+ * reference to a global element declaration (element), a compositor ( sequence, choice, or all), a reference
+ * to a named content model group (group), or an element wildcard (any).
*/
+public abstract class XmlSchemaParticle extends XmlSchemaAnnotated {
+ public static final int DEFAULT_MAX_OCCURS = 1;
+ public static final int DEFAULT_MIN_OCCURS = 1;
-public class XmlSchemaParticle extends XmlSchemaAnnotated {
-
- long maxOccurs = 1;
- String maxOccursString;
- long minOccurs = 1;
- String minOccursString;
-
- /**
- * Creates new XmlSchemaParticle Particle types are usually interchangeable. A local element declaration
- * or reference to a global element declaration (element), a compositor ( sequence, choice, or all), a
- * reference to a named content model group (group), or an element wildcard (any).
- */
- public XmlSchemaParticle() {
- }
+ private long maxOccurs = DEFAULT_MAX_OCCURS;
+ private long minOccurs = DEFAULT_MIN_OCCURS;
public void setMaxOccurs(long maxOccurs) {
this.maxOccurs = maxOccurs;
@@ -53,4 +46,5 @@
public long getMinOccurs() {
return minOccurs;
}
+
}
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?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- 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 Wed Jan 7 10:31:09 2009
@@ -1012,35 +1012,35 @@
Element serializedEl = createNewElement(doc, "element", schema.schemaNamespacePrefix,
XmlSchema.SCHEMA_NS);
- if (elementObj.refName != null) {
+ if (elementObj.getRefName() != null) {
- String resolvedName = resolveQName(elementObj.refName, schema);
+ String resolvedName = resolveQName(elementObj.getRefName(), schema);
serializedEl.setAttribute("ref", resolvedName);
- } else if (elementObj.name != null && elementObj.name.length() > 0) {
- serializedEl.setAttribute("name", elementObj.name);
+ } else if (!elementObj.isAnonymous()) {
+ serializedEl.setAttribute("name", elementObj.getName());
}
- if (elementObj.abstractElement) {
+ if (elementObj.isAbstractElement()) {
serializedEl.setAttribute("abstract", "true");
}
- if (elementObj.block != null && elementObj.block != XmlSchemaDerivationMethod.NONE) {
- serializedEl.setAttribute("block", elementObj.block.toString());
+ if (elementObj.getBlock() != null && elementObj.getBlock() != XmlSchemaDerivationMethod.NONE) {
+ serializedEl.setAttribute("block", elementObj.getBlock().toString());
}
- if (elementObj.defaultValue != null) {
- serializedEl.setAttribute("default", elementObj.defaultValue);
+ if (elementObj.getDefaultValue() != null) {
+ serializedEl.setAttribute("default", elementObj.getDefaultValue());
}
- if (elementObj.finalDerivation != null
- && elementObj.finalDerivation != XmlSchemaDerivationMethod.NONE) {
- serializedEl.setAttribute("final", elementObj.finalDerivation.toString());
+ if (elementObj.getFinalDerivation() != null
+ && elementObj.getFinalDerivation() != XmlSchemaDerivationMethod.NONE) {
+ serializedEl.setAttribute("final", elementObj.getFinalDerivation().toString());
}
- if (elementObj.fixedValue != null) {
- serializedEl.setAttribute("fixed", elementObj.fixedValue);
+ if (elementObj.getFixedValue() != null) {
+ serializedEl.setAttribute("fixed", elementObj.getFixedValue());
}
- if (elementObj.form != XmlSchemaForm.NONE) {
- serializedEl.setAttribute("form", elementObj.form.toString());
+ if (elementObj.isFormSpecified()) {
+ serializedEl.setAttribute("form", elementObj.getForm().toString());
}
if (elementObj.getId() != null) {
@@ -1049,41 +1049,43 @@
serializeMaxMinOccurs(elementObj, serializedEl);
- if (elementObj.substitutionGroup != null) {
- String resolvedQName = resolveQName(elementObj.substitutionGroup, schema);
+ if (elementObj.getSubstitutionGroup() != null) {
+ String resolvedQName = resolveQName(elementObj.getSubstitutionGroup(), schema);
serializedEl.setAttribute("substitutionGroup", resolvedQName);
}
- if (elementObj.schemaTypeName != null) {
- String resolvedName = resolveQName(elementObj.schemaTypeName, schema);
+ if (elementObj.getSchemaTypeName() != null) {
+ String resolvedName = resolveQName(elementObj.getSchemaTypeName(), schema);
serializedEl.setAttribute("type", resolvedName);
}
if (elementObj.getAnnotation() != null) {
Element annotationEl = serializeAnnotation(doc, elementObj.getAnnotation(), schema);
serializedEl.appendChild(annotationEl);
}
- if (elementObj.schemaType != null && elementObj.schemaTypeName == null) {
- if (elementObj.schemaType instanceof XmlSchemaComplexType) {
+ if (elementObj.getSchemaType() != null && elementObj.getSchemaTypeName() == null) {
+ if (elementObj.getSchemaType() instanceof XmlSchemaComplexType) {
- Element complexType = serializeComplexType(doc, (XmlSchemaComplexType)elementObj.schemaType,
- schema);
+ Element complexType =
+ serializeComplexType(doc,
+ (XmlSchemaComplexType)elementObj.getSchemaType(),
+ schema);
serializedEl.appendChild(complexType);
- } else if (elementObj.schemaType instanceof XmlSchemaSimpleType) {
- Element simpleType = serializeSimpleType(doc, (XmlSchemaSimpleType)elementObj.schemaType,
+ } else if (elementObj.getSchemaType() instanceof XmlSchemaSimpleType) {
+ Element simpleType = serializeSimpleType(doc, (XmlSchemaSimpleType)elementObj.getSchemaType(),
schema);
serializedEl.appendChild(simpleType);
}
}
- if (elementObj.constraints.getCount() > 0) {
- for (int i = 0; i < elementObj.constraints.getCount(); i++) {
+ if (elementObj.getConstraints().getCount() > 0) {
+ for (int i = 0; i < elementObj.getConstraints().getCount(); i++) {
Element constraint = serializeIdentityConstraint(
doc,
(XmlSchemaIdentityConstraint)
- elementObj.constraints
+ elementObj.getConstraints()
.getItem(i), schema);
serializedEl.appendChild(constraint);
}
}
- if (elementObj.nillable) {
+ if (elementObj.isNillable()) {
serializedEl.setAttribute("nillable", "true");
}
@@ -2268,17 +2270,18 @@
* @param element
*/
private void serializeMaxMinOccurs(XmlSchemaParticle particle, Element element) {
- if (particle.maxOccurs < Long.MAX_VALUE && (particle.maxOccurs > 1 || particle.maxOccurs == 0)) {
- element.setAttribute("maxOccurs", particle.maxOccurs + "");
- } else if (particle.maxOccurs == Long.MAX_VALUE) {
+ if (particle.getMaxOccurs() < Long.MAX_VALUE
+ && (particle.getMaxOccurs() > 1 || particle.getMaxOccurs() == 0)) {
+ element.setAttribute("maxOccurs", particle.getMaxOccurs() + "");
+ } else if (particle.getMaxOccurs() == Long.MAX_VALUE) {
element.setAttribute("maxOccurs", "unbounded");
// else not serialized
}
// 1 is the default and hence not serialized
// there is no valid case where min occurs can be unbounded!
- if (particle.minOccurs > 1 || particle.minOccurs == 0) {
- element.setAttribute("minOccurs", particle.minOccurs + "");
+ if (particle.getMinOccurs() > 1 || particle.getMinOccurs() == 0) {
+ element.setAttribute("minOccurs", particle.getMinOccurs() + "");
}
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java Wed Jan 7 10:31:09 2009
@@ -22,6 +22,12 @@
import org.apache.ws.commons.schema.XmlSchema;
+/**
+ * A named item. Named items have two names; their schema-local name (a string)
+ * and a QName qualified by their schema's target namespace. Note that the qualified
+ * name is <i>not</i> the on-the-wire name for attributes and elements. Those
+ * names depend on the form, and are managed by {@link XmlSchemaNamedWithForm}.
+ */
public interface XmlSchemaNamed {
/**
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java Wed Jan 7 10:31:09 2009
@@ -72,11 +72,9 @@
if ("".equals(name)) {
throw new XmlSchemaException("Attempt to set empty name.");
}
- // even non-top-level named items have a full qname. After all,
- // if form='qualified', we need to serialize it.
qname = new QName(parentSchema.getLogicalTargetNamespace(), name);
}
-
+
/** {@inheritDoc}*/
public XmlSchema getParent() {
return parentSchema;
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java?rev=732417&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java Wed Jan 7 10:31:09 2009
@@ -0,0 +1,60 @@
+/**
+ * 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.utils;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.commons.schema.XmlSchemaForm;
+
+/**
+ * Attributes and elements have names that are influenced by their form.
+ * Essentially, the 'form' has three possible values: qualified,
+ * unqualified, and 'inherit from parent' (= unspecified).
+ */
+public interface XmlSchemaNamedWithForm extends XmlSchemaNamed {
+ /**
+ * Get the current form, which may be inherited from the parent schema.
+ * This will never return XmlSchemaForm.NONE.
+ * @return
+ */
+ XmlSchemaForm getForm();
+
+ /**
+ * Set the schema form.
+ * @param form Schema form. Pass in XmlSchemaForm.NONE to inherit
+ * from the parent schema.
+ */
+ void setForm(XmlSchemaForm form);
+
+ /**
+ * True if this item has a specified form, false if it inherits from
+ * the parent schema.
+ * @return
+ */
+ boolean isFormSpecified();
+
+ /**
+ * The name of this item as it is sent 'over the wire'. If the form
+ * is unqualified, this has "" for a namespaceURI. Otherwise, it is the
+ * same as getName().
+ * @return
+ */
+ QName getWireName();
+}
Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithForm.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java?rev=732417&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java Wed Jan 7 10:31:09 2009
@@ -0,0 +1,92 @@
+/**
+ * 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.utils;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaException;
+import org.apache.ws.commons.schema.XmlSchemaForm;
+
+/**
+ *
+ */
+public class XmlSchemaNamedWithFormImpl extends XmlSchemaNamedImpl implements XmlSchemaNamedWithForm {
+ private XmlSchemaForm form = XmlSchemaForm.NONE;
+ private boolean element;
+ private QName wireName;
+
+ /**
+ * Delegate object for managing names for attributes and elements.
+ * @param parent containing schema.
+ * @param topLevel if this object is global.
+ * @param element true for an element, false for an attribute.
+ */
+ public XmlSchemaNamedWithFormImpl(XmlSchema parent, boolean topLevel, boolean element) {
+ super(parent, topLevel);
+ this.element = element;
+ }
+
+ /** {@inheritDoc}*/
+ public XmlSchemaForm getForm() {
+ if (form != XmlSchemaForm.NONE) {
+ return form;
+ } else if (element) {
+ return parentSchema.getElementFormDefault();
+ } else {
+ return parentSchema.getAttributeFormDefault();
+ }
+ }
+
+ /** {@inheritDoc}*/
+ public boolean isFormSpecified() {
+ return form != XmlSchemaForm.NONE;
+ }
+
+ /** {@inheritDoc}*/
+ public void setForm(XmlSchemaForm form) {
+ if (form == null) {
+ throw new XmlSchemaException("form may not be null. "
+ + "Pass XmlSchemaForm.NONE to use schema default.");
+ }
+ this.form = form;
+ setName(getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setName(String name) {
+ super.setName(name);
+ if (getForm() == XmlSchemaForm.QUALIFIED) {
+ wireName = getQName();
+ } else {
+ wireName = new QName("", getName());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public QName getWireName() {
+ return wireName;
+ }
+}
Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java?rev=732417&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java Wed Jan 7 10:31:09 2009
@@ -0,0 +1,75 @@
+/**
+ * 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.utils;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAttribute;
+import org.apache.ws.commons.schema.XmlSchemaAttributeGroup;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaGroup;
+import org.apache.ws.commons.schema.XmlSchemaNotation;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * Implementation for ref='QName', a common construct in the schema.
+ */
+public class XmlSchemaRef<T extends XmlSchemaNamed> {
+ private Class<T> targetClass;
+ private XmlSchema parent;
+ private QName targetQName;
+ private T targetObject;
+
+ public XmlSchemaRef(XmlSchema parent, Class<T> targetClass) {
+ this.parent = parent;
+ this.targetClass = targetClass;
+ }
+
+ public T getTarget() {
+ if (targetObject == null) {
+ XmlSchemaCollection parentCollection = parent.getParent();
+ if (targetClass == XmlSchemaElement.class) {
+ targetObject = targetClass.cast(parentCollection.getElementByQName(targetQName));
+ } else if (targetClass == XmlSchemaAttribute.class) {
+ targetObject = targetClass.cast(parentCollection.getAttributeByQName(targetQName));
+ } else if (targetClass == XmlSchemaType.class) {
+ targetObject = targetClass.cast(parentCollection.getTypeByQName(targetQName));
+ } else if (targetClass == XmlSchemaAttributeGroup.class) {
+ targetObject = targetClass.cast(parentCollection.getAttributeGroupByQName(targetQName));
+ } else if (targetClass == XmlSchemaGroup.class) {
+ targetObject = targetClass.cast(parentCollection.getGroupByQName(targetQName));
+ } else if (targetClass == XmlSchemaNotation.class) {
+ targetObject = targetClass.cast(parentCollection.getNotationByQName(targetQName));
+ }
+ }
+ return targetObject;
+ }
+
+ public QName getTargetQName() {
+ return targetQName;
+ }
+
+ public void setTargetQName(QName targetQName) {
+ this.targetQName = targetQName;
+ }
+
+}
Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java Wed Jan 7 10:31:09 2009
@@ -83,10 +83,10 @@
XmlSchemaElement e = (XmlSchemaElement)iterator.next();
String eName = e.getName();
if ("desktop".equals(eName)) {
- assertEquals(new QName("", "desktop"), e.getQName());
+ assertEquals(new QName("", "desktop"), e.getWireName());
assertEquals(e.getName(), "desktop");
} else if ("laptop".equals(eName)) {
- assertEquals(new QName("", "laptop"), e.getQName());
+ assertEquals(new QName("", "laptop"), e.getWireName());
assertEquals(e.getName(), "laptop");
} else {
fail("Should have had a name of desktop or laptop, but" + " instead had " + eName);
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java Wed Jan 7 10:31:09 2009
@@ -87,19 +87,19 @@
XmlSchemaElement xse = (XmlSchemaElement)col.getItem(i);
String name = xse.getName();
if ("Name".equals(name)) {
- assertEquals(new QName("", "Name"), xse.getQName());
+ assertEquals(new QName("", "Name"), xse.getWireName());
assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
xse.getSchemaTypeName());
assertTrue(!xse.isAbstract());
assertTrue(!xse.isNillable());
} else if ("Description".equals(name)) {
- assertEquals(new QName("", "Description"), xse.getQName());
+ assertEquals(new QName("", "Description"), xse.getWireName());
assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
"string"), xse.getSchemaTypeName());
assertTrue(!xse.isAbstract());
assertTrue(xse.isNillable());
} else if ("Parts".equals(name)) {
- assertEquals(new QName("", "Parts"), xse.getQName());
+ assertEquals(new QName("", "Parts"), xse.getWireName());
assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
xse.getSchemaTypeName());
} else {
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/GroupTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/GroupTest.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/GroupTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/GroupTest.java Wed Jan 7 10:31:09 2009
@@ -117,13 +117,13 @@
XmlSchemaElement e = (XmlSchemaElement)iterator.next();
String eName = e.getName();
if ("fullPrice".equals(eName)) {
- assertEquals(new QName("", "fullPrice"), e.getQName());
+ assertEquals(new QName("", "fullPrice"), e.getWireName());
} else if ("salePrice".equals(eName)) {
- assertEquals(new QName("", "salePrice"), e.getQName());
+ assertEquals(new QName("", "salePrice"), e.getWireName());
} else if ("clearancePrice".equals(eName)) {
- assertEquals(new QName("", "clearancePrice"), e.getQName());
+ assertEquals(new QName("", "clearancePrice"), e.getWireName());
} else if ("freePrice".equals(eName)) {
- assertEquals(new QName("", "freePrice"), e.getQName());
+ assertEquals(new QName("", "freePrice"), e.getWireName());
} else {
fail("The name \"" + eName + "\" was found but shouldn't " + "have been found.");
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestElementForm.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestElementForm.java?rev=732417&r1=732416&r2=732417&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestElementForm.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/TestElementForm.java Wed Jan 7 10:31:09 2009
@@ -58,10 +58,10 @@
XmlSchemaObjectCollection items = seq.getItems();
XmlSchemaElement subElement;
subElement = (XmlSchemaElement)items.getItem(0);
- QName qname = subElement.getQName();
+ QName qname = subElement.getWireName();
assertEquals("Namespace on unqualified element", "", qname.getNamespaceURI());
subElement = (XmlSchemaElement)items.getItem(1);
- qname = subElement.getQName();
+ qname = subElement.getWireName();
assertEquals("Bad namespace on qualified element", NS, qname.getNamespaceURI());
}
}