Author: bimargulies Date: Sat Nov 7 19:53:16 2009 New Revision: 833739 URL: http://svn.apache.org/viewvc?rev=833739&view=rev Log: XmlSchemaIdentityConstraint modernization.
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/XmlSchemaIdentityConstraint.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/XmlSchemaSimpleContentExtension.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ConstraintsTest.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.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=833739&r1=833738&r2=833739&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 Sat Nov 7 19:53:16 2009 @@ -1296,7 +1296,7 @@ XmlSchemaIdentityConstraint constraint = typeClass.newInstance(); if (constraintEl.hasAttribute("name")) { - constraint.name = constraintEl.getAttribute("name"); + constraint.setName(constraintEl.getAttribute("name")); } if (constraintEl.hasAttribute("refer")) { @@ -1322,11 +1322,11 @@ selectorXPath.setAnnotation(annotation); } - constraint.selector = selectorXPath; + constraint.setSelector(selectorXPath); } else if (el.getLocalName().equals("field")) { XmlSchemaXPath fieldXPath = new XmlSchemaXPath(); fieldXPath.xpath = el.getAttribute("xpath"); - constraint.fields.add(fieldXPath); + constraint.getFields().add(fieldXPath); Element annotationEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "annotation"); @@ -1693,7 +1693,7 @@ if (extEl.hasAttribute("base")) { String name = extEl.getAttribute("base"); - ext.baseTypeName = getRefQName(name, extEl); + ext.setBaseTypeName(getRefQName(name, extEl)); } for (Element el = XDOMUtil.getFirstChildElementNS(extEl, @@ -1702,13 +1702,13 @@ if (el.getLocalName().equals("attribute")) { XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl); - ext.attributes.add(attr); + ext.getAttributes().add(attr); } else if (el.getLocalName().equals("attributeGroup")) { XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef( schema, el); - ext.attributes.add(attrGroup); + ext.getAttributes().add(attrGroup); } else if (el.getLocalName().equals("anyAttribute")) { - ext.anyAttribute = handleAnyAttribute(schema, el, schemaEl); + ext.setAnyAttribute(handleAnyAttribute(schema, el, schemaEl)); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation ann = handleAnnotation(el); ext.setAnnotation(ann); Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java?rev=833739&r1=833738&r2=833739&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java Sat Nov 7 19:53:16 2009 @@ -19,26 +19,30 @@ package org.apache.ws.commons.schema; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * Class for the identity constraints: key, keyref, and unique elements. */ public class XmlSchemaIdentityConstraint extends XmlSchemaAnnotated { - XmlSchemaObjectCollection fields; + private List<XmlSchemaXPath> fields; - String name; + private String name; - XmlSchemaXPath selector; + private XmlSchemaXPath selector; /** * Creates new XmlSchemaIdentityConstraint */ public XmlSchemaIdentityConstraint() { - fields = new XmlSchemaObjectCollection(); + fields = Collections.synchronizedList(new ArrayList<XmlSchemaXPath>()); } - public XmlSchemaObjectCollection getFields() { + public List<XmlSchemaXPath> getFields() { return fields; } @@ -58,4 +62,8 @@ this.selector = selector; } + void setFields(List<XmlSchemaXPath> fields) { + this.fields = fields; + } + } 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=833739&r1=833738&r2=833739&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 Sat Nov 7 19:53:16 2009 @@ -1328,23 +1328,23 @@ throw new XmlSchemaSerializerException("not valid identity " + "constraint"); } - if (constraintObj.name != null) { - constraint.setAttribute("name", constraintObj.name); + if (constraintObj.getName() != null) { + constraint.setAttribute("name", constraintObj.getName()); } if (constraintObj.getAnnotation() != null) { Element annotation = serializeAnnotation(doc, constraintObj.getAnnotation(), schema); constraint.appendChild(annotation); } - if (constraintObj.selector != null) { - Element selector = serializeSelector(doc, constraintObj.selector, schema); + if (constraintObj.getSelector() != null) { + Element selector = serializeSelector(doc, constraintObj.getSelector(), schema); constraint.appendChild(selector); } - XmlSchemaObjectCollection fieldColl = constraintObj.fields; + List<XmlSchemaXPath> fieldColl = constraintObj.getFields(); if (fieldColl != null) { - int fieldLength = fieldColl.getCount(); + int fieldLength = fieldColl.size(); for (int i = 0; i < fieldLength; i++) { - Element field = serializeField(doc, (XmlSchemaXPath)fieldColl.getItem(i), schema); + Element field = serializeField(doc, fieldColl.get(i), schema); constraint.appendChild(field); } } @@ -1812,8 +1812,8 @@ Element extension = createNewElement(doc, "extension", schema.getSchemaNamespacePrefix(), XmlSchema.SCHEMA_NS); - if (extensionObj.baseTypeName != null) { - String baseTypeName = resolveQName(extensionObj.baseTypeName, schema); + if (extensionObj.getBaseTypeName() != null) { + String baseTypeName = resolveQName(extensionObj.getBaseTypeName(), schema); extension.setAttribute("base", baseTypeName); } @@ -1827,10 +1827,10 @@ extension.appendChild(annotation); } - XmlSchemaObjectCollection attributes = extensionObj.attributes; - int attributeLength = attributes.getCount(); + List<XmlSchemaAnnotated> attributes = extensionObj.getAttributes(); + int attributeLength = attributes.size(); for (int i = 0; i < attributeLength; i++) { - XmlSchemaObject obj = attributes.getItem(i); + XmlSchemaObject obj = attributes.get(i); if (obj instanceof XmlSchemaAttribute) { Element attribute = serializeAttribute(doc, (XmlSchemaAttribute)obj, schema); @@ -1845,8 +1845,8 @@ /* * anyAttribute must comeafter any other attributes */ - if (extensionObj.anyAttribute != null) { - Element anyAttribute = serializeAnyAttribute(doc, extensionObj.anyAttribute, schema); + if (extensionObj.getAnyAttribute() != null) { + Element anyAttribute = serializeAnyAttribute(doc, extensionObj.getAnyAttribute(), schema); extension.appendChild(anyAttribute); } Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java?rev=833739&r1=833738&r2=833739&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java Sat Nov 7 19:53:16 2009 @@ -19,6 +19,10 @@ package org.apache.ws.commons.schema; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import javax.xml.namespace.QName; /** @@ -29,22 +33,22 @@ public class XmlSchemaSimpleContentExtension extends XmlSchemaContent { /* Allows an XmlSchemaAnyAttribute to be used for the attribute value. */ - XmlSchemaAnyAttribute anyAttribute; + private XmlSchemaAnyAttribute anyAttribute; /* * Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef. Collection of attributes for the simple * type. */ - XmlSchemaObjectCollection attributes; + private List<XmlSchemaAnnotated> attributes; /* Name of the built-in data type, simple type, or complex type. */ - QName baseTypeName; + private QName baseTypeName; /** * Creates new XmlSchemaSimpleContentExtension */ public XmlSchemaSimpleContentExtension() { - attributes = new XmlSchemaObjectCollection(); + attributes = Collections.synchronizedList(new ArrayList<XmlSchemaAnnotated>()); } @@ -52,7 +56,7 @@ return this.anyAttribute; } - public XmlSchemaObjectCollection getAttributes() { + public List<XmlSchemaAnnotated> getAttributes() { return this.attributes; } @@ -60,12 +64,16 @@ return this.baseTypeName; } - public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) { + void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) { this.anyAttribute = anyAttribute; } - public void setBaseTypeName(QName baseTypeName) { + void setBaseTypeName(QName baseTypeName) { this.baseTypeName = baseTypeName; } + void setAttributes(List<XmlSchemaAnnotated> attributes) { + this.attributes = attributes; + } + } Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ConstraintsTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ConstraintsTest.java?rev=833739&r1=833738&r2=833739&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ConstraintsTest.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ConstraintsTest.java Sat Nov 7 19:53:16 2009 @@ -33,7 +33,6 @@ import org.apache.ws.commons.schema.XmlSchemaIdentityConstraint; import org.apache.ws.commons.schema.XmlSchemaKey; import org.apache.ws.commons.schema.XmlSchemaKeyref; -import org.apache.ws.commons.schema.XmlSchemaObjectCollection; import org.apache.ws.commons.schema.XmlSchemaUnique; import org.apache.ws.commons.schema.XmlSchemaXPath; @@ -97,11 +96,11 @@ XmlSchemaXPath selectorXpath = key.getSelector(); assertEquals("tns:products/tns:productName", selectorXpath.getXPath()); - XmlSchemaObjectCollection fields = key.getFields(); - assertEquals(1, fields.getCount()); + List<XmlSchemaXPath> fields = key.getFields(); + assertEquals(1, fields.size()); XmlSchemaXPath fieldXpath = null; - for (int j = 0; j < fields.getCount(); j++) { - fieldXpath = (XmlSchemaXPath)fields.getItem(j); + for (int j = 0; j < fields.size(); j++) { + fieldXpath = fields.get(j); } assertNotNull(fieldXpath); assertEquals("@productId", fieldXpath.getXPath()); @@ -114,11 +113,11 @@ XmlSchemaXPath selectorXpath = keyref.getSelector(); assertEquals("tns:manufacturers/tns:location/tns:productName", selectorXpath.getXPath()); - XmlSchemaObjectCollection fields = keyref.getFields(); - assertEquals(1, fields.getCount()); + List<XmlSchemaXPath> fields = keyref.getFields(); + assertEquals(1, fields.size()); XmlSchemaXPath fieldXpath = null; - for (int j = 0; j < fields.getCount(); j++) { - fieldXpath = (XmlSchemaXPath)fields.getItem(j); + for (int j = 0; j < fields.size(); j++) { + fieldXpath = fields.get(j); } assertNotNull(fieldXpath); assertEquals("@productId", fieldXpath.getXPath()); @@ -129,11 +128,11 @@ XmlSchemaXPath selectorXpath = unique.getSelector(); assertEquals("tns:manufacturers/tns:location", selectorXpath.getXPath()); - XmlSchemaObjectCollection fields = unique.getFields(); - assertEquals(1, fields.getCount()); + List<XmlSchemaXPath> fields = unique.getFields(); + assertEquals(1, fields.size()); XmlSchemaXPath fieldXpath = null; - for (int j = 0; j < fields.getCount(); j++) { - fieldXpath = (XmlSchemaXPath)fields.getItem(j); + for (int j = 0; j < fields.size(); j++) { + fieldXpath = fields.get(j); } assertNotNull(fieldXpath); assertEquals("@district", fieldXpath.getXPath()); Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java?rev=833739&r1=833738&r2=833739&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java Sat Nov 7 19:53:16 2009 @@ -22,17 +22,18 @@ import java.io.FileInputStream; import java.io.InputStream; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.xml.namespace.QName; import javax.xml.transform.stream.StreamSource; import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaAnnotated; import org.apache.ws.commons.schema.XmlSchemaAttribute; import org.apache.ws.commons.schema.XmlSchemaCollection; import org.apache.ws.commons.schema.XmlSchemaComplexType; import org.apache.ws.commons.schema.XmlSchemaElement; -import org.apache.ws.commons.schema.XmlSchemaObjectCollection; import org.apache.ws.commons.schema.XmlSchemaSimpleContent; import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension; @@ -77,15 +78,15 @@ assertNotNull(xssce); assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"), xssce.getBaseTypeName()); - XmlSchemaObjectCollection xsoc = xssce.getAttributes(); - assertEquals(3, xsoc.getCount()); + List<XmlSchemaAnnotated> xsoc = xssce.getAttributes(); + assertEquals(3, xsoc.size()); Set<String> s = new HashSet<String>(); s.add("units"); s.add("id"); s.add("desc"); - for (int i = 0; i < xsoc.getCount(); i++) { - XmlSchemaAttribute xsa = (XmlSchemaAttribute)xsoc.getItem(i); + for (int i = 0; i < xsoc.size(); i++) { + XmlSchemaAttribute xsa = (XmlSchemaAttribute)xsoc.get(i); String name = xsa.getName(); if ("units".equals(name)) { assertEquals(new QName("http://soapinterop.org/types", "units"), xsa.getQName());