Package org.apache.xml.dtm.ref
Class DTMAxisIteratorBase
java.lang.Object
org.apache.xml.dtm.ref.DTMAxisIteratorBase
- All Implemented Interfaces:
Cloneable,DTMAxisIterator
- Direct Known Subclasses:
DTMDefaultBaseIterators.InternalAxisIteratorBase
public abstract class DTMAxisIteratorBase extends Object implements DTMAxisIterator
This class serves as a default base for implementations of mutable
DTMAxisIterators.
-
Field Summary
Fields Modifier and Type Field Description protected boolean_includeSelfTrue if the start node should be considered part of the iteration.protected boolean_isRestartableTrue if this iteration can be restarted.protected int_lastThe position of the last node within the iteration, as defined by XPath.protected int_markedNodeThe position of the marked node within the iteration; a saved itaration state that we may want to come back to.protected int_positionThe position of the current node within the iteration, as defined by XPath.protected int_startNodeThe handle to the start, or root, of the iteration.Fields inherited from interface org.apache.xml.dtm.DTMAxisIterator
END -
Constructor Summary
Constructors Constructor Description DTMAxisIteratorBase() -
Method Summary
Modifier and Type Method Description DTMAxisIteratorcloneIterator()Returns a deep copy of this iterator.intgetAxis()Returns the axis being iterated, if it is known.intgetLast()Returns the position of the last node within the iteration, as defined by XPath.intgetNodeByPosition(int position)Return the node at the given position.intgetPosition()intgetStartNode()Get start to END should 'close' the iterator, i.e.DTMAxisIteratorincludeSelf()Set the flag to include the start node in the iteration.booleanisDocOrdered()Returns true if all the nodes in the iteration well be returned in document order.booleanisReverse()DTMAxisIteratorreset()Resets the iterator to the last start node.protected DTMAxisIteratorresetPosition()Reset the position to zero.protected intreturnNode(int node)Do any final cleanup that is required before returning the node that was passed in, and then return it.voidsetRestartable(boolean isRestartable)Set if restartable.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.xml.dtm.DTMAxisIterator
gotoMark, next, setMark, setStartNode
-
Field Details
-
_last
protected int _lastThe position of the last node within the iteration, as defined by XPath. Note that this is _not_ the node's handle within the DTM. Also, don't confuse it with the current (most recently returned) position. -
_position
protected int _positionThe position of the current node within the iteration, as defined by XPath. Note that this is _not_ the node's handle within the DTM! -
_markedNode
protected int _markedNodeThe position of the marked node within the iteration; a saved itaration state that we may want to come back to. Note that only one mark is maintained; there is no stack. -
_startNode
protected int _startNodeThe handle to the start, or root, of the iteration. Set this to END to construct an empty iterator. -
_includeSelf
protected boolean _includeSelfTrue if the start node should be considered part of the iteration. False will cause it to be skipped. -
_isRestartable
protected boolean _isRestartableTrue if this iteration can be restarted. False otherwise (eg, if we are iterating over a stream that can not be re-scanned, or if the iterator was produced by cloning another iterator.)
-
-
Constructor Details
-
DTMAxisIteratorBase
public DTMAxisIteratorBase()
-
-
Method Details
-
getStartNode
public int getStartNode()Get start to END should 'close' the iterator, i.e. subsequent call to next() should return END.- Specified by:
getStartNodein interfaceDTMAxisIterator- Returns:
- The root node of the iteration.
-
reset
Description copied from interface:DTMAxisIteratorResets the iterator to the last start node.- Specified by:
resetin interfaceDTMAxisIterator- Returns:
- A DTMAxisIterator which has been reset to the start node, which may or may not be the same as this iterator.
-
includeSelf
Set the flag to include the start node in the iteration.- Returns:
- This default method returns just returns this DTMAxisIterator, after setting the flag. (Returning "this" permits C++-style chaining of method calls into a single expression.)
-
getLast
public int getLast()Returns the position of the last node within the iteration, as defined by XPath. In a forward iterator, I believe this equals the number of nodes which this iterator will yield. In a reverse iterator, I believe it should return 1 (since the "last" is the first produced.) This may be an expensive operation when called the first time, since it may have to iterate through a large part of the document to produce its answer.- Specified by:
getLastin interfaceDTMAxisIterator- Returns:
- The number of nodes in this iterator (forward) or 1 (reverse).
-
getPosition
public int getPosition()- Specified by:
getPositionin interfaceDTMAxisIterator- Returns:
- The position of the current node within the set, as defined by XPath. Note that this is one-based, not zero-based.
-
isReverse
public boolean isReverse()- Specified by:
isReversein interfaceDTMAxisIterator- Returns:
- true if this iterator has a reversed axis, else false
-
cloneIterator
Returns a deep copy of this iterator. Cloned iterators may not be restartable. The iterator being cloned may or may not become non-restartable as a side effect of this operation.- Specified by:
cloneIteratorin interfaceDTMAxisIterator- Returns:
- a deep copy of this iterator.
-
returnNode
protected final int returnNode(int node)Do any final cleanup that is required before returning the node that was passed in, and then return it. The intended use is
return returnNode(node);%REVIEW% If we're calling it purely for side effects, should we really be bothering with a return value? Something like
accept(node); return node;
would probably optimize just about as well and avoid questions about whether what's returned could ever be different from what's passed in.- Parameters:
node- Node handle which iteration is about to yield.- Returns:
- The node handle passed in.
-
resetPosition
Reset the position to zero. NOTE that this does not change the iteration state, only the position number associated with that state. %REVIEW% Document when this would be used?- Returns:
- This instance.
-
isDocOrdered
public boolean isDocOrdered()Returns true if all the nodes in the iteration well be returned in document order.- Returns:
- true as a default.
-
getAxis
public 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.
-
setRestartable
public void setRestartable(boolean isRestartable)Description copied from interface:DTMAxisIteratorSet if restartable.- Specified by:
setRestartablein interfaceDTMAxisIterator
-
getNodeByPosition
public int getNodeByPosition(int position)Return the node at the given position.- Specified by:
getNodeByPositionin interfaceDTMAxisIterator- Parameters:
position- The position- Returns:
- The node at the given position.
-