Author: bimargulies Date: Sat Nov 7 20:06:09 2009 New Revision: 833743 URL: http://svn.apache.org/viewvc?rev=833743&view=rev Log: XmlSchemaComplexType modernization. Add class to capture common use of Attribute and AttributeGroupRef.
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeOrGroupRef.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/XmlSchemaAttribute.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/XmlSchemaComplexType.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/AttributeGroupTest.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeRefTest.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=833743&r1=833742&r2=833743&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 20:06:09 2009 @@ -308,15 +308,15 @@ // el.getPrefix(); // if(elPrefix.equals(schema.schema_ns_prefix)) { if (el.getLocalName().equals("sequence")) { - ct.particle = handleSequence(schema, el, schemaEl); + ct.setParticle(handleSequence(schema, el, schemaEl)); } else if (el.getLocalName().equals("choice")) { - ct.particle = handleChoice(schema, el, schemaEl); + ct.setParticle(handleChoice(schema, el, schemaEl)); } else if (el.getLocalName().equals("all")) { - ct.particle = handleAll(schema, el, schemaEl); + ct.setParticle(handleAll(schema, el, schemaEl)); } else if (el.getLocalName().equals("attribute")) { - ct.attributes.add(handleAttribute(schema, el, schemaEl)); + ct.getAttributes().add(handleAttribute(schema, el, schemaEl)); } else if (el.getLocalName().equals("attributeGroup")) { - ct.attributes.add(handleAttributeGroupRef(schema, el)); + ct.getAttributes().add(handleAttributeGroupRef(schema, el)); } else if (el.getLocalName().equals("group")) { XmlSchemaGroupRef group = handleGroupRef(schema, el, schemaEl); if (group.getParticle() == null) { @@ -325,9 +325,9 @@ ct.setParticle(group.getParticle()); } } else if (el.getLocalName().equals("simpleContent")) { - ct.contentModel = handleSimpleContent(schema, el, schemaEl); + ct.setContentModel(handleSimpleContent(schema, el, schemaEl)); } else if (el.getLocalName().equals("complexContent")) { - ct.contentModel = handleComplexContent(schema, el, schemaEl); + ct.setContentModel(handleComplexContent(schema, el, schemaEl)); } else if (el.getLocalName().equals("annotation")) { ct.setAnnotation(handleAnnotation(el)); } else if (el.getLocalName().equals("anyAttribute")) { 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=833743&r1=833742&r2=833743&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 Sat Nov 7 20:06:09 2009 @@ -30,7 +30,7 @@ * * ref= attributes are in the parent items collection, not in the map of named items. */ -public class XmlSchemaAttribute extends XmlSchemaAnnotated implements XmlSchemaNamedWithForm, +public class XmlSchemaAttribute extends XmlSchemaAttributeOrGroupRef implements XmlSchemaNamedWithForm, XmlSchemaAttributeGroupMember { private String defaultValue; 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=833743&r1=833742&r2=833743&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 Sat Nov 7 20:06:09 2009 @@ -26,7 +26,7 @@ * Represents the World Wide Web Consortium (W3C) attributeGroup * element with the ref attribute. */ -public class XmlSchemaAttributeGroupRef extends XmlSchemaAnnotated +public class XmlSchemaAttributeGroupRef extends XmlSchemaAttributeOrGroupRef implements XmlSchemaAttributeGroupMember { private XmlSchemaRef<XmlSchemaAttributeGroup> ref; Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeOrGroupRef.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeOrGroupRef.java?rev=833743&view=auto ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeOrGroupRef.java (added) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeOrGroupRef.java Sat Nov 7 20:06:09 2009 @@ -0,0 +1,29 @@ +/** + * 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; + +/** + * Several objects in the model allow either an XmlSchemaAttribute or + * an XmlSchemaAttributeGroupRef. This type is here only allow + * tight type specifications for them. + */ +public class XmlSchemaAttributeOrGroupRef + extends XmlSchemaAnnotated { +} Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeOrGroupRef.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java?rev=833743&r1=833742&r2=833743&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java Sat Nov 7 20:06:09 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; /** @@ -27,25 +31,25 @@ */ public class XmlSchemaComplexType extends XmlSchemaType { - XmlSchemaAnyAttribute anyAttribute; - XmlSchemaAnyAttribute attributeWildcard; - XmlSchemaObjectCollection attributes; - XmlSchemaObjectTable attributeUses; - XmlSchemaDerivationMethod block; - XmlSchemaDerivationMethod blockResolved; - XmlSchemaContentModel contentModel; - XmlSchemaContentType contentType; - XmlSchemaParticle particleType; - XmlSchemaParticle particle; - boolean isAbstract; - boolean isMixed; + private XmlSchemaAnyAttribute anyAttribute; + private XmlSchemaAnyAttribute attributeWildcard; + private List<XmlSchemaAttributeOrGroupRef> attributes; + private XmlSchemaObjectTable attributeUses; + private XmlSchemaDerivationMethod block; + private XmlSchemaDerivationMethod blockResolved; + private XmlSchemaContentModel contentModel; + private XmlSchemaContentType contentType; + private XmlSchemaParticle particleType; + private XmlSchemaParticle particle; + private boolean isAbstract; + private boolean isMixed; /** * Creates new XmlSchemaComplexType */ public XmlSchemaComplexType(XmlSchema schema, boolean topLevel) { super(schema, topLevel); - attributes = new XmlSchemaObjectCollection(); + attributes = Collections.synchronizedList(new ArrayList<XmlSchemaAttributeOrGroupRef>()); block = XmlSchemaDerivationMethod.NONE; isAbstract = false; isMixed = false; @@ -59,7 +63,7 @@ this.anyAttribute = anyAttribute; } - public XmlSchemaObjectCollection getAttributes() { + public List<XmlSchemaAttributeOrGroupRef> getAttributes() { return attributes; } @@ -147,4 +151,28 @@ return ext.getBaseTypeName(); } + void setAttributeWildcard(XmlSchemaAnyAttribute attributeWildcard) { + this.attributeWildcard = attributeWildcard; + } + + void setAttributes(List<XmlSchemaAttributeOrGroupRef> attributes) { + this.attributes = attributes; + } + + void setAttributeUses(XmlSchemaObjectTable attributeUses) { + this.attributeUses = attributeUses; + } + + void setBlockResolved(XmlSchemaDerivationMethod blockResolved) { + this.blockResolved = blockResolved; + } + + void setParticleType(XmlSchemaParticle particleType) { + this.particleType = particleType; + } + + XmlSchemaParticle getParticleType() { + return particleType; + } + } 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=833743&r1=833742&r2=833743&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 20:06:09 2009 @@ -860,10 +860,10 @@ */ } - if (complexTypeObj.isMixed) { + if (complexTypeObj.isMixed()) { serializedComplexType.setAttribute("mixed", "true"); } - if (complexTypeObj.isAbstract) { + if (complexTypeObj.isAbstract()) { serializedComplexType.setAttribute("abstract", "true"); } if (complexTypeObj.getId() != null) { @@ -875,38 +875,40 @@ serializedComplexType.appendChild(annotationEl); } - if (complexTypeObj.contentModel instanceof XmlSchemaSimpleContent) { + if (complexTypeObj.getContentModel() instanceof XmlSchemaSimpleContent) { Element simpleContent = serializeSimpleContent( doc, (XmlSchemaSimpleContent) - complexTypeObj.contentModel, + complexTypeObj.getContentModel(), schema); serializedComplexType.appendChild(simpleContent); - } else if (complexTypeObj.contentModel instanceof XmlSchemaComplexContent) { + } else if (complexTypeObj.getContentModel() instanceof XmlSchemaComplexContent) { Element complexContent = serializeComplexContent( doc, (XmlSchemaComplexContent) - complexTypeObj.contentModel, + complexTypeObj.getContentModel(), schema); serializedComplexType.appendChild(complexContent); } - if (complexTypeObj.particle instanceof XmlSchemaSequence) { - Element sequence = serializeSequence(doc, (XmlSchemaSequence)complexTypeObj.particle, schema); + if (complexTypeObj.getParticle() instanceof XmlSchemaSequence) { + Element sequence = serializeSequence(doc, + (XmlSchemaSequence)complexTypeObj.getParticle(), schema); serializedComplexType.appendChild(sequence); - } else if (complexTypeObj.particle instanceof XmlSchemaChoice) { - Element choice = serializeChoice(doc, (XmlSchemaChoice)complexTypeObj.particle, schema); + } else if (complexTypeObj.getParticle() instanceof XmlSchemaChoice) { + Element choice = serializeChoice(doc, (XmlSchemaChoice)complexTypeObj.getParticle(), schema); serializedComplexType.appendChild(choice); - } else if (complexTypeObj.particle instanceof XmlSchemaAll) { - Element all = serializeAll(doc, (XmlSchemaAll)complexTypeObj.particle, schema); + } else if (complexTypeObj.getParticle() instanceof XmlSchemaAll) { + Element all = serializeAll(doc, (XmlSchemaAll)complexTypeObj.getParticle(), schema); serializedComplexType.appendChild(all); - } else if (complexTypeObj.particle instanceof XmlSchemaGroupRef) { - Element group = serializeGroupRef(doc, (XmlSchemaGroupRef)complexTypeObj.particle, schema); + } else if (complexTypeObj.getParticle() instanceof XmlSchemaGroupRef) { + Element group = serializeGroupRef(doc, (XmlSchemaGroupRef)complexTypeObj.getParticle(), schema); serializedComplexType.appendChild(group); } - if (complexTypeObj.block != null && complexTypeObj.block != XmlSchemaDerivationMethod.NONE) { + if (complexTypeObj.getBlock() != null + && complexTypeObj.getBlock() != XmlSchemaDerivationMethod.NONE) { serializedComplexType.setAttribute("block", complexTypeObj.toString()); } @@ -915,8 +917,8 @@ serializedComplexType.setAttribute("final", complexTypeObj.getFinalDerivation().toString()); } - XmlSchemaObjectCollection attrColl = complexTypeObj.attributes; - if (attrColl.getCount() > 0) { + List<XmlSchemaAttributeOrGroupRef> attrColl = complexTypeObj.getAttributes(); + if (attrColl.size() > 0) { setupAttr(doc, attrColl, schema, serializedComplexType); } @@ -1827,7 +1829,7 @@ extension.appendChild(annotation); } - List<XmlSchemaAnnotated> attributes = extensionObj.getAttributes(); + List<XmlSchemaAttributeOrGroupRef> attributes = extensionObj.getAttributes(); int attributeLength = attributes.size(); for (int i = 0; i < attributeLength; i++) { XmlSchemaObject obj = attributes.get(i); @@ -2146,11 +2148,12 @@ // for each collection if it is an attribute serialize attribute and // append that child to container element. - void setupAttr(Document doc, XmlSchemaObjectCollection collectionObj, XmlSchema schema, Element container) + void setupAttr(Document doc, List<XmlSchemaAttributeOrGroupRef> attrColl, + XmlSchema schema, Element container) throws XmlSchemaSerializerException { - int collectionLength = collectionObj.getCount(); + int collectionLength = attrColl.size(); for (int i = 0; i < collectionLength; i++) { - XmlSchemaObject obj = collectionObj.getItem(i); + XmlSchemaAttributeOrGroupRef obj = attrColl.get(i); if (obj instanceof XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; Element attrEl = serializeAttribute(doc, attr, schema); 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=833743&r1=833742&r2=833743&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 20:06:09 2009 @@ -39,7 +39,7 @@ * Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef. Collection of attributes for the simple * type. */ - private List<XmlSchemaAnnotated> attributes; + private List<XmlSchemaAttributeOrGroupRef> attributes; /* Name of the built-in data type, simple type, or complex type. */ private QName baseTypeName; @@ -48,7 +48,7 @@ * Creates new XmlSchemaSimpleContentExtension */ public XmlSchemaSimpleContentExtension() { - attributes = Collections.synchronizedList(new ArrayList<XmlSchemaAnnotated>()); + attributes = Collections.synchronizedList(new ArrayList<XmlSchemaAttributeOrGroupRef>()); } @@ -56,7 +56,7 @@ return this.anyAttribute; } - public List<XmlSchemaAnnotated> getAttributes() { + public List<XmlSchemaAttributeOrGroupRef> getAttributes() { return this.attributes; } @@ -72,7 +72,7 @@ this.baseTypeName = baseTypeName; } - void setAttributes(List<XmlSchemaAnnotated> attributes) { + void setAttributes(List<XmlSchemaAttributeOrGroupRef> attributes) { this.attributes = attributes; } 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=833743&r1=833742&r2=833743&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 Sat Nov 7 20:06:09 2009 @@ -33,10 +33,10 @@ import org.apache.ws.commons.schema.XmlSchemaAttributeGroup; import org.apache.ws.commons.schema.XmlSchemaAttributeGroupMember; import org.apache.ws.commons.schema.XmlSchemaAttributeGroupRef; +import org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef; 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.junit.Assert; import org.junit.Test; @@ -90,8 +90,8 @@ XmlSchemaComplexType t = (XmlSchemaComplexType)elem.getSchemaType(); assertNotNull(t); - XmlSchemaObjectCollection c = t.getAttributes(); - for (Iterator i = c.getIterator(); i.hasNext();) { + List<XmlSchemaAttributeOrGroupRef> c = t.getAttributes(); + for (Iterator<XmlSchemaAttributeOrGroupRef> i = c.iterator(); i.hasNext();) { XmlSchemaAttributeGroupRef agrn = (XmlSchemaAttributeGroupRef)i.next(); assertEquals(new QName("http://soapinterop.org/types", "department"), agrn.getRef() .getTargetQName()); Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeRefTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeRefTest.java?rev=833743&r1=833742&r2=833743&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeRefTest.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeRefTest.java Sat Nov 7 20:06:09 2009 @@ -61,7 +61,7 @@ XmlSchemaComplexType typeByName = (XmlSchemaComplexType)s.getTypeByName(typeQName); assertNotNull(typeByName); - XmlSchemaAttribute item = (XmlSchemaAttribute)typeByName.getAttributes().getItem(0); + XmlSchemaAttribute item = (XmlSchemaAttribute)typeByName.getAttributes().get(0); QName qName = item.getRef().getTargetQName(); assertNotNull(qName); 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=833743&r1=833742&r2=833743&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 20:06:09 2009 @@ -29,8 +29,8 @@ 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.XmlSchemaAttributeOrGroupRef; import org.apache.ws.commons.schema.XmlSchemaCollection; import org.apache.ws.commons.schema.XmlSchemaComplexType; import org.apache.ws.commons.schema.XmlSchemaElement; @@ -78,7 +78,7 @@ assertNotNull(xssce); assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"), xssce.getBaseTypeName()); - List<XmlSchemaAnnotated> xsoc = xssce.getAttributes(); + List<XmlSchemaAttributeOrGroupRef> xsoc = xssce.getAttributes(); assertEquals(3, xsoc.size()); Set<String> s = new HashSet<String>();