001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: SingletonIterator.java 468651 2006-10-28 07:04:25Z minchau $ 020 */ 021 022 package org.apache.xalan.xsltc.dom; 023 024 import org.apache.xml.dtm.DTMAxisIterator; 025 import org.apache.xml.dtm.ref.DTMAxisIteratorBase; 026 027 /** 028 * @author Jacek Ambroziak 029 * @author Santiago Pericas-Geertsen 030 */ 031 public class SingletonIterator extends DTMAxisIteratorBase { 032 private int _node; 033 private final boolean _isConstant; 034 035 public SingletonIterator() { 036 this(Integer.MIN_VALUE, false); 037 } 038 039 public SingletonIterator(int node) { 040 this(node, false); 041 } 042 043 public SingletonIterator(int node, boolean constant) { 044 _node = _startNode = node; 045 _isConstant = constant; 046 } 047 048 /** 049 * Override the value of <tt>_node</tt> only when this 050 * object was constructed using the empty constructor. 051 */ 052 public DTMAxisIterator setStartNode(int node) { 053 if (_isConstant) { 054 _node = _startNode; 055 return resetPosition(); 056 } 057 else if (_isRestartable) { 058 if (_node <= 0) 059 _node = _startNode = node; 060 return resetPosition(); 061 } 062 return this; 063 } 064 065 public DTMAxisIterator reset() { 066 if (_isConstant) { 067 _node = _startNode; 068 return resetPosition(); 069 } 070 else { 071 final boolean temp = _isRestartable; 072 _isRestartable = true; 073 setStartNode(_startNode); 074 _isRestartable = temp; 075 } 076 return this; 077 } 078 079 public int next() { 080 final int result = _node; 081 _node = DTMAxisIterator.END; 082 return returnNode(result); 083 } 084 085 public void setMark() { 086 _markedNode = _node; 087 } 088 089 public void gotoMark() { 090 _node = _markedNode; 091 } 092 }