public class ComplexType extends Type
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 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
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(QName) 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);
The following examples will show how to use the complex type to create different XML Schema structures.
Different model groups allow the assignment of an order to the content structure. The content order can be all, sequence or choice. The all model group does not restrict the order of the content. The sequence model group requires the correct order of the content. The choice model group allows only one element to be chosen for content.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org">
<element name="all" type="allType" />
<element name="sequence" type="sequenceType" />
<element name="choice" type="choiceType" />
<xs:complexType name="allType">
<xs:all>
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />
</xs:all>
</xs:complexType>
<xs:complexType name="sequenceType">
<xs:sequence>
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="choiceType">
<xs:choice>
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />
</xs:choice>
</xs:complexType>
</xs:schema>
The XML Schema listed above allows three different elements to be used as root element for an XML
instance. In case of the element "all", the inner elements do not need any order. The order can be: a, b or b,
a.
<?xml version="1.0"?>
<all>
<a>some text</a>
<b>more text</b>
</all>
<?xml version="1.0"?>
<all>
<b>more text</b>
<a>some text</a>
</all>
In case of the element "sequence", the inner elements can only be used in the given order. The order can be: a,
b
<?xml version="1.0"?>
<sequence>
<a>some text</a>
<b>more text</b>
</sequence>
In case of the element "choice", one element must be chosen from the given elements. The elements can be: a or b, not
both.
<?xml version="1.0"?>
<choice>
<a>some text</a>
</choice>
<?xml version="1.0"?>
<choice>
<b>more text</b>
</choice>
The framework supports the all, sequence and choice model groups.
// get primitive data types
Type xsString = SchemaUtil.getSchemaType("string");
// create inner elements for the complex types
Element a = new Element(new QName("a", "http://www.example.org"), xsString);
Element b = new Element(new QName("b", "http://www.example.org"), xsString);
// create some complex type (all) and add inner elements
ComplexType allType = new ComplexType(new QName("allType", "http://www.example.org"),
ComplexType.CONTAINER_ALL);
allType.addElement(a);
allType.addElement(b);
// create some complex type (sequence) and add inner elements
ComplexType sequenceType = new ComplexType(new QName("sequenceType", "http://www.example.org"),
ComplexType.CONTAINER_SEQUENCE);
sequenceType.addElement(a);
sequenceType.addElement(b);
// create some complex type (choice) and add inner elements
ComplexType choiceType = new ComplexType(new QName("choiceType", "http://www.example.org"),
ComplexType.CONTAINER_CHOICE);
choiceType.addElement(a);
choiceType.addElement(b);
CONTAINER_ALL,
CONTAINER_SEQUENCE,
CONTAINER_CHOICE| Modifier and Type | Field and Description |
|---|---|
protected List |
appinfo |
protected ElementContainer |
container |
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.
|
protected List |
documentation |
protected Group |
group |
anyAttributeElement, attributeElementGroups, attributeElements, knownSubtypesabstractValue, nameATTRIBUTE_NAME, ATTRIBUTE_TYPE, ATTRIBUTE_VALUE_FALSE, ATTRIBUTE_VALUE_TRUE, TAG_ANY, TAG_ANYATTRIBUTEATTRIBUTE_ABSTRACT, ATTRIBUTE_DEFAULT, ATTRIBUTE_FIXED, ATTRIBUTE_USE, ATTRIBUTE_XSINIL, ATTRIBUTE_XSINIL_QUALIFIED, ATTRIBUTE_XSITYPE, ATTRIBUTE_XSITYPE_QUALIFIED, DOCUMENTATION_LANG, DOCUMENTATION_LANG_QUALIFIED, ELEMENT_ALL, ELEMENT_ALL_QUALIFIED, ELEMENT_CHOICE, ELEMENT_CHOICE_QUALIFIED, ELEMENT_DEFAULT, ELEMENT_DEFAULT_QUALIFIED, ELEMENT_FIXED, ELEMENT_FIXED_QUALIFIED, ELEMENT_MAXOCCURS, ELEMENT_MINOCCURS, ELEMENT_NILLABLE, ELEMENT_PARENT, ELEMENT_PARENT_QUALIFIED, ELEMENT_RESTRICTIONS, ELEMENT_SEQUENCE, ELEMENT_SEQUENCE_QUALIFIED, ELEMENT_SUBSTITUTIONS, ELEMENT_UNIONS, FACET_ENUMERATION, FACET_ENUMERATION_QUALIFIED, FACET_FRACTIONDIGITS, FACET_FRACTIONDIGITS_QUALIFIED, FACET_LENGTH, FACET_LENGTH_QUALIFIED, FACET_MAXEXCLUSIVE, FACET_MAXEXCLUSIVE_QUALIFIED, FACET_MAXINCLUSIVE, FACET_MAXINCLUSIVE_QUALIFIED, FACET_MAXLENGTH, FACET_MAXLENGTH_QUALIFIED, FACET_MINEXCLUSIVE, FACET_MINEXCLUSIVE_QUALIFIED, FACET_MININCLUSIVE, FACET_MININCLUSIVE_QUALIFIED, FACET_MINLENGTH, FACET_MINLENGTH_QUALIFIED, FACET_PATTERN, FACET_PATTERN_QUALIFIED, FACET_TOTALDIGITS, FACET_TOTALDIGITS_QUALIFIED, FACET_WHITESPACE, FACET_WHITESPACE_QUALIFIED, LIST_ITEMTYPE, MAXOCCURS_UNBOUNDED, SCHEMA_ANNOTATION, SCHEMA_ANNOTATION_QUALIFIED, SCHEMA_ANY, SCHEMA_ANY_QUALIFIED, SCHEMA_ANYATTRIBUTE, SCHEMA_ANYATTRIBUTE_QUALIFIED, SCHEMA_APP_INFO, SCHEMA_APP_INFO_QUALIFIED, SCHEMA_ATTRIBUTE, SCHEMA_ATTRIBUTE_QUALIFIED, SCHEMA_ATTRIBUTEFORMDEFAULT, SCHEMA_ATTRIBUTEFORMDEFAULT_QUALIFIED, SCHEMA_ATTRIBUTEGROUP, SCHEMA_ATTRIBUTEGROUP_QUALIFIED, SCHEMA_BASE, SCHEMA_BASE_QUALIFIED, SCHEMA_COMPLEXCONTENT, SCHEMA_COMPLEXCONTENT_QUALIFIED, SCHEMA_COMPLEXTYPE, SCHEMA_COMPLEXTYPE_QUALIFIED, SCHEMA_DOCUMENTATION, SCHEMA_DOCUMENTATION_QUALIFIED, SCHEMA_ELEMENT, SCHEMA_ELEMENT_QUALIFIED, SCHEMA_ELEMENTFORMDEFAULT, SCHEMA_ELEMENTFORMDEFAULT_QUALIFIED, SCHEMA_EXTENSION, SCHEMA_EXTENSION_QUALIFIED, SCHEMA_FACETS, SCHEMA_FORM, SCHEMA_FORM_QUALIFIED, SCHEMA_GROUP, SCHEMA_GROUP_QUALIFIED, SCHEMA_IMPORT, SCHEMA_IMPORT_QUALIFIED, SCHEMA_INCLUDE, SCHEMA_INCLUDE_QUALIFIED, SCHEMA_ITEMLIST, SCHEMA_ITEMLIST_QUALIFIED, SCHEMA_ITEMTYPE, SCHEMA_ITEMTYPE_QUALIFIED, SCHEMA_LIST, SCHEMA_LIST_QUALIFIED, SCHEMA_LOCATION, SCHEMA_LOCATION_QUALIFIED, SCHEMA_MEMBERTYPES, SCHEMA_MEMBERTYPES_QUALIFIED, SCHEMA_NAME, SCHEMA_NAME_QUALIFIED, SCHEMA_NAMESPACE, SCHEMA_NAMESPACE_QUALIFIED, SCHEMA_NONAMESPACESCHEMALOCATION, SCHEMA_NONAMESPACESCHEMALOCATION_QUALIFIED, SCHEMA_NOTATION, SCHEMA_NOTATION_QUALIFIED, SCHEMA_PUBLIC, SCHEMA_PUBLIC_QUALIFIED, SCHEMA_QUALIFIED, SCHEMA_QUALIFIED_QUALIFIED, SCHEMA_REDEFINE, SCHEMA_REDEFINE_QUALIFIED, SCHEMA_REF, SCHEMA_REF_QUALIFIED, SCHEMA_RESTRICTION, SCHEMA_RESTRICTION_QUALIFIED, SCHEMA_SCHEMA, SCHEMA_SCHEMA_QUALIFIED, SCHEMA_SIMPLECONTENT, SCHEMA_SIMPLECONTENT_QUALIFIED, SCHEMA_SIMPLETYPE, SCHEMA_SIMPLETYPE_QUALIFIED, SCHEMA_STYPES, SCHEMA_SUBSTITUTIONGROUP, SCHEMA_SUBSTITUTIONGROUP_QUALIFIED, SCHEMA_SYSTEM, SCHEMA_SYSTEM_QUALIFIED, SCHEMA_TARGETNAMESPACE, SCHEMA_TARGETNAMESPACE_QUALIFIED, SCHEMA_TYPE, SCHEMA_TYPE_QUALIFIED, SCHEMA_UNION, SCHEMA_UNION_QUALIFIED, SCHEMA_UNQUALIFIED, SCHEMA_UNQUALIFIED_QUALIFIED, SCHEMA_VALUE, SCHEMA_VALUE_QUALIFIED, SCHEMA_VALUEVECTOR, SCHEMA_VALUEVECTOR_QUALIFIED, 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, XSI_PREFIX| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addAppInfo(java.lang.String documentation) |
protected void |
addDocumentation(java.lang.String documentation) |
void |
addElement(Element e)
Adds an element to the enclosed container.
|
Iterator |
elements()
Returns an iterator of elements from the enclosed container.
|
protected Iterator |
getAppInfos() |
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.
|
protected Iterator |
getDocumentations() |
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. |
protected void |
serializeElements(XmlSerializer serializer,
Schema schema) |
void |
setContainerMaxOccurs(int max)
Sets the maximum occurrence for the enclosed container.
|
void |
setContainerMinOccurs(int min)
Sets the minimum occurrence for the enclosed container.
|
addAttributeElement, addAttributeElementGroup, allAttributeElements, allowAnyAttributeElement, attributeElementGroups, attributeElements, denyAnyAttributeElement, getAttribute, getAttributeElement, getAttributeElementCount, getAttributeElementGroup, getAttributeElementGroupCount, getAttributes, getKownSubtypes, getTypeCount, hasAnyAttributeElement, hasAttributeElementGroups, hasAttributeElements, hasAttributes, incrementTypeCount, isComplexType, serializeAnyAttributeElement, serializeAttributeElementGroups, serializeAttributeElements, serializeAttributes, setAttribute, setAttribute, setAttributescheckNamespace, equals, getName, getParentSchema, hashCode, isAbstract, setAbstract, setName, toStringpublic static final int CONTAINER_ALL
Should be used to define complex types without relevant element order.
public static final int CONTAINER_SEQUENCE
Should be used to define complex types with relevant element order.
public static final int CONTAINER_CHOICE
Should be used to define complex types where one element must be chosen.
protected ElementContainer container
protected Group group
protected List documentation
protected List appinfo
public ComplexType(java.lang.String name,
java.lang.String namespace,
int containerType)
name - the name of the type.namespace - the namespace.containerType - the type of the enclosed container.CONTAINER_ALL,
CONTAINER_SEQUENCE,
CONTAINER_CHOICEpublic ComplexType(int containerType)
containerType - the type of the enclosed container.CONTAINER_ALL,
CONTAINER_SEQUENCE,
CONTAINER_CHOICEpublic ComplexType(QName name, int containerType)
name - the qualified name of the typecontainerType - the type of the enclosed container.CONTAINER_ALL,
CONTAINER_SEQUENCE,
CONTAINER_CHOICEpublic int getSchemaIdentifier()
public int getContainerMinOccurs()
The "minOccurs" attribute in XML Schema describes the minimum occurrence of the enclosed container inside the created XML instance document.
public void setContainerMinOccurs(int min)
The "minOccurs" attribute in XML Schema describes the minimum occurrence of the enclosed container inside the created XML instance document.
min - the minimum occurrence for the enclosed container.public int getContainerMaxOccurs()
The "maxOccurs" attribute in XML Schema describes the maximum occurrence of the enclosed container inside the created XML instance document.
public void setContainerMaxOccurs(int max)
The "maxOccurs" attribute in XML Schema describes the maximum occurrence of the enclosed container inside the created XML instance document.
max - the maximum occurrence for the enclosed container.public boolean hasElements()
true if the enclosed container has element definitions, false
otherwise.true if the enclosed container has element definitions, false otherwise.public void addElement(Element e)
e - the element to add.public Element getElementByName(QName name)
name - the qualified name of the element which should be returned.public Element getElementByName(java.lang.String name)
This method will NOT verify the namespace.
name - the name of the element which should be returned.public int getElementCount()
public Iterator elements()
public ElementContainer getContainer()
SequenceContainer,
AllContainer,
ChoiceContainerprotected void serializeElements(XmlSerializer serializer, Schema schema) throws java.io.IOException
java.io.IOExceptionprotected void addDocumentation(java.lang.String documentation)
protected Iterator getDocumentations()
protected void addAppInfo(java.lang.String documentation)
protected Iterator getAppInfos()