public class Element extends AnyElement implements Attributable
Those elements 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).
An element consists of a qualified name (local part and
namespace) and a type.
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 like to create the element 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 element to create different XML Schema structures.
Element references allow to reference global elements.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org">
<xs:element name="a" type="xs:string" />
<xs:complexType name="b">
<xs:sequence>
<xs:element ref="a" />
</xs:sequence>
</xs:complexType>
</xs:schema>
// get primitive data types
Type xsString = SchemaUtil.getSchemaType("string");
// create element a
Element a = new Element(new QName("a", "http://example.org"), xsString);
// create reference for element a
Element aref = new Element(a);
// create type b
ComplexType b = new ComplexType(new QName("b", "http://example.org"),
ComplexType.CONTAINER_SEQUENCE);
b.addElement(aref);
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org">
<xs:element name="a" type="xs:string" />
<xs:element name="b" substitutionGroup="a" />
</xs:schema>
// get primitive data types
Type xsString = SchemaUtil.getSchemaType("string");
// create element a
Element a = new Element(new QName("a", "http://example.org"), xsString);
// create a substituted element b
Element b = new Element(new QName("b", "http://example.org"));
b.setSubstitutionGroup(new QName("a", "http://example.org"));
Schema,
Attribute,
SimpleType,
ComplexType,
Group,
AttributeGroup| Modifier and Type | Field and Description |
|---|---|
protected List |
appinfo |
protected List |
documentation |
protected boolean |
globalScope |
protected boolean |
nillable |
protected org.ws4d.java.schema.Reference |
reference |
protected QName |
referenceLink |
protected QName |
subtitutionGroup |
protected Type |
type |
protected QName |
typeLink |
max, minabstractValue, nameATTRIBUTE_NAME, 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 |
|---|
Element(Element reference)
Creates a reference based on a specified element.
|
Element(Element reference,
int min,
int max)
Creates a reference based on a specified element.
|
Element(QName name)
Creates an element with given qualified name.
|
Element(QName name,
Type type)
Creates an element with given qualified name and type.
|
Element(QName name,
Type type,
int min,
int max)
Creates an element with given qualified name, type and occurrences.
|
Element(java.lang.String name,
java.lang.String namespace)
Creates an element with the given name and namespace.
|
Element(java.lang.String name,
java.lang.String namespace,
Type type)
Creates an element with given name, namespace and type.
|
Element(java.lang.String name,
java.lang.String namespace,
Type type,
int min,
int max)
Creates an element with given name, namespace and type.
|
Element(java.lang.String elementName,
Type type)
Creates an element with given element name and type.
|
Element(Type type)
Creates an element with given type.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addAppInfo(java.lang.String documentation) |
protected void |
addDocumentation(java.lang.String documentation) |
protected Iterator |
getAppInfos() |
CustomAttributeValue |
getAttribute(QName name)
Returns the value of the attribute with the given
name or null, if
this attribute is not available (or if its value is actually explicitly set to null
). |
HashMap |
getAttributes()
Returns all attributes explicitly set for this
Attributable instance. |
protected Iterator |
getDocumentations() |
static int |
getElementCount()
Returns the number of elements created by the framework.
|
QName |
getName()
Returns the qualified name.
|
org.ws4d.java.schema.Reference |
getReference() |
int |
getSchemaIdentifier() |
QName |
getSubstitutionGroup()
Returns the name of the substitution group for this element.
|
Type |
getType()
Returns the type of this element.
|
boolean |
hasAttributes()
Returns
true only if this instance has at least one attribute set. |
static void |
incrementElementCount() |
boolean |
isNillable()
Returns whether the instance of this element can handle nil values or not.
|
boolean |
isReference()
Returns
true if the element is a reference for another schema object, false
otherwise. |
void |
serializeAttributes(XmlSerializer serializer)
Serializes the attributes stored within this instance, if any.
|
void |
setAttribute(QName name,
CustomAttributeValue value)
Sets the
value for the attribute with the specified name. |
void |
setAttribute(QName name,
java.lang.String value)
Sets the
value for the attribute with the specified name. |
void |
setAttributes(HashMap attributes)
Sets all attributes at once to those contained within argument
attributes. |
protected void |
setLocalType(Type type) |
void |
setName(QName name)
Sets the qualified name.
|
void |
setNillable(boolean nillable)
Set whether the instance of this element can handle nil values or not.
|
void |
setSubstitutionGroup(QName group)
Sets the name of the substitution group for this element.
|
void |
setType(Type type)
Sets the type of the element.
|
java.lang.String |
toString() |
getMaxOccurs, getMinOccurs, setMaxOccurs, setMinOccurscheckNamespace, equals, getParentSchema, hashCode, isAbstract, setAbstractprotected boolean globalScope
protected QName typeLink
protected Type type
protected QName subtitutionGroup
protected boolean nillable
protected QName referenceLink
protected org.ws4d.java.schema.Reference reference
protected List documentation
protected List appinfo
public Element(java.lang.String name,
java.lang.String namespace)
This constructor will generate an appropriate qualified name.
name - the name of the element.namespace - the namespace.public Element(java.lang.String name,
java.lang.String namespace,
Type type)
This constructor will generate an appropriate qualified name.
name - the name of the element.namespace - the namespace.type - the type of the element.public Element(QName name)
name - the qualified name of the element.public Element(java.lang.String elementName,
Type type)
elementName - the qualified name of the element.type - the type of the element.public Element(Type type)
type - the type of the element.public Element(QName name, Type type)
name - the qualified name of the element.type - the type of the element.public Element(java.lang.String name,
java.lang.String namespace,
Type type,
int min,
int max)
This constructor will generated an appropriate qualified name.
name - the name of the element.namespace - the namespace.type - the type of the element.min - the minimum occurrence of this element.max - the maximum occurrence of this element.public Element(QName name, Type type, int min, int max)
name - the qualified name of the element.type - the type of the element.min - the minimum occurrence of this element.max - the maximum occurrence of this element.public Element(Element reference)
reference - the element which should be referenced.public Element(Element reference, int min, int max)
reference - the element which should be referenced.min - the minimum occurrence of this element.max - the maximum occurrence of this element.public static int getElementCount()
public static void incrementElementCount()
public java.lang.String toString()
toString in class NamedObjectpublic int getSchemaIdentifier()
getSchemaIdentifier in interface AnygetSchemaIdentifier in class AnyElementpublic CustomAttributeValue getAttribute(QName name)
Attributablename or null, if
this attribute is not available (or if its value is actually explicitly set to null
).getAttribute in interface Attributablename - the name of the attribute of which to query the valuenullpublic void setAttribute(QName name, CustomAttributeValue value)
Attributablevalue for the attribute with the specified name. Throws a
java.lang.IllegalArgumentException in case name is null.setAttribute in interface Attributablename - the name of the attribute to set, must not be nullvalue - the value to set the named attribute to (may be nullpublic void setAttribute(QName name, java.lang.String value)
Attributablevalue for the attribute with the specified name. The value
will be represented as plain String. It will be wrapped within a new instance of StringAttributeValue. This method throws a java.lang.IllegalArgumentException in
case name is null.
This is a shorthand for setAttribute(name, new StringAttributeValue(value)).
setAttribute in interface Attributablename - the name of the attribute to set, must not be nullvalue - the value to set the named attribute to (may be nullpublic HashMap getAttributes()
AttributableAttributable instance. Note that
depending on the actual implementation the returned reference may point at the 'life map', i
.e. the actual storage for the attributes. Thus, modifications to that map should be performed
with care and keeping this in mind.getAttributes in interface Attributablepublic void setAttributes(HashMap attributes)
Attributableattributes. Note
that depending on the actual implementation it is possible that the map attributes
points at may be used for the actual internal storage of the attributes (i.e. without copying
it). That is why, after passing it to this method, modifications to this map should be made
with care. This method throws a java.lang.IllegalArgumentException in cases where
attributes is null.setAttributes in interface Attributableattributes - the new attributes to setpublic boolean hasAttributes()
Attributabletrue only if this instance has at least one attribute set. Returns
false in any other case.hasAttributes in interface Attributabletrue only if there is at least one attribute set within this instancepublic void serializeAttributes(XmlSerializer serializer) throws java.io.IOException
AttributableserializeAttributes in interface Attributableserializer - the serializer to which to send outputjava.io.IOException - in case writing to serializer fails for any reasonpublic Type getType()
getType in class AnyElementpublic void setType(Type type)
type - the type of the element.public QName getSubstitutionGroup()
public void setSubstitutionGroup(QName group)
This affects only elements which are root elements of a XML Schema.
group - the qualified name for the group.protected void setLocalType(Type type)
public boolean isNillable()
true if the instance can handle nil values, false otherwise.public void setNillable(boolean nillable)
nillable - true if the instance can handle nil values, false otherwise.public QName getName()
NamedObjectgetName in class NamedObjectpublic void setName(QName name)
NamedObjectsetName in class NamedObjectname - the qname to set.public boolean isReference()
true if the element is a reference for another schema object, false
otherwise.true if the element is a reference for another schema object, false otherwise.public org.ws4d.java.schema.Reference getReference()
protected void addDocumentation(java.lang.String documentation)
protected Iterator getDocumentations()
protected void addAppInfo(java.lang.String documentation)
protected Iterator getAppInfos()