FileDocCategorySizeDatePackage
CurrentNodeListIterator.javaAPI DocJava SE 6 API5504Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.dom

CurrentNodeListIterator

public final class CurrentNodeListIterator extends DTMAxisIteratorBase
Iterators of this kind use a CurrentNodeListFilter to filter a subset of nodes from a source iterator. For each node from the source, the boolean method CurrentNodeListFilter.test() is called. All nodes from the source are read into an array upon calling setStartNode() (this is needed to determine the value of last, a parameter to CurrentNodeListFilter.test()). The method getLast() returns the last element after applying the filter.
author
Jacek Ambroziak
author
Santiago Pericas-Geertsen
author
Morten Jorgensen

Fields Summary
private boolean
_docOrder
A flag indicating if nodes are returned in document order.
private DTMAxisIterator
_source
The source for this iterator.
private final CurrentNodeListFilter
_filter
A reference to a filter object.
private IntegerArray
_nodes
An integer array to store nodes from source iterator.
private int
_currentIndex
Index in _nodes of the next node to filter.
private final int
_currentNode
The current node in the stylesheet at the time of evaluation.
private AbstractTranslet
_translet
A reference to the translet.
Constructors Summary
public CurrentNodeListIterator(DTMAxisIterator source, CurrentNodeListFilter filter, int currentNode, AbstractTranslet translet)


       
				    
				    
				     
    
	this(source, !source.isReverse(), filter, currentNode, translet);
    
public CurrentNodeListIterator(DTMAxisIterator source, boolean docOrder, CurrentNodeListFilter filter, int currentNode, AbstractTranslet translet)

	_source = source;
	_filter = filter;
	_translet = translet;
	_docOrder = docOrder;
	_currentNode = currentNode;
    
Methods Summary
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorcloneIterator()

	try {
	    final CurrentNodeListIterator clone =
		(CurrentNodeListIterator) super.clone();
	    clone._nodes = (IntegerArray) _nodes.clone();
	    clone._source = _source.cloneIterator();
	    clone._isRestartable = false;
	    return clone.reset();
	}
	catch (CloneNotSupportedException e) {
	    BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
				      e.toString());
	    return null;
	}
    
private intcomputePositionOfLast()

        final int last = _nodes.cardinality();
        final int currNode = _currentNode;
	final AbstractTranslet translet = _translet;

	int lastPosition = _position;
	for (int index = _currentIndex; index < last; ) {
	    final int position = _docOrder ? index + 1 : last - index;
            int nodeIndex = _nodes.at(index++); 	// note increment

            if (_filter.test(nodeIndex, position, last, currNode, translet,
                             this)) {
                lastPosition++;
            }
        }
	return lastPosition;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorforceNaturalOrder()

	_docOrder = true;
	return this;
    
public intgetLast()

	if (_last == -1) {
	    _last = computePositionOfLast();
	}
	return _last;
    
public voidgotoMark()

	_currentIndex = _markedNode;
    
public booleanisReverse()

	return !_docOrder;
    
public intnext()

	final int last = _nodes.cardinality();
	final int currentNode = _currentNode;
	final AbstractTranslet translet = _translet;

	for (int index = _currentIndex; index < last; ) {
	    final int position = _docOrder ? index + 1 : last - index;
	    final int node = _nodes.at(index++); 	// note increment

	    if (_filter.test(node, position, last, currentNode, translet,
                             this)) {
		_currentIndex = index;
		return returnNode(node);
	    }
	}
	return END;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorreset()

	_currentIndex = 0;
	return resetPosition();
    
public voidsetMark()

	_markedNode = _currentIndex;
    
public voidsetRestartable(boolean isRestartable)

	_isRestartable = isRestartable;
	_source.setRestartable(isRestartable);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorsetStartNode(int node)

	if (_isRestartable) {
	    _source.setStartNode(_startNode = node);

	    _nodes.clear();
	    while ((node = _source.next()) != END) {
		_nodes.add(node);
	    }
	    _currentIndex = 0;
	    resetPosition();
	}
	return this;