org.ws4d.java.schema
Class ElementContainer

java.lang.Object
  extended by org.ws4d.java.schema.ElementContainer
All Implemented Interfaces:
SchemaConstants, Any
Direct Known Subclasses:
AllContainer, ChoiceContainer, SequenceContainer

public abstract class ElementContainer
extends java.lang.Object
implements Any

This class represents the model group part of XML Schema.

http://www.w3.org/ TR/xmlschema11-1/#Model_Groups

It allows to add elements, groups and other containers.

XML Schema

It is possible to create nested container structures like this:

 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org">
    <element name="nested" type="nestedType" />
    <xs:complexType name="nestedType">
       <xs:all>
          <xs:element name="a" type="xs:string" />
          <xs:element name="b" type="xs:string" />
          <xs:sequence>
              <xs:element name="c" type="xs:string" />
              <xs:element name="d" type="xs:string" />
              <xs:choice>
                 <xs:element name="e" type="xs:string" />
                 <xs:element name="f" type="xs:string" />
              </xs:choice>
          </xs:sequence>
       </xs:all>
    </xs:complexType>
 </xs:schema>
 

Framework

 // get primitive data types
 Type xsString = SchemaUtil.getSchemaType("string");
 
 // create inner elements
 Element a = new Element(new QName("a", "http://www.example.org"), xsString);
 Element b = new Element(new QName("b", "http://www.example.org"), xsString);
 Element c = new Element(new QName("c", "http://www.example.org"), xsString);
 Element d = new Element(new QName("d", "http://www.example.org"), xsString);
 Element e = new Element(new QName("f", "http://www.example.org"), xsString);
 
 // create the nested structure (bottom-up)
 ChoiceContainer choice = new ChoiceContainer();
 choice.addElement(e);
 choice.addElement(f);
 
 SequenceContainer sequence = new SequenceContainer();
 sequence.add(c);
 sequence.add(d);
 sequence.addContainer(choice);
 
 // create the complex type
 ComplexType nestedType = new ComplexType(new QName("nestedType", "http://www.example.org"), ComplexType.CONTAINER_ALL);
 nestedType.addElement(a);
 nestedType.addElement(b);
 
 // get the enclosed container and add the other container
 AllContainer all = nestedType.getContainer();
 all.addContainer(sequence);
 
 


Field Summary
 
Fields inherited from interface org.ws4d.java.schema.Any
ATTRIBUTE_NAME, ATTRIBUTE_TYPE, ATTRIBUTE_VALUE_FALSE, ATTRIBUTE_VALUE_TRUE, TAG_ANY, TAG_ANYATTRIBUTE
 
Fields inherited from interface org.ws4d.java.constants.SchemaConstants
ATTRIBUTE_ABSTRACT, ATTRIBUTE_DEFAULT, ATTRIBUTE_FIXED, ATTRIBUTE_USE, ATTRIBUTE_XSINIL, ATTRIBUTE_XSITYPE, DOCUMENTATION_LANG, ELEMENT_ALL, ELEMENT_CHOICE, ELEMENT_DEFAULT, ELEMENT_FIXED, ELEMENT_MAXOCCURS, ELEMENT_MINOCCURS, ELEMENT_NILLABLE, ELEMENT_PARENT, ELEMENT_RESTRICTIONS, ELEMENT_SEQUENCE, ELEMENT_SUBSTITUTIONS, ELEMENT_UNIONS, FACET_ENUMERATION, FACET_FRACTIONDIGITS, FACET_LENGTH, FACET_MAXEXCLUSIVE, FACET_MAXINCLUSIVE, FACET_MAXLENGTH, FACET_MINEXCLUSIVE, FACET_MININCLUSIVE, FACET_MINLENGTH, FACET_PATTERN, FACET_TOTALDIGITS, FACET_WHITESPACE, LIST_ITEMTYPE, MAXOCCURS_UNBOUNDED, SCHEMA_ANNOTATION, SCHEMA_ANY, SCHEMA_ANYATTRIBUTE, SCHEMA_APP_INFO, SCHEMA_ATTRIBUTE, SCHEMA_ATTRIBUTEFORMDEFAULT, SCHEMA_ATTRIBUTEGROUP, SCHEMA_BASE, SCHEMA_COMPLEXCONTENT, SCHEMA_COMPLEXTYPE, SCHEMA_DOCUMENTATION, SCHEMA_ELEMENT, SCHEMA_ELEMENTFORMDEFAULT, SCHEMA_EXTENSION, SCHEMA_FACETS, SCHEMA_FORM, SCHEMA_GROUP, SCHEMA_IMPORT, SCHEMA_INCLUDE, SCHEMA_ITEMLIST, SCHEMA_ITEMTYPE, SCHEMA_LIST, SCHEMA_LOCATION, SCHEMA_MEMBERTYPES, SCHEMA_NAME, SCHEMA_NAMESPACE, SCHEMA_NONAMESPACESCHEMALOCATION, SCHEMA_NOTATION, SCHEMA_PUBLIC, SCHEMA_QUALIFIED, SCHEMA_REDEFINE, SCHEMA_REF, SCHEMA_RESTRICTION, SCHEMA_SCHEMA, SCHEMA_SIMPLECONTENT, SCHEMA_SIMPLETYPE, SCHEMA_STYPES, SCHEMA_SUBSTITUTIONGROUP, SCHEMA_SYSTEM, SCHEMA_TARGETNAMESPACE, SCHEMA_TYPE, SCHEMA_UNION, SCHEMA_UNQUALIFIED, SCHEMA_VALUE, SCHEMA_VALUEVECTOR, USE_OPTIONAL, USE_PROHIBITED, USE_REQUIRED, XMLSCHEMA_NAMESPACE, XMLSCHEMA_PREFIX, XSD_ALLMODEL, XSD_ANYATTRIBUTE, XSD_ANYELEMENT, XSD_ATTRIBUTE, XSD_ATTRIBUTEGROUP, XSD_CHOICEMODEL, XSD_COMPLEXTYPE, XSD_ELEMENT, XSD_EXTENDEDCOMPLEXCONTENT, XSD_EXTENDEDSIMPLECONTENT, XSD_GROUP, XSD_NOTATION, XSD_RESTRICTEDCOMPLEXCONTENT, XSD_RESTRICTEDSIMPLECONTENT, XSD_RESTRICTEDSIMPLETYPE, XSD_SCHEMA, XSD_SEQUENCEMODEL, XSD_SIMPLETYPE, XSI_NAMESPACE
 
Method Summary
 void addAnyElement(AnyElement e)
          Adds an any element to the container.
 void addContainer(ElementContainer container)
          Adds another container to this container.
 void addElement(Element e)
          Adds an element to the container.
 void addGroup(Group g)
          Adds a group of elements to the container.
 Iterator all()
           
 Iterator allElements()
          Returns an iterator of elements from this container and all elements from nested containers.
 Iterator containers()
          Returns an iterator of containers inside this container.
 Iterator getContainerContent()
           
abstract  int getContainerType()
          Returns the information about the type of this container.
 Element getElementByName(QName name)
          Returns an element from the container with matching name.
 Element getElementByName(java.lang.String name)
          Returns an element with matching name from the container.
 int getElementCount()
          Returns the element count of the enclosed containers.
 Element getFirstElement()
           
 int getInnerContainerCount()
          Returns the number of containers inside this container.
 Element getLocalElementByName(QName name)
          Returns a local element (i.e. one that is directly contained by this container) from the container with matching name.
 Element getLocalElementByName(java.lang.String name)
          Returns a local element (i.e. one that is directly contained by this container) with matching name from the container.
 int getMaxOccurs()
          Returns the maximum occurrence for the container.
 int getMinOccurs()
          Returns the minimum occurrence for the container.
 boolean hasElements()
          Returns true if the container has element definitions, false otherwise.
 Iterator listAll()
           
 void mergeContainer(ElementContainer container)
          Merge one container into this container.
 Iterator ownElements()
          Returns an iterator of elements from this container.
 void setMaxOccurs(int max)
          Sets the maximum occurrence for the container.
 void setMinOccurs(int min)
          Sets the minimum occurrence for the container.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ws4d.java.schema.Any
getSchemaIdentifier
 

Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getMinOccurs

public int getMinOccurs()
Returns the minimum occurrence for the container.

The "minOccurs" attribute in XML Schema describes the minimum occurrence of the container inside the created XML instance document.

Returns:
the minimum occurrence for the container.

getMaxOccurs

public int getMaxOccurs()
Returns the maximum occurrence for the container.

The "maxOccurs" attribute in XML Schema describes the maximum occurrence of the container inside the created XML instance document.

Returns:
the maximum occurrence for the container.

setMinOccurs

public void setMinOccurs(int min)
Sets the minimum occurrence for the container.

The "minOccurs" attribute in XML Schema describes the minimum occurrence of the container inside the created XML instance document.

Parameters:
min - the minimum occurrence for the container.

setMaxOccurs

public void setMaxOccurs(int max)
Sets the maximum occurrence for the container.

The "maxOccurs" attribute in XML Schema describes the maximum occurrence of the container inside the created XML instance document.

Parameters:
max - the maximum occurrence for the container.

mergeContainer

public void mergeContainer(ElementContainer container)
Merge one container into this container.

Parameters:
container - the container which should be merged with this one.

getInnerContainerCount

public int getInnerContainerCount()
Returns the number of containers inside this container.

Returns:
the number of containers inside this container.

addContainer

public void addContainer(ElementContainer container)
Adds another container to this container.

Parameters:
container - the container to add.

addElement

public void addElement(Element e)
Adds an element to the container.

Parameters:
e - the element to add.

addAnyElement

public void addAnyElement(AnyElement e)
Adds an any element to the container. This allows to add elements from other schemas to the XML instance document.

Parameters:
e - the element to add.

addGroup

public void addGroup(Group g)
Adds a group of elements to the container.

Parameters:
g - the group to add.

getElementCount

public int getElementCount()
Returns the element count of the enclosed containers.

Returns:
the element count.

getElementByName

public Element getElementByName(QName name)
Returns an element from the container with matching name.

Parameters:
name - the qualified name of the element which should be returned.
Returns:
the element.

getLocalElementByName

public Element getLocalElementByName(QName name)
Returns a local element (i.e. one that is directly contained by this container) from the container with matching name.

Parameters:
name - the qualified name of the element which should be returned.
Returns:
the element.

getElementByName

public Element getElementByName(java.lang.String name)
Returns an element with matching name from the container.

This method will NOT verify the namespace.

Parameters:
name - the name of the element which should be returned.
Returns:
the element.

getLocalElementByName

public Element getLocalElementByName(java.lang.String name)
Returns a local element (i.e. one that is directly contained by this container) with matching name from the container.

This method will NOT verify the namespace.

Parameters:
name - the name of the element which should be returned.
Returns:
the element.

listAll

public Iterator listAll()

containers

public Iterator containers()
Returns an iterator of containers inside this container.

Returns:
the containers.

all

public Iterator all()

getFirstElement

public Element getFirstElement()

ownElements

public Iterator ownElements()
Returns an iterator of elements from this container.

Returns:
the elements.

allElements

public Iterator allElements()
Returns an iterator of elements from this container and all elements from nested containers.

Returns:
the elements.

getContainerContent

public Iterator getContainerContent()

hasElements

public boolean hasElements()
Returns true if the container has element definitions, false otherwise.

Returns:
true if the container has element definitions, false otherwise.

getContainerType

public abstract int getContainerType()
Returns the information about the type of this container. (xs:all, xs:sequence or xs:choice).

Returns:
the type of this container.