org.apache.xml.utils
Interface DTMIterator


public interface DTMIterator

Iterators are used to step through a set of nodes. It 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 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.

State: In progress!!


Field Summary
static short FILTER_ACCEPT
          Accept the node.
static short FILTER_REJECT
          Reject the node.
static short FILTER_SKIP
          Skip this single node.
 
Method Summary
 java.lang.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 getCurrentNode()
          Get the current node in the iterator..
 int getCurrentPos()
          Get the current position, which is one less than the next nextNode() call will retrieve.
 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 isFresh()
          Tells if this NodeSet 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, NodeSet will call this method to run the iterator to the index.
 void setCurrentPos(int i)
          Set the current position in the node set.
 void setEnvironment(java.lang.Object environment)
          Set the environment in which this iterator operates, which should provide: a node (the context node...
 void setRoot(int nodeHandle)
          The root node of the DTMIterator, as 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 Detail

FILTER_ACCEPT

public static final short FILTER_ACCEPT
Accept the node.

FILTER_REJECT

public static final short FILTER_REJECT
Reject the node. (same as FILTER_SKIP).

FILTER_SKIP

public static final short FILTER_SKIP
Skip this single node.
Method Detail

setEnvironment

public void setEnvironment(java.lang.Object environment)
Set 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.

Parameters:
environment - The environment object.

getRoot

public int getRoot()
The root node of the 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 itteration begins.
Returns:
nodeHandle int Handle of the context node.

setRoot

public void setRoot(int nodeHandle)
The root node of the 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 itteration begins.
Parameters:
nodeHandle - int Handle of the context node.

reset

public void reset()
Reset the iterator to the start.

getWhatToShow

public int getWhatToShow()
This attribute determines which node types are presented via the iterator. The available set of constants is defined above. Nodes not accepted by whatToShow will be skipped, but their children may still be considered.
Returns:
one of the SHOW_XXX constants.

getExpandEntityReferences

public 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 over 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.
Returns:
true if entity references will be expanded.

nextNode

public int nextNode()
Returns the next node in the set and advances the position of the iterator in the set. After a DTMIterator has setRoot called, the first call to nextNode() returns the first node in the set.
Returns:
The next node handle in the set being iterated over, or -1 if there are no more members in that set.

previousNode

public int previousNode()
Returns the previous node in the set and moves the position of the DTMIterator backwards in the set.
Returns:
The previous node handle in the set being iterated over, or null if there are no more members in that set.

detach

public void detach()
Detaches the 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.

getCurrentNode

public int getCurrentNode()
Get the current node in the iterator..
Returns:
The current node handle, or -1.

isFresh

public boolean isFresh()
Tells if this NodeSet 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

public 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.
Parameters:
b - true if the nodes should be cached.

getCurrentPos

public int getCurrentPos()
Get the current position, 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

public void runTo(int index)
If an index is requested, NodeSet 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.
Parameters:
index - The index to run to, or -1 if the iterator should be run to the end.

setCurrentPos

public void setCurrentPos(int i)
Set the current position in the node set.
Parameters:
i - Must be a valid index.

item

public int item(int index)
Returns the 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.
Parameters:
index - of the item.
Returns:
The node handle at the indexth position in the DTMIterator, or -1 if that is not a valid index.

getLength

public int getLength()
The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
Returns:
The number of nodes in the list.

cloneWithReset

public DTMIterator cloneWithReset()
                           throws java.lang.CloneNotSupportedException
Get a cloned Iterator that is reset to the start of the iteration.
Returns:
A clone of this iteration that has been reset.
Throws:
java.lang.CloneNotSupportedException -  

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
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:
java.lang.CloneNotSupportedException -  


Copyright © 2000 Apache XML Project. All Rights Reserved.