public interface XmlDataCursor
The XMlDataCursor allows a program to iterate over the element content of an XmlData-formatted IData document. The content of XmlData-formated IData is a collection of key/value pairs. The key has a very specialized format. The key is comprised of several components: a particle ID, a local name, and an optional namespace. There are four different types of keys: element tags, wildcard (any) tags, group tags, and substitution tags. On a historical note, the legacy form of IData encoding for XML only had element tags. The values also have specialized structure. Element tags have either IData or String values which represent either simple or complex content. Wildcard (any) tags have special any object content which in turn contain the name and actual value. This indirect representation allows Flow Maps to manipulate wildcard content. Substitution tags also have a specialized structure. They contain a substitution object which is an IData containing the actual key/value pair. Group tags contain nested complex content that mirrors the model groups of schema. Groups always contain an IData (or IData[] for repeating values).
Retrieving and updating the content of XmlData content is very similar to that of the legacy approach, but rather than obtaining an IDataCursor, the XmlData class is used to obtain an XmlDataCursor on an IData object. The XmlDataCursor is used to navigate through the element content. Just as with IDataCursors, a newly created XmlDataCursor is unpositioned, meaning that the cursor is not positioned on any particular entry. The cursor becomes positioned after a successful method invocation such as first(), last(), next(), etc. Each method description includes a description of the method's resultant behavior when the cursor is positioned, and when it is unpositioned. Navigation using XmlDataCursor is much more structured and constrained than using the legacy IDataCursor.
There are three different ways of accessing the content of the XmlDataCursor: object, value, or content. The getObject() and setObject() methods directly access the content associated with the key. For example, when an any object is present, getObject() returns the any object. The getValue() returns the value referenced by the any object. In a similar way, getKey() returns the actual key (which would be the *any tag), while getValueKey() returns the key stored on the any object. The getContent() returns only the content content portion of the item, unlike getValue() which returns the full element content (which includes the attributes). This will always be either a String (from simple content) or an IData (for complex content).
Attributes are also accessed through the XMlDataCursor. However, unlike the legacy IData structure, XmlData stores attributes separately from the element content. The attributes are not accessible as "peers" of the elements. Instead, there are explicit methods to get and set attributes values for the element at the current cursor position.
XmlData
Modifier and Type | Method and Description |
---|---|
int |
count()
Returns the number of values stored at the current cursor position.
|
boolean |
delete(int... index)
Removes the current item (key and value) from the content.
|
void |
destroy()
Releases any resources associated with the current cursor.
|
boolean |
first()
Positions the cursor at the first item.
|
boolean |
first(XmlDataContentTag key)
Positions the cursor on the first occurrence of the specified tag and return true.
|
XmlDataAttributeTag[] |
getAttributeNames(int... index)
Returns a list of attribute names for the current element.
|
IData |
getAttributes(int... index)
Returns an IData list of attributes and values at the current cursor location.
|
java.lang.String |
getAttributeValue(XmlDataAttributeTag attribute,
int... index)
Returns the value of an attribute for the current item.
|
java.lang.Object |
getContent(int... index)
Returns the content associated with the current item.
|
XmlDataCursor |
getCopy()
Returns a copy of the cursor.
|
XmlDataContentTag |
getKey()
Returns the key of the content item.
|
java.lang.Object |
getObject(int... index)
Returns the value stored at the cursor.
|
java.lang.Object |
getValue(int... index)
Returns the value of the object at the current cursor position.
|
XmlDataElementTag |
getValueKey(int... index)
Returns the key associated with the current item.
|
boolean |
hasAttributes(int... index)
Determines if the current entry has attributes.
|
void |
home()
The cursor becomes unpositioned as if newly created.
|
void |
insertAfter(XmlDataContentTag tag,
java.lang.Object value)
Inserts a content item (a key and value pair) into the content after the current cursor position.
|
void |
insertBefore(XmlDataContentTag tag,
java.lang.Object value)
Inserts a content item (a key and value pair) into the content before the current cursor position.
|
void |
insertValueAfter(java.lang.Object value,
int index)
Inserts a repeating value for the current key in the array of recurring values after the specified index.
|
void |
insertValueBefore(java.lang.Object value,
int index)
Inserts a repeating value for the current key in the array of repeating values before the specified index.
|
boolean |
isAny()
Determines if the cursor is positioned on an element wildcard item
|
boolean |
isGroup()
Determines if the cursor is positioned on a *group item
|
boolean |
isHome()
Indicates whether the cursor is unpositioned.
|
boolean |
isRepeating()
Indicates if the current item is a repeating key.
|
boolean |
isSubstitution()
Determines if the cursor is positioned on a substitution head item
|
boolean |
last()
Positions the cursor at the last item.
|
boolean |
last(XmlDataContentTag key)
Positions the cursor on the last occurrence of the specified tag and returns true.
|
boolean |
next()
Positions the cursor on the next content item.
|
boolean |
next(XmlDataContentTag key)
Positions the cursor on the next occurrence of the specified tag and returns true.
|
boolean |
previous()
Positions the cursor on the previous item.
|
boolean |
previous(XmlDataContentTag key)
Positions the cursor on the previous occurrence of the specified tag and returns true.
|
boolean |
removeAttribute(XmlDataAttributeTag attribute,
int... index)
Removes the specified attribute from the current element.
|
void |
setAttributes(IData attributes,
int... index) |
void |
setAttributeValue(XmlDataAttributeTag attribute,
java.lang.String value,
int... index)
Sets the value for the specified attribute.
|
void |
setContent(java.lang.Object data,
int... index)
Replaces the value of the current element while preserving any original associated attributes.
|
void |
setKey(XmlDataContentTag tag)
Sets the key of the current content item.
|
void |
setObject(java.lang.Object object,
int... index)
Sets the object stored at the current cursor position.
|
void |
setValue(java.lang.Object object,
int... index)
Sets the value stored at the current cursor.
|
void |
setValueKey(XmlDataContentTag key,
int... index)
Sets the key of the value of the current cursor.
|
int count()
boolean delete(int... index)
index
- optional offset into the array if repeating content is presentXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemvoid destroy()
boolean first()
boolean first(XmlDataContentTag key)
key
- the XmlDataContentTag to be searchedXmlDataAttributeTag[] getAttributeNames(int... index)
index
- offset into the repeating content array (if repeating content is present)XmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current item??XmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionIData getAttributes(int... index)
index
- the offset of the item if repeating values are presentjava.lang.String getAttributeValue(XmlDataAttributeTag attribute, int... index)
attribute
- the key of the attribute XmlDataAttributeTagindex
- offset into the list of repeating values (starting at 0)XmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionjava.lang.Object getContent(int... index)
For an element, content is one of the following:
index
- the index of the repeating valueXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataCursor getCopy()
XmlDataContentTag getKey()
XmlDataException.UnpositionedCursor
- if the cursor is not positionedjava.lang.Object getObject(int... index)
XmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemjava.lang.Object getValue(int... index)
index
- the offset into the repeating contentXmlDataElementTag getValueKey(int... index)
index
- the index of the repeating valueXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemboolean hasAttributes(int... index)
XmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemvoid home()
void insertAfter(XmlDataContentTag tag, java.lang.Object value)
tag
- - the key of the key/value pair to be inserted after the current cursor positionvalue
- - the value of the key/value pair. The value must be String, String[], IData, IData[], or Object[]void insertBefore(XmlDataContentTag tag, java.lang.Object value)
tag
- - the key of the key/value pair to be inserted before the current cursor positionvalue
- - the value of the key/value pair. The value must be String, String[], IData, IData[], or Object[]void insertValueAfter(java.lang.Object value, int index)
index
- the insert position after which the item is insertedvalue
- the value to insert; the value must be String or IDataXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataException.UnsupportedType
- if the value is not a String or IDatavoid insertValueBefore(java.lang.Object value, int index)
index
- the index position before which the value is insertedvalue
- the value to insert; the value must be String or IDataXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataException.UnsupportedType
- if the value is not a String or IDataboolean isAny()
XmlDataException.UnpositionedCursor
- if the cursor is not positionedboolean isGroup()
XmlDataException.UnpositionedCursor
- if the cursor is not positionedboolean isHome()
boolean isRepeating()
XmlDataException.UnpositionedCursor
- if the cursor is not positionedboolean isSubstitution()
XmlDataException.UnpositionedCursor
- if the cursor is not positionedboolean last()
boolean last(XmlDataContentTag key)
key
- the XmlDataContentTag to be searchedboolean next()
boolean next(XmlDataContentTag key)
key
- the XmlDataContentTag to be searchedboolean previous()
boolean previous(XmlDataContentTag key)
key
- the XmlDataContentTag to be searchedboolean removeAttribute(XmlDataAttributeTag attribute, int... index)
attribute
- an XmlDataAttributeTag naming the attributeindex
- the offset if the element is a repeating valueXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionvoid setAttributes(IData attributes, int... index)
void setAttributeValue(XmlDataAttributeTag attribute, java.lang.String value, int... index)
attribute
- - an XmlDataAttributeTag naming the attributevalue
- - the value to set where value must be a Stringindex
- - optional offset into array of repeating valuesXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionXmlDataException.UnsupportedType
- if the value is not a String or IDatavoid setContent(java.lang.Object data, int... index)
data
- the value that replaces the current contentindex
- optional offset when repeating values are presentXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor positionXmlDataException.TypeConflict
- if an incompatible object type is assigned to an array. Specifically, it is thrown
when an attempt is made to store an IData object in a Sting array or store a String object in an IData array.XmlDataException.UnsupportedType
- if the value is not a String or IDatavoid setKey(XmlDataContentTag tag)
tag
- is one of the following XmlDataContentTags XmlDataElementTag, an XmlDataAnyTag, an XmlDataGroupTag, or an XmlDataSubstitutionTagXmlDataException.UnpositionedCursor
- if the cursor is not positionedvoid setObject(java.lang.Object object, int... index)
It is preferable to use of the XmlData methods to construct the value if it is not a String or String[]. Use createGroupValue() if the content does not contain attributes and the top-level group does not contain repeating values. Otherwise use createComplexValue().
When no index is specified, the specified value completely replaces the existing value and all existing attributes for the element are cleared. If an index is specified, the specified value in the array of repeating values is set and any associated attributes are cleared. The array is enlarged if necessary. When an index is specified, the object must be a scalar String or an IData object. An index of -1 is equivalent to the index of the last repeating item. It is an error if the value is incompatible with the current key. For example, *substitution, *group, and *any tags only accept an IData as value. If tag and content are not compatible, the TagAndContentConflict exception is thrown.
object
- the value to be replaced.index
- the position in the list of repeating values to be set. When index is specified, the value may not be an array.XmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.UnsupportedType
- if the type is not String, String[], IData, IData[], or Object[]XmlDataException.TagAndContentConflict
- if the tag and content are incompatibleXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemvoid setValue(java.lang.Object object, int... index)
object
- the IData or String object that is assigned as the value of the current cursor positionindex
- the offset into the repeating values if the current item is an arrayXmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.UnsupportedType
- if the type is not String, String[], IData, IData[], or Object[]XmlDataException.TagAndContentConflict
- if the tag and content are incompatibleXmlDataException.IndexOutOfRange
- if the specified index is greater than or equal to the actual number of repeating values that are present at the current itemvoid setValueKey(XmlDataContentTag key, int... index)
key
- the key assigned to assign to the current valueindex
- the offset into the repeating value array.XmlDataException.UnpositionedCursor
- if the cursor is not positionedXmlDataException.IndexRequired
- if an index is not specified when repeating values are present at the current cursor position