KickJava   Java API By Example, From Geeks To Geeks.

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


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: ForwardPositionIterator.java,v 1.9 2004/02/27 01:59:31 zongaro 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
26 /**
27  * This iterator is a wrapper that always returns the position of
28  * a node in document order. It is needed for the case where
29  * a call to position() occurs in the context of an XSLT element
30  * such as xsl:for-each, xsl:apply-templates, etc.
31  *
32  * The getPosition() methods in DTMAxisIterators defined
33  * in DTMDefaultBaseIterators always return the position
34  * in document order, which is backwards for XPath in the
35  * case of the ancestor, ancestor-or-self, previous and
36  * previous-sibling.
37  *
38  * XSLTC implements position() with the
39  * BasisLibrary.positionF() method, and uses the
40  * DTMAxisIterator.isReverse() method to determine
41  * whether the result of getPosition() should be
42  * interpreted as being equal to position().
43  * But when the expression appears in apply-templates of
44  * for-each, the position() function operates in document
45  * order.
46  *
47  * The only effect of the ForwardPositionIterator is to force
48  * the result of isReverse() to false, so that
49  * BasisLibrary.positionF() calculates position() in a way
50  * that's consistent with the context in which the
51  * iterator is being used."
52  *
53  * (Apparently the correction of isReverse() occurs
54  * implicitly, by inheritance. This class also appears
55  * to maintain its own position counter, which seems
56  * redundant.)
57  *
58  * @deprecated This class exists only for backwards compatibility with old
59  * translets. New code should not reference it.
60  */

61 public final class ForwardPositionIterator extends DTMAxisIteratorBase {
62
63     private DTMAxisIterator _source;
64
65     public ForwardPositionIterator(DTMAxisIterator source) {
66     _source = source;
67     }
68
69     public DTMAxisIterator cloneIterator() {
70     try {
71         final ForwardPositionIterator clone =
72         (ForwardPositionIterator) super.clone();
73         clone._source = _source.cloneIterator();
74         clone._isRestartable = false;
75         return clone.reset();
76     }
77     catch (CloneNotSupportedException JavaDoc e) {
78         BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
79                       e.toString());
80         return null;
81     }
82     }
83
84     public int next() {
85     return returnNode(_source.next());
86     }
87     
88     public DTMAxisIterator setStartNode(int node) {
89     _source.setStartNode(node);
90     return this;
91     }
92
93     public DTMAxisIterator reset() {
94     _source.reset();
95     return resetPosition();
96     }
97
98     public void setMark() {
99     _source.setMark();
100     }
101
102     public void gotoMark() {
103     _source.gotoMark();
104     }
105 }
106
Popular Tags