org.ws4d.java.schema
Class ComplexType

java.lang.Object
  extended by org.ws4d.java.schema.NamedObject
      extended by org.ws4d.java.schema.Type
          extended by org.ws4d.java.schema.ComplexType
All Implemented Interfaces:
SchemaConstants, Any
Direct Known Subclasses:
ComplexContent

public class ComplexType
extends Type

This class allows object representation of XML Schema complex types.

Those types are part of the XML Schema definition and are used inside WSDL documents to describe the content of a message. It is possible to define XML Schema structures with the classes Schema, Element, Attribute, SimpleType, ComplexType, Group and AttributeGroup. This is at least necessary to invoke SOAP operations (like used in DPWS).
A complex type consists of a qualified name and the description of the content structure.

XML Schema

XML Schema describes the structure of the content for a XML instance document. Each element is linked to a specific data type. XML Schema comes with built-in primitive data types like string, boolean, decimal and derived data types like byte, int, token and positiveInteger. It is also possible to define one's own derived data types. An XML Schema could looks like this:

 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org"> 
    <xs:complexType name="personType">
       <xs:sequence>
          <xs:element name="firstname" type="xs:string" />
          <xs:element name="lastname" type="xs:string" />
          <xs:element name="age" type="xs:int" />
       </xs:sequence>
    </xs:complexType>
    <xs:element name="person" type="personType" />
 </xs:schema>
 

The XML Schema above defines a derived data type called personType which contains inner-elements. The derived data type is used by the element person. This XML schema allows the creation of the following XML instance document:

 <?xml version="1.0"?>
 <person>
    <firstname>John</firstname>
    <lastname>Doe</lastname>
    <age>66</age>
 </person>
 

You can learn more about XML Schema at http://www.w3.org/XML/Schema

Framework

If you want to create the complex type described above, it is necessary to create the derived data type too and use the primitive data type string. If you can access predefined primitive data types with the SchemaUtil.getSchemaType(String) method.
The created code should look like this:

 // get primitive data types
 Type xsString = SchemaUtil.getSchemaType("string");
 Type xsInt = SchemaUtil.getSchemaType("int");
 
 // create inner elements for personType
 Element firstname = new Element(new QName("firstname", "http://www.example.org"), xsString);
 Element lastname = new Element(new QName("lastname", "http://www.example.org"), xsString);
 Element age = new Element(new QName("age", "http://www.example.org"), xsInt);
 
 // create personType and add inner elements
 ComplexType personType = new ComplexType(new QName("personType", "http://www.example.org"), ComplexType.CONTAINER_SEQUENCE);
 personType.addElement(firstname);
 personType.addElement(lastname);
 personType.addElement(age);
 
 // create element
 Element person = new Element(new QName("person", "http://www.example.org"), personType);
 

Details

The following examples will show how to use the complex type to create different XML Schema structures.

See Also:
CONTAINER_ALL, CONTAINER_SEQUENCE, CONTAINER_CHOICE

Field Summary
static int CONTAINER_ALL
          This is the constant field value for the all model group.
static int CONTAINER_CHOICE
          This is the constant field value for the choice model group.
static int CONTAINER_SEQUENCE
          This is the constant field value for the sequence model group.
 
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
 
Constructor Summary
ComplexType(int containerType)
          This constructor must be used when declaring inline types, which must not have a name.
ComplexType(QName name, int containerType)
          This constructor must be used when declaring top-level types, which have a non-empty name.
ComplexType(java.lang.String name, java.lang.String namespace, int containerType)
          This constructor must be used when declaring top-level types, which have a non-empty name.
 
Method Summary
 void addElement(Element e)
          Adds an element to the enclosed container.
 Iterator elements()
          Returns an iterator of elements from the enclosed container.
 ElementContainer getContainer()
          Returns the enclosed container for this complex type.
 int getContainerMaxOccurs()
          Returns the maximum occurrence for the enclosed container.
 int getContainerMinOccurs()
          Returns the minimum occurrence for the enclosed container.
 Element getElementByName(QName name)
          Returns an element with matching name from the container.
 Element getElementByName(java.lang.String name)
          Returns an element with matching name from the container.
 int getElementCount()
          Returns the element count in the enclosed container.
 int getSchemaIdentifier()
           
 boolean hasElements()
          Returns true if the enclosed container has element definitions, false otherwise.
 void setContainerMaxOccurs(int max)
          Sets the maximum occurrence for the enclosed container.
 void setContainerMinOccurs(int min)
          Sets the minimum occurrence for the enclosed container.
 
Methods inherited from class org.ws4d.java.schema.Type
addAttribute, addAttributeGroup, allAttributes, allowAnyAttribute, attributeGroups, attributes, denyAnyAttribute, getAttribute, getAttributeCount, getAttributeGroup, getAttributeGroupCount, getKownSubtypes, getTypeCount, hasAnyAttribute, hasAttributeGroups, hasAttributes, isComplexType
 
Methods inherited from class org.ws4d.java.schema.NamedObject
checkNamespace, equals, getName, getParentSchema, hashCode, isAbstract, setAbstract, setName, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTAINER_ALL

public static final int CONTAINER_ALL
This is the constant field value for the all model group.

Should be used to define complex types without relevant element order.

See Also:
Constant Field Values

CONTAINER_SEQUENCE

public static final int CONTAINER_SEQUENCE
This is the constant field value for the sequence model group.

Should be used to define complex types with relevant element order.

See Also:
Constant Field Values

CONTAINER_CHOICE

public static final int CONTAINER_CHOICE
This is the constant field value for the choice model group.

Should be used to define complex types where one element must be chosen.

See Also:
Constant Field Values
Constructor Detail

ComplexType

public ComplexType(java.lang.String name,
                   java.lang.String namespace,
                   int containerType)
This constructor must be used when declaring top-level types, which have a non-empty name.

Parameters:
name - the name of the type.
namespace - the namespace.
containerType - the type of the enclosed container.
See Also:
CONTAINER_ALL, CONTAINER_SEQUENCE, CONTAINER_CHOICE

ComplexType

public ComplexType(int containerType)
This constructor must be used when declaring inline types, which must not have a name.

Parameters:
containerType - the type of the enclosed container.
See Also:
CONTAINER_ALL, CONTAINER_SEQUENCE, CONTAINER_CHOICE

ComplexType

public ComplexType(QName name,
                   int containerType)
This constructor must be used when declaring top-level types, which have a non-empty name.

Parameters:
name - the qualified name of the type
containerType - the type of the enclosed container.
See Also:
CONTAINER_ALL, CONTAINER_SEQUENCE, CONTAINER_CHOICE
Method Detail

getSchemaIdentifier

public int getSchemaIdentifier()

getContainerMinOccurs

public int getContainerMinOccurs()
Returns the minimum occurrence for the enclosed container.

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

Returns:
the minimum occurrence for the enclosed container.

getContainerMaxOccurs

public int getContainerMaxOccurs()
Returns the maximum occurrence for the enclosed container.

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

Returns:
the maximum occurrence for the enclosed container.

setContainerMinOccurs

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

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

Parameters:
min - the minimum occurrence for the enclosed container.

setContainerMaxOccurs

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

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

Parameters:
max - the maximum occurrence for the enclosed container.

hasElements

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

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

addElement

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

Parameters:
e - the element to add.

getElementByName

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

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.

getElementCount

public int getElementCount()
Returns the element count in the enclosed container.

Returns:
the element count.

elements

public Iterator elements()
Returns an iterator of elements from the enclosed container.

Returns:
the elements.

getContainer

public ElementContainer getContainer()
Returns the enclosed container for this complex type.

Returns:
the enclosed container.
See Also:
SequenceContainer, AllContainer, ChoiceContainer