KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > dom > SingletonIterator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: SingletonIterator.java,v 1.4 2004/02/16 22:54:59 minchau Exp $
18  */

19
20 package org.apache.xalan.xsltc.dom;
21
22 import org.apache.xml.dtm.DTMAxisIterator;
23 import org.apache.xml.dtm.ref.DTMAxisIteratorBase;
24
25 /**
26  * @author Jacek Ambroziak
27  * @author Santiago Pericas-Geertsen
28  */

29 public class SingletonIterator extends DTMAxisIteratorBase {
30     private int _node;
31     private final boolean _isConstant;
32
33     public SingletonIterator() {
34     this(Integer.MIN_VALUE, false);
35     }
36
37     public SingletonIterator(int node) {
38     this(node, false);
39     }
40
41     public SingletonIterator(int node, boolean constant) {
42     _node = _startNode = node;
43     _isConstant = constant;
44     }
45     
46     /**
47      * Override the value of <tt>_node</tt> only when this
48      * object was constructed using the empty constructor.
49      */

50     public DTMAxisIterator setStartNode(int node) {
51     if (_isConstant) {
52         _node = _startNode;
53         return resetPosition();
54     }
55     else if (_isRestartable) {
56         if (_node <= 0)
57         _node = _startNode = node;
58         return resetPosition();
59     }
60     return this;
61     }
62     
63     public DTMAxisIterator reset() {
64     if (_isConstant) {
65         _node = _startNode;
66         return resetPosition();
67     }
68     else {
69         final boolean temp = _isRestartable;
70         _isRestartable = true;
71         setStartNode(_startNode);
72         _isRestartable = temp;
73     }
74     return this;
75     }
76     
77     public int next() {
78     final int result = _node;
79     _node = DTMAxisIterator.END;
80     return returnNode(result);
81     }
82
83     public void setMark() {
84     _markedNode = _node;
85     }
86
87     public void gotoMark() {
88     _node = _markedNode;
89     }
90 }
91
Popular Tags