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 22:51:54 UTC
svn commit: r732522 - 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 13:51:53 2009
New Revision: 732522
URL: http://svn.apache.org/viewvc?rev=732522&view=rev
Log:
Move the <element> to use the new ref discipline.
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/XmlSchemaAttributeGroupRef.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/XmlSchemaSerializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefs2Test.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefsTest.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=732522&r1=732521&r2=732522&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 13:51:53 2009
@@ -291,7 +291,7 @@
} else if (el.getLocalName().equals("attribute")) {
ct.attributes.add(handleAttribute(schema, el, schemaEl));
} else if (el.getLocalName().equals("attributeGroup")) {
- ct.attributes.add(handleAttributeGroupRef(el));
+ ct.attributes.add(handleAttributeGroupRef(schema, el));
} else if (el.getLocalName().equals("group")) {
XmlSchemaGroupRef group = handleGroupRef(schema, el, schemaEl);
ct.particle = group.particle == null ? (XmlSchemaParticle)group : group.particle;
@@ -487,8 +487,7 @@
} else if (el.getAttributeNode("ref") != null) {
String refName = el.getAttribute("ref");
QName refQName = getRefQName(refName, el);
- element.setRefName(refQName);
- element.setName(refQName.getLocalPart());
+ element.getRef().setTargetQName(refQName);
}
}
@@ -844,8 +843,8 @@
XmlSchemaElement element = handleElement(currentSchema, el, schemaEl, true);
if (element.isTopLevel()) {
currentSchema.elements.collection.put(element.getQName(), element);
- } else if (element.getRefName() != null) {
- currentSchema.elements.collection.put(element.getRefName(), element);
+ } else if (element.getRef().getTargetQName() != null) {
+ currentSchema.elements.collection.put(element.getRef().getTargetQName(), element);
}
currentSchema.items.add(element);
} else if (el.getLocalName().equals("include")) {
@@ -1277,7 +1276,7 @@
XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl);
attrGroup.getAttributes().add(attr);
} else if (el.getLocalName().equals("attributeGroup")) {
- XmlSchemaAttributeGroupRef attrGroupRef = handleAttributeGroupRef(el);
+ XmlSchemaAttributeGroupRef attrGroupRef = handleAttributeGroupRef(schema, el);
attrGroup.getAttributes().add(attrGroupRef);
} else if (el.getLocalName().equals("anyAttribute")) {
attrGroup.setAnyAttribute(handleAnyAttribute(schema, el, schemaEl));
@@ -1289,13 +1288,13 @@
return attrGroup;
}
- private XmlSchemaAttributeGroupRef handleAttributeGroupRef(Element attrGroupEl) {
+ private XmlSchemaAttributeGroupRef handleAttributeGroupRef(XmlSchema schema, Element attrGroupEl) {
- XmlSchemaAttributeGroupRef attrGroup = new XmlSchemaAttributeGroupRef();
+ XmlSchemaAttributeGroupRef attrGroup = new XmlSchemaAttributeGroupRef(schema);
if (attrGroupEl.hasAttribute("ref")) {
String ref = attrGroupEl.getAttribute("ref");
- attrGroup.refName = getRefQName(ref, attrGroupEl);
+ attrGroup.getRef().setTargetQName(getRefQName(ref, attrGroupEl));
}
if (attrGroupEl.hasAttribute("id")) {
@@ -1402,7 +1401,7 @@
} else if (el.getLocalName().equals("attribute")) {
ext.attributes.add(handleAttribute(schema, el, schemaEl));
} else if (el.getLocalName().equals("attributeGroup")) {
- ext.attributes.add(handleAttributeGroupRef(el));
+ ext.attributes.add(handleAttributeGroupRef(schema, el));
} else if (el.getLocalName().equals("group")) {
ext.particle = handleGroupRef(schema, el, schemaEl);
} else if (el.getLocalName().equals("anyAttribute")) {
@@ -1437,7 +1436,7 @@
} else if (el.getLocalName().equals("attribute")) {
restriction.attributes.add(handleAttribute(schema, el, schemaEl));
} else if (el.getLocalName().equals("attributeGroup")) {
- restriction.attributes.add(handleAttributeGroupRef(el));
+ restriction.attributes.add(handleAttributeGroupRef(schema, el));
} else if (el.getLocalName().equals("group")) {
restriction.particle = handleGroupRef(schema, el, schemaEl);
} else if (el.getLocalName().equals("anyAttribute")) {
@@ -1731,7 +1730,7 @@
XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl);
ext.attributes.add(attr);
} else if (el.getLocalName().equals("attributeGroup")) {
- XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(el);
+ XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(schema, el);
ext.attributes.add(attrGroup);
} else if (el.getLocalName().equals("anyAttribute")) {
ext.anyAttribute = handleAnyAttribute(schema, el, schemaEl);
@@ -1767,7 +1766,7 @@
XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl);
restriction.attributes.add(attr);
} else if (el.getLocalName().equals("attributeGroup")) {
- XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(el);
+ XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(schema, el);
restriction.attributes.add(attrGroup);
} else if (el.getLocalName().equals("simpleType")) {
restriction.baseType = handleSimpleType(schema, el, schemaEl, false);
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java?rev=732522&r1=732521&r2=732522&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java Wed Jan 7 13:51:53 2009
@@ -19,27 +19,29 @@
package org.apache.ws.commons.schema;
-import javax.xml.namespace.QName;
+import org.apache.ws.commons.schema.utils.XmlSchemaRef;
/**
- * Class for the attribute group reference. Represents the World Wide Web Consortium (W3C) attributeGroup
+ * Class for the attribute group reference.
+ * Represents the World Wide Web Consortium (W3C) attributeGroup
* element with the ref attribute.
*/
public class XmlSchemaAttributeGroupRef extends XmlSchemaAnnotated {
- QName refName;
+ private XmlSchemaRef<XmlSchemaAttributeGroup> ref;
/**
- * Creates new XmlSchemaAttributeGroupRef
+ * Create an attribute group reference.
+ * @param parent containing schema.
*/
- public XmlSchemaAttributeGroupRef() {
+ public XmlSchemaAttributeGroupRef(XmlSchema parent) {
+ ref = new XmlSchemaRef<XmlSchemaAttributeGroup>(parent, XmlSchemaAttributeGroup.class);
}
- public QName getRefName() {
- return this.refName;
- }
-
- public void setRefName(QName refName) {
- this.refName = refName;
+ /**
+ * Return the reference object.
+ * @return
+ */
+ public XmlSchemaRef<XmlSchemaAttributeGroup> getRef() {
+ return ref;
}
-
}
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=732522&r1=732521&r2=732522&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 13:51:53 2009
@@ -23,6 +23,7 @@
import org.apache.ws.commons.schema.utils.XmlSchemaNamedWithForm;
import org.apache.ws.commons.schema.utils.XmlSchemaNamedWithFormImpl;
+import org.apache.ws.commons.schema.utils.XmlSchemaRef;
/**
* Class for elements. Represents the World Wide Web Consortium (W3C) element element.
@@ -35,12 +36,6 @@
*/
private XmlSchemaDerivationMethod block;
- /**
- * 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.
- */
- private XmlSchemaDerivationMethod blockResolved;
private XmlSchemaObjectCollection constraints;
/**
@@ -55,7 +50,7 @@
private boolean abstractElement;
private boolean nillable;
- private QName refName;
+ private XmlSchemaRef<XmlSchemaElement> ref;
/**
* Returns the type of the element. This can either be a complex type or a simple type.
@@ -80,6 +75,10 @@
*/
public XmlSchemaElement(XmlSchema parentSchema, boolean topLevel) {
namedDelegate = new XmlSchemaNamedWithFormImpl(parentSchema, topLevel, true);
+ ref = new XmlSchemaRef<XmlSchemaElement>(parentSchema, XmlSchemaElement.class);
+ namedDelegate.setRefObject(ref);
+ ref.setNamedObject(namedDelegate);
+
constraints = new XmlSchemaObjectCollection();
abstractElement = false;
nillable = false;
@@ -118,10 +117,6 @@
this.finalDerivation = finalDerivationValue;
}
- public XmlSchemaDerivationMethod getBlockResolved() {
- return blockResolved;
- }
-
public String getFixedValue() {
return fixedValue;
}
@@ -146,14 +141,11 @@
this.nillable = isNillable;
}
- public QName getRefName() {
- return refName;
- }
-
- public void setRefName(QName refName) {
- this.refName = refName;
+
+ public XmlSchemaRef<XmlSchemaElement> getRef() {
+ return ref;
}
-
+
public XmlSchemaType getSchemaType() {
return schemaType;
}
@@ -199,8 +191,8 @@
xml += "type=\"" + schemaTypeName + "\"";
}
- if (refName != null) {
- xml += "ref=\"" + refName + "\" ";
+ if (ref.getTargetQName() != null) {
+ xml += "ref=\"" + ref.getTargetQName() + "\" ";
}
if (getMinOccurs() != 1) {
@@ -284,13 +276,6 @@
}
/**
- * @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) {
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=732522&r1=732521&r2=732522&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 13:51:53 2009
@@ -546,9 +546,8 @@
Element attributeGroupRef = createNewElement(doc, "attributeGroup", schema.schemaNamespacePrefix,
XmlSchema.SCHEMA_NS);
-
- if (attributeGroupObj.refName != null) {
- String refName = resolveQName(attributeGroupObj.refName, schema);
+ if (attributeGroupObj.getRef().getTarget() != null) {
+ String refName = resolveQName(attributeGroupObj.getRef().getTargetQName(), schema);
attributeGroupRef.setAttribute("ref", refName);
} else {
throw new XmlSchemaSerializerException("Attribute group must have " + "ref name set");
@@ -1011,9 +1010,9 @@
Element serializedEl = createNewElement(doc, "element", schema.schemaNamespacePrefix,
XmlSchema.SCHEMA_NS);
- if (elementObj.getRefName() != null) {
+ if (elementObj.getRef().getTargetQName() != null) {
- String resolvedName = resolveQName(elementObj.getRefName(), schema);
+ String resolvedName = resolveQName(elementObj.getRef().getTargetQName(), schema);
serializedEl.setAttribute("ref", resolvedName);
} else if (!elementObj.isAnonymous()) {
serializedEl.setAttribute("name", elementObj.getName());
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=732522&r1=732521&r2=732522&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 Wed Jan 7 13:51:53 2009
@@ -46,15 +46,6 @@
finalDerivation = XmlSchemaDerivationMethod.NONE;
}
- /**
- * If there is a base schema type, which by definition has to have a global name, return it.
- *
- * @return the qualified name of the base schema type. Return null if none (e.g. for simple types).
- */
- public QName getBaseSchemaTypeName() {
- return null;
- }
-
public XmlSchemaDerivationMethod getDeriveBy() {
return deriveBy;
}
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=732522&r1=732521&r2=732522&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 13:51:53 2009
@@ -40,6 +40,11 @@
public class XmlSchemaNamedImpl implements XmlSchemaNamed {
protected XmlSchema parentSchema;
+ /*
+ * Some objects implement both name= and ref=. This reference allows us some error
+ * checking.
+ */
+ protected XmlSchemaRefBase refTwin;
// Store the name as a QName for the convenience of QName fans.
private QName qname;
private boolean topLevel;
@@ -52,6 +57,15 @@
this.parentSchema = parent;
this.topLevel = topLevel;
}
+
+ /**
+ * If the named object also implements ref=, it should pass the reference object
+ * here for some error checking.
+ * @param refBase
+ */
+ public void setRefObject(XmlSchemaRefBase refBase) {
+ refTwin = refBase;
+ }
/** {@inheritDoc}*/
public String getName() {
@@ -69,10 +83,16 @@
/** {@inheritDoc}*/
public void setName(String name) {
- if ("".equals(name)) {
+ if (name == null) {
+ this.qname = null;
+ } else if ("".equals(name)) {
throw new XmlSchemaException("Attempt to set empty name.");
+ } else {
+ if (refTwin != null && refTwin.getTargetQName() != null) {
+ throw new XmlSchemaException("Attempt to set name on object with ref='xxx'");
+ }
+ qname = new QName(parentSchema.getLogicalTargetNamespace(), name);
}
- qname = new QName(parentSchema.getLogicalTargetNamespace(), name);
}
/** {@inheritDoc}*/
Modified: 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=732522&r1=732521&r2=732522&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedWithFormImpl.java Wed Jan 7 13:51:53 2009
@@ -87,6 +87,12 @@
* {@inheritDoc}
*/
public QName getWireName() {
- return wireName;
+ // If this is a ref= case, then we take the name from the ref=, not from the QName.
+ // what about ref='foo' form='unqualified'? Is that possible?
+ if (refTwin != null && refTwin.getTargetQName() != null) {
+ return refTwin.getTargetQName();
+ } else {
+ return wireName;
+ }
}
}
Modified: 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=732522&r1=732521&r2=732522&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaRef.java Wed Jan 7 13:51:53 2009
@@ -19,7 +19,6 @@
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;
@@ -33,17 +32,18 @@
/**
* Implementation for ref='QName', a common construct in the schema.
*/
-public class XmlSchemaRef<T extends XmlSchemaNamed> {
+public class XmlSchemaRef<T extends XmlSchemaNamed> extends XmlSchemaRefBase {
private Class<? extends T> targetClass;
- private XmlSchema parent;
- private QName targetQName;
private T targetObject;
-
public XmlSchemaRef(XmlSchema parent, Class<T> targetClass) {
this.parent = parent;
this.targetClass = targetClass;
}
+ protected void forgetTargetObject() {
+ targetObject = null;
+ }
+
public T getTarget() {
if (targetObject == null) {
@@ -65,13 +65,4 @@
}
return targetObject;
}
-
- public QName getTargetQName() {
- return targetQName;
- }
-
- public void setTargetQName(QName targetQName) {
- this.targetQName = targetQName;
- }
-
}
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java?rev=732522&r1=732521&r2=732522&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java Wed Jan 7 13:51:53 2009
@@ -90,7 +90,8 @@
XmlSchemaObjectCollection c = t.getAttributes();
for (Iterator i = c.getIterator(); i.hasNext();) {
XmlSchemaAttributeGroupRef agrn = (XmlSchemaAttributeGroupRef)i.next();
- assertEquals(new QName("http://soapinterop.org/types", "department"), agrn.getRefName());
+ assertEquals(new QName("http://soapinterop.org/types", "department"),
+ agrn.getRef().getTargetQName());
}
XmlSchemaObjectTable attG = schema.getAttributeGroups();
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefs2Test.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefs2Test.java?rev=732522&r1=732521&r2=732522&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefs2Test.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefs2Test.java Wed Jan 7 13:51:53 2009
@@ -62,7 +62,7 @@
Iterator it = items.getIterator();
while (it.hasNext()) {
XmlSchemaElement innerElement = (XmlSchemaElement)it.next();
- assertNotNull(innerElement.getRefName());
+ assertNotNull(innerElement.getRef().getTargetQName());
}
// test writing
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefsTest.java?rev=732522&r1=732521&r2=732522&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefsTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ElementRefsTest.java Wed Jan 7 13:51:53 2009
@@ -55,7 +55,7 @@
Iterator it = items.getIterator();
while (it.hasNext()) {
XmlSchemaElement innerElement = (XmlSchemaElement)it.next();
- assertNotNull(innerElement.getRefName());
+ assertNotNull(innerElement.getRef().getTargetQName());
}
// test writing