public class ParameterValue extends java.lang.Object implements Lockable
XML Schema describes the structure of content for XML instance documents. Those definitions are used inside WSDL
documents to describe a message's content. 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 an XML instance document. Each element is dedicated 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 look 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 person element defined above can be used as input or output parameter
of an operation. This will allow to use this parameter within a service. As shown in the XML Schema part, an element
defined inside an XML Schema will be used to create XML instance documents. The Framework allows to create those XML
instance documents with this class. A parameter value can be created from an element with the ParameterValueManagement.createElementValue(Element) method, or will be pass-through within action invocation.
The ParameterValue class allows nested structures like seen in XML. An object of this class
represents a single entry in an XML instance document. The XML shown above, has an root element named "person"
containing three inner-elements, firstname, lastname and age.
This would lead to an parameter value with three
nested inner-elements. The ParameterValue class allows to access the element directly and any
inner-element. To access the value of a parameter it is necessary to check the type of the parameter and cast
to the correct implementation. The framework comes along with the implementation of xs:string StringValue, xs:QNAME QNameValue and xs:base64binary AttachmentValue. It is possible to register own
implementation of XML Schema datatypes. If no implementation matches the given data type a it will be handles as
xs:string (fallback). The following lines of code, will show the usage for the structure defined above:
// create ParameterValue from element
ParameterValue personInstance = ParameterValue.createElementValue(person);
// as person does not have any values to set, set the value of the
// inner-elements.
// direct access using the path (something like XPath).
ParameterValue fname = personInstance.get("firstname");
ParameterValue lname = personInstance.get("lastname");
ParameterValue a = personInstance.get("age");
// check for correct type, cast and set the value
if (fname.getValueType() == ParameterValue.TYPE_STRING) {
StringValue firstname = (StringValue) fname;
// set value for the string
firstname.set("John");
}
if (lname.getValueType() == ParameterValue.TYPE_STRING) {
StringValue lastname = (StringValue) lname;
// set value for the string
lastname.set("Doe");
}
// As there is not implementation for xs:integer we must use the xs:string
// fallback here
if (a.getValueType() == ParameterValue.TYPE_STRING) {
StringValue age = (StringValue) a;
// set value for the string
age.set("66");
}
The path value used in different methods, allows direct access the inner-elements. Let us assume the XML content below:
<?xml version="1.0"?>
<person>
<firstname>John</firstname>
<lastname>Doe</lastname>
<age>66</age>
<address>
<street>Mainstreet 20</firstname>
<city>Los Wochos</lastname>
<phone>555-123-780-JOHNDOE</phone>
<phone>555-123-780-XML</phone>
</address>
</person>
To access the elements like street, or even the both phone elements, it necessary to extend the path. The path is always relative to the current element. Every next entry in the path is divided by a slash (/). No set path points the current element. If an entry exists more then once, like the phone element in the example above, a specific element can be accessed by using an index. The index starts with 0. Omitting the index is like using 0.
path syntax: child[index]/child-from-child[index]/child-from-child-from-chil[index]/ ... and so on.
// create ParameterValue from element
ParameterValue personInstance = ParameterValue.createElementValue(person);
// as person does not have any values to set, set the value of the
// inner-elements.
// direct access using the path (something like XPath).
personInstance.get("firstname");
The ParameterValueManagement class offers shortcut methods for the most common cast, get and set
operations for the build-in implementation of datatypes.
Element,
Operation,
StringValue,
QNameValue,
AttachmentValue,
ParameterValueManagement| Modifier and Type | Class and Description |
|---|---|
protected static class |
ParameterValue.ParameterPath
This class allows to separate the path.
|
| Modifier and Type | Field and Description |
|---|---|
protected HashMap |
attributes |
protected List |
children |
static java.lang.Object |
EMPTY_CACHE |
protected Type |
instanceType |
protected int |
max |
protected int |
min |
protected QName |
name |
protected boolean |
nil |
protected java.lang.String |
overwrite |
protected LockSupport |
pvLock |
protected Type |
type |
protected java.lang.String |
uniqueIdForAttachmentDisposal |
| Constructor and Description |
|---|
ParameterValue() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(ParameterAttribute attribute) |
void |
add(ParameterValue value)
Adds an inner-element to this parameter value.
|
void |
addAnyAttribute(QName name,
java.lang.String value) |
Iterator |
attributeNames()
Returns an iterator over the qualified names of all attributes within this parameter value.
|
Iterator |
attributes()
Returns an iterator of attributes for this parameter value.
|
Iterator |
children()
Returns an iterator of inner-elements for this parameter value.
|
Iterator |
childrenFromType()
Returns an iterator of types for all inner-elements.
|
ParameterValue |
createChild(java.lang.String path) |
ParameterValue |
createChild(java.lang.String path,
Type instanceType) |
void |
disposeAllAttachments()
Disposes all attachments contained in this
ParameterValue and its children. |
void |
exclusiveLock()
Acquires an exclusive lock.
|
ParameterValue |
get(java.lang.String path) |
ParameterValue |
get(java.lang.String path,
Type instanceType) |
java.lang.String |
getAttributeValue(QName attribute)
Returns the value of an attribute for this parameter value.
|
List |
getChildren(java.lang.String path)
Returns an iterator of inner-elements for the parameter value given by the path.
|
int |
getChildrenCount()
Returns the number of inner-elements for the parameter value.
|
int |
getChildrenCount(java.lang.String path)
Returns the number of inner-elements for the parameter value given by the path.
|
ListIterator |
getChildrenList()
Returns an listiterator of inner-elements for this parameter value.
|
Type |
getInstanceType()
Returns the instance type of this parameter value (in accordance to xsi:Type attribute).
|
LockSupport |
getLockObject() |
int |
getMaxOccurs()
Returns the the maximum occurrence for this parameter value.
|
int |
getMinOccurs()
Returns the the minimum occurrence for this parameter value.
|
QName |
getName()
Returns the name of the parameter value.
|
HashMap |
getNamespaceCache(java.lang.String comManId) |
List |
getNamespaces()
Returns the namespaces used by this parameter value.
|
java.lang.String |
getOverwritten() |
Type |
getType()
Returns the type of this parameter value.
|
int |
getValueType()
Returns the VALUE TYPE for this parameter.
|
boolean |
hasAttributes()
Returns
true if this parameter value has attributes, false otherwise. |
boolean |
hasChildren()
Returns
true if this parameter value has inner-elements, false
otherwise. |
boolean |
hasChildrenFromType()
Returns
true if this parameter value is based on a complex type, false
otherwise. |
boolean |
isNil()
Returns whether the XML instance nil value is set or not.
|
boolean |
isOverwritten()
Returns whether this parameter value is overridden or not.
|
void |
overwriteSerialization(java.lang.String value)
Allows to overwrite the serialization of this parameter.
|
boolean |
releaseExclusiveLock()
Releases an exclusive lock of the current thread.
|
void |
releaseSharedLock()
Releases a shared lock of the current thread.
|
void |
remove(ParameterValue value) |
ParameterValue |
removeChild(java.lang.String path) |
void |
resolveTypes(Schema s)
Resolve the types based on the given XML schema.
|
void |
setAttributes(HashMap newAttributes) |
void |
setAttributeValue(QName attribute,
java.lang.String value)
Sets the value of an attribute of this parameter value with given value.
|
void |
setInstanceType(Type instanceType) |
void |
setMaxOccurs(int max) |
void |
setMinOccurs(int min) |
void |
setName(QName name)
Set the name of this parameter value.
|
void |
setNil(boolean nil)
Set whether this parameter should carry values or not.
|
void |
setType(Type type)
Set the type of this parameter value.
|
void |
sharedLock()
Acquires a shared lock.
|
java.lang.String |
toString() |
boolean |
tryExclusiveLock()
Try to get an exclusive lock immediately.
|
boolean |
trySharedLock()
Tries to get a shared lock immediately.
|
public static final java.lang.Object EMPTY_CACHE
protected java.lang.String overwrite
protected Type type
protected Type instanceType
protected int min
protected int max
protected boolean nil
protected QName name
protected List children
protected HashMap attributes
protected LockSupport pvLock
protected java.lang.String uniqueIdForAttachmentDisposal
public HashMap getNamespaceCache(java.lang.String comManId)
public List getNamespaces()
This method allows to collect all namespaces and use it if necessary.
public int getValueType()
A VALUE TYPE should be a unique representation of a ParameterValue implementation
which allows to identify the implementation and cast correctly.
public void overwriteSerialization(java.lang.String value)
The given String can contain anything but SHOULD contain correct XML data.
This method should be used for debug purposes. A nested parameter can be
overwritten too.
Set to null to disable the overwrite.
value - the value which should overwrite the parameter serialization, or null if the parameter
should not be overridden.public boolean isOverwritten()
true the parameter serialization is overridden, false otherwise.public java.lang.String getOverwritten()
public void setAttributeValue(QName attribute, java.lang.String value)
attribute - the name of the attribute.value - the value of the attribute.public java.lang.String getAttributeValue(QName attribute)
attribute - the attribute to get the value of.public void add(ParameterAttribute attribute)
public void addAnyAttribute(QName name, java.lang.String value)
public boolean hasAttributes()
true if this parameter value has attributes, false otherwise.true if this parameter value has attributes, false otherwise.public Iterator attributes()
public void setAttributes(HashMap newAttributes)
public Iterator attributeNames()
QName instances, which represent the names of this parameter value's attributespublic boolean isNil()
true if the XML instance nil value is set, false otherwise.public void setNil(boolean nil)
nil - true this parameter will not have any values and the XML instance nil will be set.
xsi:nil="true"public Type getType()
public void setType(Type type)
type - the type.public LockSupport getLockObject()
public Type getInstanceType()
public void setInstanceType(Type instanceType)
public int getMinOccurs()
The "minOccurs" attribute in XML Schema describes the minimum occurrence of this element inside the created XML instance document.
public void setMinOccurs(int min)
public int getMaxOccurs()
The "maxOccurs" attribute in XML Schema describes the maximum occurrence of this element inside the created XML instance document.
public void setMaxOccurs(int max)
public QName getName()
public void setName(QName name)
name - the name.public void add(ParameterValue value)
value - the parameter value to add.public void remove(ParameterValue value)
public boolean hasChildren()
true if this parameter value has inner-elements, false
otherwise.true if this parameter value has inner-elements, false otherwise.public int getChildrenCount()
public int getChildrenCount(java.lang.String path)
path - the path to access the inner-element.public List getChildren(java.lang.String path)
path - the path to access the inner-element.public boolean hasChildrenFromType()
true if this parameter value is based on a complex type, false
otherwise.true if this parameter value is based on a complex type, false otherwise.public Iterator childrenFromType()
public Iterator children()
public ListIterator getChildrenList()
public void resolveTypes(Schema s)
s - the XML schema which contains the types for this parameter value.public ParameterValue removeChild(java.lang.String path)
public ParameterValue createChild(java.lang.String path)
public ParameterValue createChild(java.lang.String path, Type instanceType)
public ParameterValue get(java.lang.String path) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsExceptionjava.lang.IllegalArgumentExceptionpublic ParameterValue get(java.lang.String path, Type instanceType) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsExceptionjava.lang.IllegalArgumentExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic void sharedLock()
LockablesharedLock in interface Lockablepublic void exclusiveLock()
LockableexclusiveLock in interface Lockablepublic boolean trySharedLock()
LockabletrySharedLock in interface Lockabletrue if the lock has been allocated, false otherwisepublic boolean tryExclusiveLock()
LockabletryExclusiveLock in interface Lockabletrue if the lock has been allocated, false otherwisepublic void releaseSharedLock()
LockablereleaseSharedLock in interface Lockablepublic boolean releaseExclusiveLock()
LockablereleaseExclusiveLock in interface Lockablepublic void disposeAllAttachments()
ParameterValue and its children. It is
important to call this method for incoming ParameterValues to allow the attachment
store to clean up the attachment data.
This Method does only work for the root ParameterValue which was returned by an
invoke call on an Operation.