286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: CachedNodeListIterator.java,v 1.2.4.1 2005/09/06 05:57:47 pvedula Exp $
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xalan.internal.xsltc.dom;
286N/A
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
286N/Aimport com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.util.IntegerArray;
286N/A
286N/A/**
286N/A * CachedNodeListIterator is used for select expressions in a
286N/A * variable or parameter. This iterator caches all nodes in an
286N/A * IntegerArray. Its cloneIterator() method is overridden to
286N/A * return an object of ClonedNodeListIterator.
286N/A */
286N/Apublic final class CachedNodeListIterator extends DTMAxisIteratorBase {
286N/A
286N/A /**
286N/A * Source for this iterator.
286N/A */
286N/A private DTMAxisIterator _source;
286N/A private IntegerArray _nodes = new IntegerArray();
286N/A private int _numCachedNodes = 0;
286N/A private int _index = 0;
286N/A private boolean _isEnded = false;
286N/A
286N/A public CachedNodeListIterator(DTMAxisIterator source) {
286N/A _source = source;
286N/A }
286N/A
286N/A public void setRestartable(boolean isRestartable) {
286N/A //_isRestartable = isRestartable;
286N/A //_source.setRestartable(isRestartable);
286N/A }
286N/A
286N/A public DTMAxisIterator setStartNode(int node) {
286N/A if (_isRestartable) {
286N/A _startNode = node;
286N/A _source.setStartNode(node);
286N/A resetPosition();
286N/A
286N/A _isRestartable = false;
286N/A }
286N/A return this;
286N/A }
286N/A
286N/A public int next() {
286N/A return getNode(_index++);
286N/A }
286N/A
286N/A public int getPosition() {
286N/A return _index == 0 ? 1 : _index;
286N/A }
286N/A
286N/A public int getNodeByPosition(int pos) {
286N/A return getNode(pos);
286N/A }
286N/A
286N/A public int getNode(int index) {
286N/A if (index < _numCachedNodes) {
286N/A return _nodes.at(index);
286N/A }
286N/A else if (!_isEnded){
286N/A int node = _source.next();
286N/A if (node != END) {
286N/A _nodes.add(node);
286N/A _numCachedNodes++;
286N/A }
286N/A else {
286N/A _isEnded = true;
286N/A }
286N/A return node;
286N/A }
286N/A else
286N/A return END;
286N/A }
286N/A
286N/A public DTMAxisIterator cloneIterator() {
286N/A ClonedNodeListIterator clone = new ClonedNodeListIterator(this);
286N/A return clone;
286N/A }
286N/A
286N/A public DTMAxisIterator reset() {
286N/A _index = 0;
286N/A return this;
286N/A }
286N/A
286N/A public void setMark() {
286N/A _source.setMark();
286N/A }
286N/A
286N/A public void gotoMark() {
286N/A _source.gotoMark();
286N/A }
286N/A}