1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: SingletonIterator.java,v 1.2.4.1 2005/09/06 10:15:18 pvedula Exp $ 22 */ 23 24 package com.sun.org.apache.xalan.internal.xsltc.dom; 25 26 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; 27 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase; 28 29 /** 30 * @author Jacek Ambroziak 31 * @author Santiago Pericas-Geertsen 32 */ 33 public class SingletonIterator extends DTMAxisIteratorBase { 34 private int _node; 35 private final boolean _isConstant; 36 37 public SingletonIterator() { 38 this(Integer.MIN_VALUE, false); 39 } 40 41 public SingletonIterator(int node) { 42 this(node, false); 43 } 44 45 public SingletonIterator(int node, boolean constant) { 46 _node = _startNode = node; 47 _isConstant = constant; 48 } 49 50 /** 51 * Override the value of <tt>_node</tt> only when this 52 * object was constructed using the empty constructor. 53 */ 54 public DTMAxisIterator setStartNode(int node) { 55 if (_isConstant) { 56 _node = _startNode; 57 return resetPosition(); 58 } 59 else if (_isRestartable) { 60 if (_node <= 0) 61 _node = _startNode = node; 62 return resetPosition(); 63 } 64 return this; 65 } 66 67 public DTMAxisIterator reset() { 68 if (_isConstant) { 69 _node = _startNode; 70 return resetPosition(); 71 } 72 else { 73 final boolean temp = _isRestartable; 74 _isRestartable = true; 75 setStartNode(_startNode); 76 _isRestartable = temp; 77 } 78 return this; 79 } 80 81 public int next() { 82 final int result = _node; 83 _node = DTMAxisIterator.END; 84 return returnNode(result); 85 } 86 87 public void setMark() { 88 _markedNode = _node; 89 } 90 91 public void gotoMark() { 92 _node = _markedNode; 93 } 94 }