org.apache.xalan.xsltc.dom

Class MatchingIterator

Implemented Interfaces:
Cloneable, DTMAxisIterator

public final class MatchingIterator
extends DTMAxisIteratorBase

This is a special kind of iterator that takes a source iterator and a node N. If initialized with a node M (the parent of N) it computes the position of N amongst the children of M. This position can be obtained by calling getPosition(). It is an iterator even though next() will never be called. It is used to match patterns with a single predicate like: BOOK[position() = last()] In this example, the source iterator will return elements of type BOOK, a call to position() will return the position of N. Notice that because of the way the pattern matching is implemented, N will always be a node in the source since (i) it is a BOOK or the test sequence would not be considered and (ii) the source iterator is initialized with M which is the parent of N. Also, and still in this example, a call to last() will return the number of elements in the source (i.e. the number of BOOKs).
Authors:
Jacek Ambroziak
Santiago Pericas-Geertsen

Fields inherited from interface org.apache.xml.dtm.DTMAxisIterator

END

Constructor Summary

MatchingIterator(int match, DTMAxisIterator source)

Method Summary

DTMAxisIterator
cloneIterator()
Returns a deep copy of this iterator.
int
getLast()
Returns the position of the last node within the iteration, as defined by XPath.
int
getPosition()
void
gotoMark()
Restores the current node remembered by setMark().
int
next()
Get the next node in the iteration.
DTMAxisIterator
reset()
void
setMark()
Remembers the current node for the next call to gotoMark().
void
setRestartable(boolean isRestartable)
Set if restartable.
DTMAxisIterator
setStartNode(int node)
Set start to END should 'close' the iterator, i.e. subsequent call to next() should return END.

Methods inherited from class org.apache.xml.dtm.ref.DTMAxisIteratorBase

cloneIterator, getAxis, getLast, getNodeByPosition, getPosition, getStartNode, includeSelf, isDocOrdered, isReverse, reset, setRestartable

Constructor Details

MatchingIterator

public MatchingIterator(int match,
                        DTMAxisIterator source)

Method Details

cloneIterator

public DTMAxisIterator 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:
cloneIterator in interface DTMAxisIterator
Overrides:
cloneIterator in interface DTMAxisIteratorBase
Returns:
a deep copy of this iterator.

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:
getLast in interface DTMAxisIterator
Overrides:
getLast in interface DTMAxisIteratorBase
Returns:
The number of nodes in this iterator (forward) or 1 (reverse).

getPosition

public int getPosition()
Specified by:
getPosition in interface DTMAxisIterator
Overrides:
getPosition in interface DTMAxisIteratorBase
Returns:
The position of the current node within the set, as defined by XPath. Note that this is one-based, not zero-based.

gotoMark

public void gotoMark()
Restores the current node remembered by setMark().
Specified by:
gotoMark in interface DTMAxisIterator

next

public int next()
Get the next node in the iteration.
Specified by:
next in interface DTMAxisIterator
Returns:
The next node handle in the iteration, or END.

reset

public DTMAxisIterator reset()
Specified by:
reset in interface DTMAxisIterator
Overrides:
reset in interface DTMAxisIteratorBase
Returns:
A DTMAxisIterator which has been reset to the start node, which may or may not be the same as this iterator.

setMark

public void setMark()
Remembers the current node for the next call to gotoMark().
Specified by:
setMark in interface DTMAxisIterator

setRestartable

public void setRestartable(boolean isRestartable)
Set if restartable.
Specified by:
setRestartable in interface DTMAxisIterator
Overrides:
setRestartable in interface DTMAxisIteratorBase

setStartNode

public DTMAxisIterator setStartNode(int node)
Set start to END should 'close' the iterator, i.e. subsequent call to next() should return END.
Specified by:
setStartNode in interface DTMAxisIterator
Parameters:
node - Sets the root of the iteration.
Returns:
A DTMAxisIterator set to the start of the iteration.

Copyright B) 2006 Apache XML Project. All Rights Reserved.