public class XmlData
extends java.lang.Object
The XmlData feature encodes the XML Infoset as IData structures using a format similar to but more advanced than the legacy format of prior implementations. The structure of IData itself is completely unaffected by this feature. Rather, this feature adds a layer of formalism to the way in which XML infosets are represented using IData. This new format is independent of the legacy implementation; the legacy implementation, services, and applications that use the legacy format will continue to function without change. The new format is exploited using a separate set of public services and helper classes. The two formats cannot be intermixed. The XmlData content should not reference legacy content, and legacy XML content should not reference XmlData content. However, either or both types of content can be referenced from an IData that does not represent XML encoded data (for example the Integration Server pipeline).
The encoding format also conforms to the format of the new XML document types, though it is possible to use XmlData without using XML document types. The new XML document types more fully represent the capabilities of XML and XML Schema.
This new format is created from XML and converted back to XML using new services in the pub.xmldata folder in the WmPublic package. The new format may also be created and updated using the facilities of this XmlData helper class and the XmlDataCursor class. The new content is defined using hierarchies of document types. This makes it possible for flow map manipulate the new format in ways very similar to the legacy format.
Like the legacy approach, XmlData uses IData objects to represent complex content as key/values pairs. Likewise, it uses Strings to represent simple content. Also, repeating elements (schema minOCcurs > 1) are represented as arrays. However, XmlData format allows no other object type, not even Java null. Empty simple content must be represented as empty Strings and empty complex content must be represented as empty IData objects.
In a more obvious departure from the legacy format, the XmlData feature encodes QNames as ncname#url rather than
prefix:ncname. This eliminates the need for and complexity of
a secondary definition of the namespace elsewhere such as in a document type or in an instance nsdecls
map.
Using a simple example, the XML content:
<inv:address xmlns:inv="www.invoice.com">555 Mockingbird Lane</inv:address>is represented in the legacy format using IData as key/value pair:
"inv:address" :: "555 Mockingbird Lane"with the prefix "inv" being defined externally, while in the new XmlData format, it is represented as an IData key/value pair:
"address#www.invoice.com" :: "555 Mockingbird Lane"
When creating document types from schemas, model groups (sequence, choice, and all) are represented using a field named *group
with a content type of Document. The document type contains the child content definition of the group.
When complex content has attributes, the attributes are encoded under a separate Document containing the attributes. This separate IData value
has a key named *attributes
. If simple content is present with attributes, it is encoded using the key *simple
.
If a schema contains an "any" element wildcard, that particle is represented as a field with name *any
and a content of Document.
The Document content is a very specialized any object format described later.
If a schema contains substitution groups, the head of a substitution group is encoded as field with name *substitution-
name with a very
specialized IData content that is described later.
Finally, the members of model groups are further qualified by a leading prefix of the form {1}, {2}, ... etc. This prefix uniquely identifies particles in
a group since more than one particle with the same name can appear throughout a content model. Such qualification applies to *group, *any, *substitution-, and
elements, and is present even when the names are not repeated.
This qualification is in addition to element repetition. For example, an element named "student" might have a maxOccurs property of 5 in one part of a content model
and a maxOccurs property of 1 at some later point in the model. Thus, the first occurrence {1}student
is defined as an array while the second
occurrence {2}student
is a scalar. In similar fashion, a content model might contain two choice groups. The first choice group is defined by a field with
name {1}*group
while the second choice group is defined by a field named {2}*group
.
These examples illustrate the encoding. For clarity, unqualified names, though th same layout is used for qualified names.
Simple String content such as:
<name>kilroy</name>is encoded as a single IData key/value pair with the value being a simple String:
IData "{1}name" :: "kilroy"Note that the
name
field has been prefixed with {1}
to denote the first occurrence of the element in the content.
More complex content such as
<people xmlns:family> <brother>Sam</brother> <sister>Karen</sister> <brother>Bill</brother> </people>is encoded in a similar way with multiple kye/value pairs:
"{1}people#family" :: IData "{1}brother#family" :: "Sam" "{1}sister#family" :: "Karen" "{2}brother#family" :: "Bill"Note that field names such as
{1}brother#family
include the XML namespace. Also note there there are distinct occurrences of the
brother#family
element each with a unique prefix. However, if content contains adjacent repeating elements,
the content is represented as an array.
<people xmlns:family> <brother>Sam</brother> <brother>Bill</brother> <sister>Karen</sister> </people>is encoded in a somewhat similar way, but uses a String[] for the repeated value
"{1}people#family" :: IData "{1}brother#family" :: String[] "Sam" "Bill" "{1}sister#family" :: "Karen"Content with attributes such as:
<item size="medium" color="blue"> <supplier>ABC Inc.</supplier> <distributor> XYZ Inc.</distributor> </item>is encoded as two separate sub-documents named *attributes and *group
"item" :: IData "*attributes" :: IData "size" :: "medium" "color" :: "blue" "{1}*group" :: IData "{1}supplier" :: "ABC Inc." "{1}distributor" :: "XYZ Inc."when an element has attributes but only simple content, such as
<item size="medium" color="blue">shoe</item>the simple content is encoded as a *simple key/value pair rather than a *group sub-document
"item :: IData "*attributes" :: IData "size" :: "medium" "*simple" :: "shoe"
In the preceding examples, the *group item was present only when attributes were also present. Otherwise, the *group items are not typically needed when only child elements are present. However, if an element has maxOccurs > 1 and its top level model group also has maxOccurs > 1, it is necessary that the *group item be present because both the element and the group have repeating values stored as arrays. For example, given this XML document,
<emplyees> <name>Sam</name> <address>Mars</address> <name>Mary</name> <address>Venus</address> </employees> <employees> <name>George</name> <address>Pluto</address> <name>Sally</name> <address>Saturn</address> </employees>if employees is defined as a particle with maxOccurs > 1 and it content model is defined as multiple repetitions of name and address, then the IData representation of the XML is:
"employees" :: IData[] [0] IData "*group" :: IData[] [0] IData "name" :: "Sam" "address" :: "Mars" [1] IData "name" :: "Mary" "address" :: "Venus" [1] IData "*group" :: IData[] [0] IData "name" :: "George" "address" :: "Pluto" [1] IData "name" :: "Sally" "address" :: "Saturn"It is possible to use XmlData without following the document type model. When no document types are in use, it is not possible to manipulate XmlData from Flow. It is also not possible to validate the content. When document types are not used, there are no wildcards, substitution heads, or model groups. Therefore, it is not necessary, or even desirable to create wildcard, group, or substitution content when not using document types. In addition, the public services always represent repeating content as Object[] when document types are not in use. This greatly simplifies the use of XmlData when document types are not used.
Constructor and Description |
---|
XmlData() |
Modifier and Type | Method and Description |
---|---|
static IData |
createAny(XmlDataContentTag tag,
java.lang.Object content)
Creates a *any document for either a substitution or element tag.
|
static IData |
createAny(XmlDataElementTag tag,
java.lang.Object content)
Creates a *any document.
|
static IData |
createAny(XmlDataSubstitutionTag tag,
IData content)
Creates a *any document for substitution group content.
|
static IData |
createAny(XmlDataSubstitutionTag subsTag,
XmlDataElementTag eTag,
java.lang.Object content)
Creates a *any document for a substitution group.
|
static IData |
createAttributes(java.lang.Object... pairs)
Creates the attribute content for a complex type.
|
static IData |
createComplexValue()
Creates a new empty complex value.
|
static IData |
createComplexValue(IData attributes,
java.lang.Object content)
Creates a new populated complex value.
|
java.lang.String[] |
createEmptyStringList(int size)
Creates a list of empty Strings.
|
IData[] |
createEmptyXmlDataList(int size)
Creates a list of empty IDatas
|
static IData |
createGroupValue(java.lang.Object... pairs)
Creates new group content.
|
java.lang.Object[] |
createObjectList(java.lang.Object[] list)
Converts an array to an explicit Object[].
|
static IData |
createSubstitution(XmlDataElementTag tag,
java.lang.Object content)
Creates an IData object in the form of *substitution document.
|
static boolean |
equalTo(java.lang.Object objA,
java.lang.Object objB)
Tests equality of two XmlData formatted objects.
|
static XmlDataContentTag |
getAnyKey(IData anyContent)
Returns the XmlDataElementTag from an *any document.
|
static java.lang.Object |
getAnyObject(IData anyContent)
Returns the content of a *any document.
|
static java.lang.Object |
getAnyValue(IData anyContent)
Returns the content of a *any document.
|
static XmlDataElementTag |
getAnyValueKey(IData anyContent)
Returns the XmlDataElementTag from the *any formatted IData object.
|
static java.lang.Object |
getContent(java.lang.Object parent)
Finds the content of an Object that was retrieved using XmlDataCursor.getValue().
|
static java.lang.String |
getInstanceProp(IData data,
XmlDataElementTag tag,
java.lang.String prop,
int... index)
Retrieves an xsi property on an element.
|
static IData |
getNamespacePrefixes(IData data,
XmlDataElementTag tag,
int... index)
Gets all prefix/URI pairs for a an element.
|
static java.lang.String |
getNamespacePrefixValue(IData data,
XmlDataElementTag tag,
java.lang.String prefix,
int... index)
Gets the namespace URI for the specified prefix.
|
static java.lang.Object |
getSubstitutionValue(IData substitutionContent)
Returns the value of the substituted element in a *substitution document.
|
static XmlDataElementTag |
getSubstitutionValueKey(IData substitutionContent)
Returns the XmlDataTag of the substitution content.
|
static XmlDataCursor |
getXmlDataCursor(IData root)
Returns an XmlDataCursor on the specified IData object.
|
static XmlDataTreeCursor |
getXmlDataTreeCursor(IData root)
Creates and returns an XmlDataTreeCursor.
|
static boolean |
hasComplexContent(IData item) |
static boolean |
hasSimpleContent(IData item) |
static void |
internNames(boolean b)
Determines when XmlDataTags are interned Strings
|
static boolean |
isAny(XmlDataContentTag tag)
Returns true if the specified tag is a *any wildcard tag
|
static boolean |
isIntern()
Indicates whether XmlDataTags are interned Strings.
|
static boolean |
isSubstitution(XmlDataContentTag tag)
Returns true if the specified tag is a substitution tag.
|
static java.lang.Object |
makeRepeating(java.lang.Object val)
Converts a scalar item into a repeating item with a single value.
|
static void |
setAnyKey(IData anyContent,
XmlDataContentTag key)
Sets the ncname and namespace properties of an *any document.
|
static void |
setAnyObject(IData anyContent,
java.lang.Object value)
Sets the content property of a *any document.
|
static void |
setAnyValue(IData anyContent,
java.lang.Object value)
Sets the value in the *any content
|
static void |
setAnyValueKey(IData anyContent,
XmlDataElementTag name)
Sets the ncname and namespace for properties of an *any document.
|
static void |
setInstanceProp(IData data,
XmlDataElementTag tag,
int index,
java.lang.String xsitag,
java.lang.String xsivalue)
Sets the xsi prop declaration for a given XmlData element with repeating values.
|
static void |
setInstanceProp(IData data,
XmlDataElementTag tag,
java.lang.String xsitag,
java.lang.String xsivalue)
Sets the xsi property declaration for a given XmlData element with a non-repeating value.
|
static void |
setNamespacePrefix(IData data,
XmlDataContentTag tag,
int index,
java.lang.String prefix,
java.lang.String namespace)
Sets the prefix/namespace declaration for a given XmlData element with a repeating values.
|
static void |
setNamespacePrefix(IData data,
XmlDataContentTag tag,
java.lang.String prefix,
java.lang.String namespace)
Sets the prefix/namespace declaration for a given XmlData element with a non-repeating value.
|
static void |
setSubstitutionValue(IData substitutionContent,
java.lang.Object value)
Sets the value of the substituted element in a *substitution document.
|
static void |
setSubstitutionValueKey(IData substitutionContent,
XmlDataElementTag tag)
Sets the XmlDataElementTag for the substituted element in a *substitution document.
|
public static IData createAny(XmlDataElementTag tag, java.lang.Object content)
tag
- - the XmlDataElementTag for the content tagcontent
- - the content valuepublic static IData createAny(XmlDataSubstitutionTag tag, IData content)
tag
- - the substitution namecontent
- - the content value which should be created in substitution format; for example, XmlData.createSubstitution()XmlDataException.FormatError
- - when the content is not a valid *substitution documentpublic static IData createAny(XmlDataContentTag tag, java.lang.Object content)
tag
- - the XmlDataSubstitutionTag or XmlDataElementTag for the contentcontent
- - the content value for the *any document.public static IData createAny(XmlDataSubstitutionTag subsTag, XmlDataElementTag eTag, java.lang.Object content)
subsTag
- - the XmlDataSubstitutionTag for the contenteTag
- - the XmlDataElement tag for the *substitution document.content
- - the content value for the *substitution document.public static IData createAttributes(java.lang.Object... pairs)
pairs
- - pairs of alternating XmlDataAttributeTags and Strings.XmlDataException.FormatError
- - when an odd number of arguments is passedXmlDataException.UnsupportedType
- - when an attribute value is not a StringXmlDataException.TagAndContentConflict
- - when a pair starts with anything except an XmlDataAttributeTagpublic static IData createComplexValue()
public static IData createComplexValue(IData attributes, java.lang.Object content)
attributes
- - the attribute values, typically constructed by a call to XmlData.createAttributescontent
- - the complex value content (either a String for simple, or an IData for group_XmlDataException.UnsupportedType
- - when value is not an IData or Stringpublic java.lang.String[] createEmptyStringList(int size)
size
- - the number of entriespublic IData[] createEmptyXmlDataList(int size)
size
- - the number of entriespublic static IData createGroupValue(java.lang.Object... pairs)
pairs
- - possibly empty Object[] where even members are instances of XmlDataContentTag subclasses and odd members are content
objects suitable for their corresponding tag that immediately precedes them.XmlDataException.FormatError
- - when an odd number of arguments is passedXmlDataException.TagAndContentConflict
- - when the first member of a pair is not an XmlDataContentTagXmlDataException.UnsupportedType
- - when the second member of a pair is not valid XmlData content: String, String[], IData, IData[], or Objet[]public java.lang.Object[] createObjectList(java.lang.Object[] list)
list
- - the input array (typically String[] or IData[]XmlDataException.UnsupportedType
- - when a member of the list is not a String or IDatapublic static IData createSubstitution(XmlDataElementTag tag, java.lang.Object content)
tag
- - the XmlDataElementTag of the substituted elementcontent
- - the contentXmlDataException.UnsupportedType
- - when content is not a String or IData instancepublic static boolean equalTo(java.lang.Object objA, java.lang.Object objB)
objA
- - the first ObjectobjB
- - the second Objectpublic static java.lang.Object getContent(java.lang.Object parent)
parent
- - the parent ObjectXmlDataException.FormatError
- - when the parent is not a IData or Stringpublic static XmlDataContentTag getAnyKey(IData anyContent)
anyContent
- - the IData object in the *any formatXmlDataException.FormatError
- - when the input content is not in proper XmlData content format.public static java.lang.Object getAnyObject(IData anyContent)
anyContent
- - the IData object in the *any formatXmlDataException.FormatError
- - when the input content is not in proper XmlData content format.public static java.lang.Object getAnyValue(IData anyContent)
anyContent
- - a *any documentXmlDataException.FormatError
- - when the input content is not in proper XmlData content format.public static XmlDataElementTag getAnyValueKey(IData anyContent)
anyContent
- - the IData object in the *any formatXmlDataException.FormatError
- - when the input content is not in proper XmlData content format.public static java.lang.String getInstanceProp(IData data, XmlDataElementTag tag, java.lang.String prop, int... index)
data
- - the parent IDatatag
- - the XMlDataElementTag to be queriedprop
- - the property queried, for example: type, nilindex
- - the optional offset into repeating valuespublic static java.lang.String getNamespacePrefixValue(IData data, XmlDataElementTag tag, java.lang.String prefix, int... index)
data
- - the parent IDatatag
- - the XmlDataElementTag to be queriedprefix
- - the prefix queriedindex
- - the optional offset index if repeating values are presentpublic static IData getNamespacePrefixes(IData data, XmlDataElementTag tag, int... index)
data
- - the parent IData objecttag
- - the XmlDataElementTag for which the pairs are retrievedindex
- - option offset in array if repeating values are presentpublic static XmlDataElementTag getSubstitutionValueKey(IData substitutionContent)
substitutionContent
- - content that is in substitution group format (must be an IData)XmlDataException.FormatError
- when the substitutionContent is nullpublic static java.lang.Object getSubstitutionValue(IData substitutionContent)
substitutionContent
- - the *substitution formatted contentXmlDataException.FormatError
- - when the substitutionContent is nullpublic static XmlDataCursor getXmlDataCursor(IData root)
root
- - the IData object for which an XmlDatCursor is createdpublic static XmlDataTreeCursor getXmlDataTreeCursor(IData root)
root
- - a cursor positioned on the item for which a tree cursor is createdpublic static void internNames(boolean b)
b
- - if true, names are interned Strings; otherwise names are discrete Strings.public static boolean isAny(XmlDataContentTag tag)
tag
- - the tag that is testedpublic static boolean isIntern()
public static boolean isSubstitution(XmlDataContentTag tag)
tag
- - the tag that is testedpublic static java.lang.Object makeRepeating(java.lang.Object val)
val
- - the value to be converted. Must be of type String or IData.XmlDataException.UnsupportedType
- when val is not a String or IDatapublic static void setAnyKey(IData anyContent, XmlDataContentTag key)
anyContent
- - the *any document. The setAnyValueKey method is preferable to this method. This method is used only
when directly modifying the *any document fields regardless of content (such as a substitution group).key
- - the XmlDataContentTag that provides the ncname and the XML namespace URIXmlDataException.FormatError
- if the any document has an invalid structurepublic static void setAnyObject(IData anyContent, java.lang.Object value)
anyContent
- - A *any documentvalue
- - the value assigned to the content property.XmlDataException.FormatError
- if anyContent is null, or the IData cannot be formatted properly.public static void setAnyValue(IData anyContent, java.lang.Object value)
anyContent
- - the IData object that is formatted as *any contentvalue
- - the value to set in the *any content format
throws UnsupportedType when anyContent is nto an IData object formatted as *any content
throws FormatError when the input content is not in proper XmlData content format.public static void setAnyValueKey(IData anyContent, XmlDataElementTag name)
anyContent
- - the value of the element wildcardname
- - the XmlDataElementTag naming the wildcard elementXmlDataException.FormatError
- if anyContent is not an IDatapublic static void setInstanceProp(IData data, XmlDataElementTag tag, java.lang.String xsitag, java.lang.String xsivalue)
data
- - the parent of the elementtag
- - the tag of the element for which an xsi property is specifiedxsitag
- - the xsi tag to be assigned a value (e.g. nil, type, etc.)xsivalue
- - the value assigned to the tag (e.g. true, string, etc.)public static void setInstanceProp(IData data, XmlDataElementTag tag, int index, java.lang.String xsitag, java.lang.String xsivalue)
data
- - the parent of the elementtag
- - the tag of the element for which an xsi property is specifiedindex
- - the index of the repeating itemxsitag
- - the xsi tag to be assigned a value (e.g. nil, type, etc.)xsivalue
- - the value assigned to the tag (e.g. true, string, etc.)public static void setNamespacePrefix(IData data, XmlDataContentTag tag, java.lang.String prefix, java.lang.String namespace)
data
- - the parent of the elementtag
- - the tag of the element for which a namespace declaration is specifiedprefix
- - the prefix tag to be assigned a namespacenamespace
- - the namespace assigned to the prefixpublic static void setNamespacePrefix(IData data, XmlDataContentTag tag, int index, java.lang.String prefix, java.lang.String namespace)
data
- - the parent of the elementtag
- - the tag of the element for which a namespace declaration is specifiedindex
- - the index of the repeating contentprefix
- - the prefix tag to be assigned a namespacenamespace
- - the namespace assigned to the prefixpublic static void setSubstitutionValue(IData substitutionContent, java.lang.Object value)
substitutionContent
- - the IData *substitution documentvalue
- - the value to be stored in the *content fieldXmlDataException.FormatError
- - when value is null or substitutionContent does not have a childpublic static void setSubstitutionValueKey(IData substitutionContent, XmlDataElementTag tag)
substitutionContent
- - the *substitution formated IData objecttag
- - the XmlDataELement tag of the substituted elementXmlDataException.FormatError
- - when substitutionContent is null or has no childpublic static boolean hasSimpleContent(IData item)
public static boolean hasComplexContent(IData item)