public interface DTMIterator
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!!
| Modifier and Type | Field and Description |
|---|---|
static short |
FILTER_ACCEPT
Accept the node.
|
static short |
FILTER_SKIP
Skip this single node.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
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.
|
DTMIterator |
cloneWithReset()
Get a cloned Iterator that is reset to the start of the iteration.
|
void |
detach()
Detaches the
DTMIterator 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 |
getCurrentNode()
Get the current node in the iterator.
|
int |
getCurrentPos()
Get the current position within the cached list, which is one less than the next nextNode()
call will retrieve.
|
DTM |
getDTM(int nodeHandle)
Get an instance of a DTM that "owns" a node handle.
|
DTMManager |
getDTMManager()
Get an instance of the DTMManager.
|
boolean |
getExpandEntityReferences()
The value of this flag determines whether the children of entity reference nodes are visible to
the iterator.
|
int |
getLength()
The number of nodes in the list.
|
int |
getRoot()
The root node of the
DTMIterator, as specified when it was created. |
int |
getWhatToShow()
This attribute determines which node types are presented via the iterator.
|
boolean |
isDocOrdered()
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 the
node 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 |
previousNode()
Returns the previous node in the set and moves the position of the
DTMIterator
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 |
setRoot(int nodeHandle,
Object environment)
Reset the root node of the
DTMIterator, 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.
|
static final short FILTER_ACCEPT
static final short FILTER_SKIP
DTM getDTM(int nodeHandle)
nodeHandle - the nodeHandle.DTMManager getDTMManager()
int getRoot()
DTMIterator, 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.void setRoot(int nodeHandle,
Object environment)
DTMIterator, 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.nodeHandle - int Handle of the context node.environment - The environment object. The environment in which this iterator operates,
which should provide:
At this time the exact implementation of this environment is application dependent. Probably a proper interface will be created fairly soon.
void reset()
int getWhatToShow()
whatToShow will be skipped, but
their children may still be considered.boolean getExpandEntityReferences()
whatToShow 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 set expandEntityReferences to true when creating the iterator.
To produce a view of the document that has entity reference nodes but no entity expansion, use
the whatToShow flags to show the entity reference node and set
expandEntityReferences 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.
int nextNode()
DTMIterator has setRoot called, the first call to nextNode() returns
that root or (if it is rejected by the filters) the first node within its subtree which is not
filtered out.DTM.NULL if there
are no more members in that set.int previousNode()
DTMIterator
backwards in the set.DTM.NULL if
there are no more members in that set.void detach()
DTMIterator from the set which it iterated over, releasing any
computational resources and placing the iterator in the INVALID state. After detach
has been invoked, calls to nextNode or previousNode will
raise a runtime exception.int getCurrentNode()
boolean isFresh()
void setShouldCacheNodes(boolean b)
%REVIEW% Shouldn't the other random-access methods throw an exception if they're called on a DTMIterator with this flag set false?
b - true if the nodes should be cached.int getCurrentPos()
void runTo(int index)
index - The index to run to, or -1 if the iterator should be run to the end.void setCurrentPos(int i)
i - Must be a valid index.int item(int index)
node handle of an item in the collection. If index is
greater than or equal to the number of nodes in the list, this returns null.index - of the item.indexth position in the DTMIterator,
or -1 if that is not a valid index.int getLength()
length-1
inclusive. Note that this requires running the iterator to completion, and presumably
filling the cache.DTMIterator cloneWithReset() throws CloneNotSupportedException
CloneNotSupportedException - if anyObject clone() throws CloneNotSupportedException
CloneNotSupportedException - if anyboolean isDocOrdered()
int getAxis()
Copyright © 2022–2024 HtmlUnit. All rights reserved.