KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > axes > OneStepIteratorForward


1 /*
2  * Copyright 1999-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: OneStepIteratorForward.java,v 1.10 2004/02/17 04:32:08 minchau Exp $
18  */

19 package org.apache.xpath.axes;
20
21 import org.apache.xml.dtm.DTM;
22 import org.apache.xml.dtm.DTMFilter;
23 import org.apache.xpath.Expression;
24 import org.apache.xpath.compiler.Compiler;
25
26 /**
27  * This class implements a general iterator for
28  * those LocationSteps with only one step, and perhaps a predicate,
29  * that only go forward (i.e. it can not be used with ancestors,
30  * preceding, etc.)
31  * @see org.apache.xpath.axes#ChildTestIterator
32  * @xsl.usage advanced
33  */

34 public class OneStepIteratorForward extends ChildTestIterator
35 {
36   /** The traversal axis from where the nodes will be filtered. */
37   protected int m_axis = -1;
38
39   /**
40    * Create a OneStepIterator object.
41    *
42    * @param compiler A reference to the Compiler that contains the op map.
43    * @param opPos The position within the op map, which contains the
44    * location path expression for this itterator.
45    *
46    * @throws javax.xml.transform.TransformerException
47    */

48   OneStepIteratorForward(Compiler JavaDoc compiler, int opPos, int analysis)
49           throws javax.xml.transform.TransformerException JavaDoc
50   {
51     super(compiler, opPos, analysis);
52     int firstStepPos = compiler.getFirstChildPos(opPos);
53     
54     m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
55     
56   }
57     
58   /**
59    * Create a OneStepIterator object that will just traverse the self axes.
60    *
61    * @param axis One of the org.apache.xml.dtm.Axis integers.
62    *
63    * @throws javax.xml.transform.TransformerException
64    */

65   public OneStepIteratorForward(int axis)
66   {
67     super(null);
68     
69     m_axis = axis;
70     int whatToShow = DTMFilter.SHOW_ALL;
71     initNodeTest(whatToShow);
72   }
73
74   
75
76   
77   /**
78    * Initialize the context values for this expression
79    * after it is cloned.
80    *
81    * @param execContext The XPath runtime context for this
82    * transformation.
83    */

84   public void setRoot(int context, Object JavaDoc environment)
85   {
86     super.setRoot(context, environment);
87     m_traverser = m_cdtm.getAxisTraverser(m_axis);
88     
89   }
90   
91 // /**
92
// * Return the first node out of the nodeset, if this expression is
93
// * a nodeset expression. This is the default implementation for
94
// * nodesets.
95
// * <p>WARNING: Do not mutate this class from this function!</p>
96
// * @param xctxt The XPath runtime context.
97
// * @return the first node out of the nodeset, or DTM.NULL.
98
// */
99
// public int asNode(XPathContext xctxt)
100
// throws javax.xml.transform.TransformerException
101
// {
102
// if(getPredicateCount() > 0)
103
// return super.asNode(xctxt);
104
//
105
// int current = xctxt.getCurrentNode();
106
//
107
// DTM dtm = xctxt.getDTM(current);
108
// DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
109
//
110
// String localName = getLocalName();
111
// String namespace = getNamespace();
112
// int what = m_whatToShow;
113
//
114
// // System.out.println("what: ");
115
// // NodeTest.debugWhatToShow(what);
116
// if(DTMFilter.SHOW_ALL == what
117
// || ((DTMFilter.SHOW_ELEMENT & what) == 0)
118
// || localName == NodeTest.WILD
119
// || namespace == NodeTest.WILD)
120
// {
121
// return traverser.first(current);
122
// }
123
// else
124
// {
125
// int type = getNodeTypeTest(what);
126
// int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
127
// return traverser.first(current, extendedType);
128
// }
129
// }
130

131   /**
132    * Get the next node via getFirstAttribute && getNextAttribute.
133    */

134   protected int getNextNode()
135   {
136     m_lastFetched = (DTM.NULL == m_lastFetched)
137                      ? m_traverser.first(m_context)
138                      : m_traverser.next(m_context, m_lastFetched);
139     return m_lastFetched;
140   }
141   
142   /**
143    * Returns the axis being iterated, if it is known.
144    *
145    * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
146    * types.
147    */

148   public int getAxis()
149   {
150     return m_axis;
151   }
152
153   /**
154    * @see Expression#deepEquals(Expression)
155    */

156   public boolean deepEquals(Expression expr)
157   {
158     if(!super.deepEquals(expr))
159         return false;
160         
161     if(m_axis != ((OneStepIteratorForward)expr).m_axis)
162         return false;
163         
164     return true;
165   }
166
167   
168 }
169
Popular Tags