2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 * $Id: OneStepIteratorForward.java 469314 2006-10-30 23:31:59Z minchau $
21 package org.apache.xpath.axes;
23 import org.apache.xml.dtm.DTM;
24 import org.apache.xml.dtm.DTMFilter;
25 import org.apache.xpath.Expression;
26 import org.apache.xpath.compiler.Compiler;
27 import org.apache.xpath.compiler.OpMap;
30 * This class implements a general iterator for
31 * those LocationSteps with only one step, and perhaps a predicate,
32 * that only go forward (i.e. it can not be used with ancestors,
34 * @see org.apache.xpath.axes#ChildTestIterator
37 public class OneStepIteratorForward extends ChildTestIterator
39 static final long serialVersionUID = -1576936606178190566L;
40 /** The traversal axis from where the nodes will be filtered. */
41 protected int m_axis = -1;
44 * Create a OneStepIterator object.
46 * @param compiler A reference to the Compiler that contains the op map.
47 * @param opPos The position within the op map, which contains the
48 * location path expression for this itterator.
50 * @throws javax.xml.transform.TransformerException
52 OneStepIteratorForward(Compiler compiler, int opPos, int analysis)
53 throws javax.xml.transform.TransformerException
55 super(compiler, opPos, analysis);
56 int firstStepPos = OpMap.getFirstChildPos(opPos);
58 m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
63 * Create a OneStepIterator object that will just traverse the self axes.
65 * @param axis One of the org.apache.xml.dtm.Axis integers.
67 * @throws javax.xml.transform.TransformerException
69 public OneStepIteratorForward(int axis)
74 int whatToShow = DTMFilter.SHOW_ALL;
75 initNodeTest(whatToShow);
82 * Initialize the context values for this expression
85 * @param context The XPath runtime context for this
88 public void setRoot(int context, Object environment)
90 super.setRoot(context, environment);
91 m_traverser = m_cdtm.getAxisTraverser(m_axis);
96 // * Return the first node out of the nodeset, if this expression is
97 // * a nodeset expression. This is the default implementation for
99 // * <p>WARNING: Do not mutate this class from this function!</p>
100 // * @param xctxt The XPath runtime context.
101 // * @return the first node out of the nodeset, or DTM.NULL.
103 // public int asNode(XPathContext xctxt)
104 // throws javax.xml.transform.TransformerException
106 // if(getPredicateCount() > 0)
107 // return super.asNode(xctxt);
109 // int current = xctxt.getCurrentNode();
111 // DTM dtm = xctxt.getDTM(current);
112 // DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
114 // String localName = getLocalName();
115 // String namespace = getNamespace();
116 // int what = m_whatToShow;
118 // // System.out.println("what: ");
119 // // NodeTest.debugWhatToShow(what);
120 // if(DTMFilter.SHOW_ALL == what
121 // || ((DTMFilter.SHOW_ELEMENT & what) == 0)
122 // || localName == NodeTest.WILD
123 // || namespace == NodeTest.WILD)
125 // return traverser.first(current);
129 // int type = getNodeTypeTest(what);
130 // int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
131 // return traverser.first(current, extendedType);
136 * Get the next node via getFirstAttribute && getNextAttribute.
138 protected int getNextNode()
140 m_lastFetched = (DTM.NULL == m_lastFetched)
141 ? m_traverser.first(m_context)
142 : m_traverser.next(m_context, m_lastFetched);
143 return m_lastFetched;
147 * Returns the axis being iterated, if it is known.
149 * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
158 * @see Expression#deepEquals(Expression)
160 public boolean deepEquals(Expression expr)
162 if(!super.deepEquals(expr))
165 if(m_axis != ((OneStepIteratorForward)expr).m_axis)