KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > dom > AbsoluteIterator


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: AbsoluteIterator.java,v 1.11 2004/02/16 22:54:59 minchau Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.dom;
21
22 import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
23 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
24 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
25 import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
26
27 /**
28  * Absolute iterators ignore the node that is passed to setStartNode().
29  * Instead, they always start from the root node. The node passed to
30  * setStartNode() is not totally useless, though. It is needed to obtain the
31  * DOM mask, i.e. the index into the MultiDOM table that corresponds to the
32  * DOM "owning" the node.
33  *
34  * The DOM mask is cached, so successive calls to setStartNode() passing
35  * nodes from other DOMs will have no effect (i.e. this iterator cannot
36  * migrate between DOMs).
37  * @author Jacek Ambroziak
38  * @author Santiago Pericas-Geertsen
39  */

40 public final class AbsoluteIterator extends DTMAxisIteratorBase {
41
42     /**
43      * Source for this iterator.
44      */

45     private DTMAxisIterator _source;
46
47     public AbsoluteIterator(DTMAxisIterator source) {
48     _source = source;
49 // System.out.println("AI source = " + source + " this = " + this);
50
}
51
52     public void setRestartable(boolean isRestartable) {
53     _isRestartable = isRestartable;
54     _source.setRestartable(isRestartable);
55     }
56
57     public DTMAxisIterator setStartNode(int node) {
58     _startNode = DTMDefaultBase.ROOTNODE;
59     if (_isRestartable) {
60         _source.setStartNode(_startNode);
61         resetPosition();
62     }
63     return this;
64     }
65
66     public int next() {
67     return returnNode(_source.next());
68     }
69
70     public DTMAxisIterator cloneIterator() {
71     try {
72         final AbsoluteIterator clone = (AbsoluteIterator) super.clone();
73         clone._source = _source.cloneIterator(); // resets source
74
clone.resetPosition();
75         clone._isRestartable = false;
76         return clone;
77     }
78     catch (CloneNotSupportedException JavaDoc e) {
79         BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
80                       e.toString());
81         return null;
82     }
83     }
84
85     public DTMAxisIterator reset() {
86     _source.reset();
87     return resetPosition();
88     }
89     
90     public void setMark() {
91     _source.setMark();
92     }
93
94     public void gotoMark() {
95     _source.gotoMark();
96     }
97 }
98
Popular Tags