Interface DTMIterator
- All Known Implementing Classes:
AttributeIterator
,BasicTestIterator
,ChildIterator
,ChildTestIterator
,DescendantIterator
,LocPathIterator
,NodeSequence
,NodeSetDTM
,OneStepIterator
,OneStepIteratorForward
,SelfIteratorNoPredicate
,UnionChildIterator
,UnionPathIterator
,WalkingIterator
,WalkingIteratorSorted
,XNodeSet
DTMIterators
are used to step through a (possibly filtered) set of nodes. Their API
is modeled largely after the DOM NodeIterator.
A DTMIterator is a somewhat unusual type of iterator, in that it can serve both single node iteration and random access.
The DTMIterator's traversal semantics, i.e. how it walks the tree, are specified when it is created, possibly and probably by an XPath LocationPath or a UnionExpr.
A DTMIterator is meant to be created once as a master static object, and then cloned many times for runtime use. Or the master object itself may be used for simpler use cases.
At this time, we do not expect DTMIterator to emulate NodeIterator's "maintain relative position" semantics under document mutation. It's likely to respond more like the TreeWalker's "current node" semantics. However, since the base DTM is immutable, this issue currently makes no practical difference.
State: In progress!!
-
Field Summary
Modifier and TypeFieldDescriptionstatic final short
Accept the node.static final short
Skip this single node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
allowDetachToRelease
(boolean allowRelease) Specify if it's OK for detach to release the iterator for reuse.clone()
Get a clone of this iterator, but don't reset the iteration in the process, so that it may be used from the current position.Get a cloned Iterator that is reset to the start of the iteration.void
detach()
Detaches theDTMIterator
from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.int
getAxis()
Returns the axis being iterated, if it is known.int
Get the current node in the iterator.int
Get the current position within the cached list, which is one less than the next nextNode() call will retrieve. i.e. if you call getCurrentPos() and the return is 0, the next fetch will take place at index 1.getDTM
(int nodeHandle) Get an instance of a DTM that "owns" a node handle.Get an instance of the DTMManager.boolean
The value of this flag determines whether the children of entity reference nodes are visible to the iterator.int
The number of nodes in the list.int
getRoot()
The root node of theDTMIterator
, as specified when it was created.int
This attribute determines which node types are presented via the iterator.boolean
Returns true if all the nodes in the iteration well be returned in document order.boolean
isFresh()
Tells if this NodeSetDTM is "fresh", in other words, if the first nextNode() that is called will return the first node in the set.int
item
(int index) Returns thenode handle
of an item in the collection.int
nextNode()
Returns the next node in the set and advances the position of the iterator in the set.int
Returns the previous node in the set and moves the position of theDTMIterator
backwards in the set.void
reset()
Reset the iterator to the start.void
runTo
(int index) If an index is requested, NodeSetDTM will call this method to run the iterator to the index.void
setCurrentPos
(int i) Set the current position in the node set.void
Reset the root node of theDTMIterator
, overriding the value specified when it was created.void
setShouldCacheNodes
(boolean b) If setShouldCacheNodes(true) is called, then nodes will be cached, enabling random access, and giving the ability to do sorts and the like.
-
Field Details
-
FILTER_ACCEPT
static final short FILTER_ACCEPTAccept the node.- See Also:
-
FILTER_SKIP
static final short FILTER_SKIPSkip this single node.- See Also:
-
-
Method Details
-
getDTM
Get an instance of a DTM that "owns" a node handle. Since a node iterator may be passed without a DTMManager, this allows the caller to easily get the DTM using just the iterator.- Parameters:
nodeHandle
- the nodeHandle.- Returns:
- a non-null DTM reference.
-
getDTMManager
DTMManager getDTMManager()Get an instance of the DTMManager. Since a node iterator may be passed without a DTMManager, this allows the caller to easily get the DTMManager using just the iterator.- Returns:
- a non-null DTMManager reference.
-
getRoot
int getRoot()The root node of theDTMIterator
, as specified when it was created. Note the root node is not the root node of the document tree, but the context node from where the iteration begins and ends.- Returns:
- nodeHandle int Handle of the context node.
-
setRoot
Reset the root node of theDTMIterator
, overriding the value specified when it was created. Note the root node is not the root node of the document tree, but the context node from where the iteration begins.- Parameters:
nodeHandle
- int Handle of the context node.environment
- The environment object. The environment in which this iterator operates, which should provide:a node (the context node... same value as "root" defined below)
a pair of non-zero positive integers (the context position and the context size)
a set of variable bindings
a function library
the set of namespace declarations in scope for the expression.
At this time the exact implementation of this environment is application dependent. Probably a proper interface will be created fairly soon.
-
reset
void reset()Reset the iterator to the start. After resetting, the next node returned will be the root node -- or, if that's filtered out, the first node within the root's subtree which is _not_ skipped by the filters. -
getWhatToShow
int getWhatToShow()This attribute determines which node types are presented via the iterator. The available set of constants is defined above. Nodes not accepted bywhatToShow
will be skipped, but their children may still be considered.- Returns:
- one of the SHOW_XXX constants, or several ORed together.
-
getExpandEntityReferences
boolean getExpandEntityReferences()The value of this flag determines whether the children of entity reference nodes are visible to the iterator. If false, they and their descendants will be rejected. Note that this rejection takes precedence overwhatToShow
and the filter.To produce a view of the document that has entity references expanded and does not expose the entity reference node itself, use the
whatToShow
flags to hide the entity reference node and setexpandEntityReferences
to true when creating the iterator. To produce a view of the document that has entity reference nodes but no entity expansion, use thewhatToShow
flags to show the entity reference node and setexpandEntityReferences
to false.NOTE: In Xalan's use of DTM we will generally have fully expanded entity references when the document tree was built, and thus this flag will have no effect.
- Returns:
- true if entity references will be expanded.
-
nextNode
int nextNode()Returns the next node in the set and advances the position of the iterator in the set. After aDTMIterator
has setRoot called, the first call tonextNode()
returns that root or (if it is rejected by the filters) the first node within its subtree which is not filtered out.- Returns:
- The next node handle in the set being iterated over, or
DTM.NULL
if there are no more members in that set.
-
previousNode
int previousNode()Returns the previous node in the set and moves the position of theDTMIterator
backwards in the set.- Returns:
- The previous node handle in the set being iterated over, or
DTM.NULL
if there are no more members in that set.
-
detach
void detach()Detaches theDTMIterator
from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. Afterdetach
has been invoked, calls tonextNode
orpreviousNode
will raise a runtime exception. -
allowDetachToRelease
void allowDetachToRelease(boolean allowRelease) Specify if it's OK for detach to release the iterator for reuse.- Parameters:
allowRelease
- true if it is OK for detach to release this iterator for pooling.
-
getCurrentNode
int getCurrentNode()Get the current node in the iterator. Note that this differs from the DOM's NodeIterator, where the current position lies between two nodes (as part of the maintain-relative-position semantic).- Returns:
- The current node handle, or -1.
-
isFresh
boolean isFresh()Tells if this NodeSetDTM is "fresh", in other words, if the first nextNode() that is called will return the first node in the set.- Returns:
- true if the iteration of this list has not yet begun.
-
setShouldCacheNodes
void setShouldCacheNodes(boolean b) If setShouldCacheNodes(true) is called, then nodes will be cached, enabling random access, and giving the ability to do sorts and the like. They are not cached by default.%REVIEW% Shouldn't the other random-access methods throw an exception if they're called on a DTMIterator with this flag set false?
- Parameters:
b
- true if the nodes should be cached.
-
getCurrentPos
int getCurrentPos()Get the current position within the cached list, which is one less than the next nextNode() call will retrieve. i.e. if you call getCurrentPos() and the return is 0, the next fetch will take place at index 1.- Returns:
- The position of the iteration.
-
runTo
void runTo(int index) If an index is requested, NodeSetDTM will call this method to run the iterator to the index. By default this sets m_next to the index. If the index argument is -1, this signals that the iterator should be run to the end and completely fill the cache.- Parameters:
index
- The index to run to, or -1 if the iterator should be run to the end.
-
setCurrentPos
void setCurrentPos(int i) Set the current position in the node set.- Parameters:
i
- Must be a valid index.
-
item
int item(int index) Returns thenode handle
of an item in the collection. Ifindex
is greater than or equal to the number of nodes in the list, this returnsnull
.- Parameters:
index
- of the item.- Returns:
- The node handle at the
index
th position in theDTMIterator
, or-1
if that is not a valid index.
-
getLength
int getLength()The number of nodes in the list. The range of valid child node indices is 0 tolength-1
inclusive. Note that this requires running the iterator to completion, and presumably filling the cache.- Returns:
- The number of nodes in the list.
-
cloneWithReset
Get a cloned Iterator that is reset to the start of the iteration.- Returns:
- A clone of this iteration that has been reset.
- Throws:
CloneNotSupportedException
- if any
-
clone
Get a clone of this iterator, but don't reset the iteration in the process, so that it may be used from the current position.- Returns:
- A clone of this object.
- Throws:
CloneNotSupportedException
- if any
-
isDocOrdered
boolean isDocOrdered()Returns true if all the nodes in the iteration well be returned in document order.- Returns:
- true if all the nodes in the iteration well be returned in document order.
-
getAxis
int getAxis()Returns the axis being iterated, if it is known.- Returns:
- Axis.CHILD, etc., or -1 if the axis is not known or is of multiple types.
-