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/04/08 18:55:55 UTC
svn commit: r763313 - in /webservices/commons/trunk/modules/XmlSchema/src:
main/java/org/apache/ws/commons/schema/
main/java/org/apache/ws/commons/schema/utils/ test/java/tests/
test/java/tests/customext/attrib/ test/java/tests/customext/elt/ test/java...
Author: bimargulies
Date: Wed Apr 8 16:55:55 2009
New Revision: 763313
URL: http://svn.apache.org/viewvc?rev=763313&view=rev
Log:
Refactoring on the Element element.
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/XmlSchemaElement.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/AllSimpleTypeTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/RedefineTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.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=763313&r1=763312&r2=763313&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 Apr 8 16:55:55 2009
@@ -1613,16 +1613,7 @@
currentSchema.items.add(type);
collection.resolveType(type.getQName(), type);
} else if (el.getLocalName().equals("element")) {
- XmlSchemaElement element = handleElement(currentSchema, el,
- schemaEl, true);
- if (element.isTopLevel()) {
- currentSchema.elements.collection.put(element.getQName(),
- element);
- } else if (element.getRef().getTargetQName() != null) {
- currentSchema.elements.collection.put(element.getRef()
- .getTargetQName(), element);
- }
- currentSchema.items.add(element);
+ handleElement(currentSchema, el, schemaEl, true);
} else if (el.getLocalName().equals("include")) {
handleInclude(currentSchema, el, schemaEl);
} else if (el.getLocalName().equals("import")) {
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=763313&r1=763312&r2=763313&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 Apr 8 16:55:55 2009
@@ -57,7 +57,6 @@
static final String SCHEMA_NS = XMLConstants.W3C_XML_SCHEMA_NS_URI;
private static final String UTF_8_ENCODING = "UTF-8";
- XmlSchemaObjectTable elements;
XmlSchemaObjectTable groups;
XmlSchemaObjectTable notations;
XmlSchemaObjectTable schemaTypes;
@@ -76,6 +75,7 @@
private List<XmlSchemaExternal> externals;
private Map<QName, XmlSchemaAttributeGroup> attributeGroups;
private Map<QName, XmlSchemaAttribute> attributes;
+ private Map<QName, XmlSchemaElement> elements;
private NamespacePrefixList namespaceContext;
// keep the encoding of the input
private String inputEncoding;
@@ -102,7 +102,7 @@
finalDefault = XmlSchemaDerivationMethod.NONE;
items = new XmlSchemaObjectCollection();
externals = new ArrayList<XmlSchemaExternal>();
- elements = new XmlSchemaObjectTable();
+ elements = new HashMap<QName, XmlSchemaElement>();
attributeGroups = new HashMap<QName, XmlSchemaAttributeGroup>();
attributes = new HashMap<QName, XmlSchemaAttribute>();
groups = new XmlSchemaObjectTable();
@@ -167,7 +167,7 @@
this.elementFormDefault = elementFormDefault;
}
- public XmlSchemaObjectTable getElements() {
+ public Map<QName, XmlSchemaElement> getElements() {
return elements;
}
@@ -177,7 +177,7 @@
return null;
}
- XmlSchemaElement element = (XmlSchemaElement)elements.getItem(name);
+ XmlSchemaElement element = elements.get(name);
if (deep) {
if (element == null) {
// search the imports
@@ -805,5 +805,9 @@
this.attributes = attributes;
}
+ void setElements(Map<QName, XmlSchemaElement> elements) {
+ this.elements = elements;
+ }
+
}
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=763313&r1=763312&r2=763313&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 Apr 8 16:55:55 2009
@@ -27,6 +27,8 @@
/**
* Class for attribute types. Represents the World Wide Web Consortium (W3C) attribute element.
+ *
+ * ref= attributes are in the parent items collection, not in the map of named items.
*/
public class XmlSchemaAttribute extends XmlSchemaAnnotated implements XmlSchemaNamedWithForm {
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=763313&r1=763312&r2=763313&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 Apr 8 16:55:55 2009
@@ -27,6 +27,9 @@
/**
* Class for elements. Represents the World Wide Web Consortium (W3C) element element.
+ *
+ * Note that ref= elements are in the parent schema 'items' collection,
+ * not in the 'element' Map.
*/
public class XmlSchemaElement extends XmlSchemaParticle implements TypeReceiver, XmlSchemaNamedWithForm {
@@ -84,6 +87,9 @@
nillable = false;
finalDerivation = XmlSchemaDerivationMethod.NONE;
block = XmlSchemaDerivationMethod.NONE;
+ if (topLevel) {
+ parentSchema.getItems().add(this);
+ }
}
/**
@@ -199,9 +205,14 @@
return namedDelegate.isTopLevel();
}
-
public void setName(String name) {
+ if (namedDelegate.isTopLevel() && namedDelegate.getName() != null) {
+ namedDelegate.getParent().getElements().remove(getQName());
+ }
namedDelegate.setName(name);
+ if (namedDelegate.isTopLevel()) {
+ namedDelegate.getParent().getElements().put(getQName(), this);
+ }
}
public XmlSchemaForm getForm() {
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=763313&r1=763312&r2=763313&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 Apr 8 16:55:55 2009
@@ -35,6 +35,7 @@
public class XmlSchemaRef<T extends XmlSchemaNamed> extends XmlSchemaRefBase {
private Class<? extends T> targetClass;
private T targetObject;
+
public XmlSchemaRef(XmlSchema parent, Class<T> targetClass) {
this.parent = parent;
this.targetClass = targetClass;
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java Wed Apr 8 16:55:55 2009
@@ -19,8 +19,6 @@
package tests;
-import java.util.Iterator;
-
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
@@ -52,9 +50,7 @@
// loop through the schema elements and inspect the SchemaTypeObject
// if the type is registered, then getSchemaType should return a SchemaType
// object
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
+ for (XmlSchemaElement elt : schema.getElements().values()) {
XmlSchemaType schemaType = elt.getSchemaType();
assertNotNull(schemaType);
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/RedefineTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/RedefineTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/RedefineTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/RedefineTest.java Wed Apr 8 16:55:55 2009
@@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -81,12 +82,13 @@
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is), null);
- XmlSchemaObjectTable xsot = schema.getElements();
- assertEquals(1, xsot.getCount());
+ Map<QName, XmlSchemaElement> xsot = schema.getElements();
+ assertEquals(1, xsot.size());
XmlSchemaElement xse = null;
- for (Iterator i = xsot.getValues(); i.hasNext();) {
- xse = (XmlSchemaElement)i.next();
+ Iterator<XmlSchemaElement> ei = xsot.values().iterator();
+ while (ei.hasNext()) {
+ xse = ei.next();
}
assertEquals("vip", xse.getName());
assertEquals(new QName("http://soapinterop.org/types", "person"), xse.getSchemaTypeName());
@@ -95,16 +97,16 @@
assertEquals(1, xsoc.size());
XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.get(0);
- xsot = xsr.getSchemaTypes();
- assertEquals(1, xsot.getCount());
+ XmlSchemaObjectTable redefTypes = xsr.getSchemaTypes();
+ assertEquals(1, redefTypes.getCount());
- for (Iterator i = xsot.getNames(); i.hasNext();) {
+ for (Iterator i = redefTypes.getNames(); i.hasNext();) {
QName qname = (QName)i.next();
assertEquals(new QName("http://soapinterop.org/types", "person"), qname);
}
XmlSchemaComplexType xsct = null;
- for (Iterator i = xsot.getValues(); i.hasNext();) {
+ for (Iterator i = redefTypes.getValues(); i.hasNext();) {
xsct = (XmlSchemaComplexType)i.next();
}
assertNotNull(xsct);
@@ -154,12 +156,13 @@
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is), null);
- XmlSchemaObjectTable xsot = schema.getElements();
- assertEquals(1, xsot.getCount());
+ Map<QName, XmlSchemaElement> elements = schema.getElements();
+ assertEquals(1, elements.size());
XmlSchemaElement xse = null;
- for (Iterator i = xsot.getValues(); i.hasNext();) {
- xse = (XmlSchemaElement)i.next();
+ Iterator<XmlSchemaElement> ei = elements.values().iterator();
+ while (ei.hasNext()) {
+ xse = ei.next();
}
assertEquals("childsizedrink", xse.getName());
assertEquals(new QName("http://soapinterop.org/types", "drinksize"), xse.getSchemaTypeName());
@@ -168,7 +171,7 @@
assertEquals(1, xsoc.size());
XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.get(0);
- xsot = xsr.getSchemaTypes();
+ XmlSchemaObjectTable xsot = xsr.getSchemaTypes();
assertEquals(1, xsot.getCount());
for (Iterator i = xsot.getNames(); i.hasNext();) {
@@ -369,12 +372,13 @@
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is), null);
- XmlSchemaObjectTable xsot = schema.getElements();
- assertEquals(1, xsot.getCount());
+ Map<QName, XmlSchemaElement> elements = schema.getElements();
+ assertEquals(1, elements.size());
XmlSchemaElement xse = null;
- for (Iterator i = xsot.getValues(); i.hasNext();) {
- xse = (XmlSchemaElement)i.next();
+ Iterator<XmlSchemaElement> ei = elements.values().iterator();
+ while (ei.hasNext()) {
+ xse = ei.next();
}
assertEquals("vip", xse.getName());
assertEquals(new QName("http://soapinterop.org/types", "person"), xse.getSchemaTypeName());
@@ -383,7 +387,7 @@
assertEquals(1, xsoc.size());
XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.get(0);
- xsot = xsr.getSchemaTypes();
+ XmlSchemaObjectTable xsot = xsr.getSchemaTypes();
assertEquals(1, xsot.getCount());
for (Iterator i = xsot.getNames(); i.hasNext();) {
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java Wed Apr 8 16:55:55 2009
@@ -18,7 +18,6 @@
*/
package tests.customext.attrib;
-import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -59,9 +58,7 @@
// get the elements and check whether their annotations are properly
// populated
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
+ for (XmlSchemaElement elt : schema.getElements().values()) {
assertNotNull(elt);
Map metaInfoMap = elt.getMetaInfoMap();
assertNotNull(metaInfoMap);
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java Wed Apr 8 16:55:55 2009
@@ -20,7 +20,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -78,10 +77,7 @@
// get the elements and check whether their annotations are properly
// populated
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
- assertNotNull(elt);
+ for (XmlSchemaElement elt : schema.getElements().values()) {
Map metaInfoMap = elt.getMetaInfoMap();
assertNotNull(metaInfoMap);
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java Wed Apr 8 16:55:55 2009
@@ -18,7 +18,6 @@
*/
package tests.customext.elt;
-import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -58,10 +57,7 @@
// get the elements and check whether their annotations are properly
// populated
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
- assertNotNull(elt);
+ for (XmlSchemaElement elt : schema.getElements().values()) {
Map metaInfoMap = elt.getMetaInfoMap();
assertNotNull(metaInfoMap);
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java Wed Apr 8 16:55:55 2009
@@ -20,7 +20,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -78,10 +77,7 @@
// get the elements and check whether their annotations are properly
// populated
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
- assertNotNull(elt);
+ for (XmlSchemaElement elt : schema.getElements().values()) {
Map metaInfoMap = elt.getMetaInfoMap();
assertNotNull(metaInfoMap);
Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java?rev=763313&r1=763312&r2=763313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java Wed Apr 8 16:55:55 2009
@@ -18,7 +18,6 @@
*/
package tests.ext;
-import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -54,10 +53,7 @@
// get the elements and check whether their annotations are properly
// populated
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
- assertNotNull(elt);
+ for (XmlSchemaElement elt : schema.getElements().values()) {
Map metaInfoMap = elt.getMetaInfoMap();
assertNotNull(metaInfoMap);
@@ -79,9 +75,7 @@
// get the elements and check whether their annotations are properly
// populated
- Iterator values = schema.getElements().getValues();
- while (values.hasNext()) {
- XmlSchemaElement elt = (XmlSchemaElement)values.next();
+ for (XmlSchemaElement elt : schema.getElements().values()) {
assertNotNull(elt);
Map metaInfoMap = elt.getMetaInfoMap();
assertNotNull(metaInfoMap);