1/* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5/* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22package com.sun.org.apache.xpath.internal.axes; 23 24import com.sun.org.apache.xml.internal.dtm.DTM; 25import com.sun.org.apache.xml.internal.dtm.DTMFilter; 26import com.sun.org.apache.xpath.internal.Expression; 27import com.sun.org.apache.xpath.internal.compiler.Compiler; 28import com.sun.org.apache.xpath.internal.compiler.OpMap; 29 30/** 31 * This class implements a general iterator for 32 * those LocationSteps with only one step, and perhaps a predicate, 33 * that only go forward (i.e. it can not be used with ancestors, 34 * preceding, etc.) 35 * @see com.sun.org.apache.xpath.internal.axes#ChildTestIterator 36 * @xsl.usage advanced 37 */ 38public class OneStepIteratorForward extends ChildTestIterator 39{ 40 static final long serialVersionUID = -1576936606178190566L; 41 /** The traversal axis from where the nodes will be filtered. */ 42 protected int m_axis = -1; 43 44 /** 45 * Create a OneStepIterator object. 46 * 47 * @param compiler A reference to the Compiler that contains the op map. 48 * @param opPos The position within the op map, which contains the 49 * location path expression for this itterator. 50 * 51 * @throws javax.xml.transform.TransformerException 52 */ 53 OneStepIteratorForward(Compiler compiler, int opPos, int analysis) 54 throws javax.xml.transform.TransformerException 55 { 56 super(compiler, opPos, analysis); 57 int firstStepPos = OpMap.getFirstChildPos(opPos); 58 59 m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos); 60 61 } 62 63 /** 64 * Create a OneStepIterator object that will just traverse the self axes. 65 * 66 * @param axis One of the com.sun.org.apache.xml.internal.dtm.Axis integers. 67 * 68 * @throws javax.xml.transform.TransformerException 69 */ 70 public OneStepIteratorForward(int axis) 71 { 72 super(null); 73 74 m_axis = axis; 75 int whatToShow = DTMFilter.SHOW_ALL; 76 initNodeTest(whatToShow); 77 } 78 79 80 81 82 /** 83 * Initialize the context values for this expression 84 * after it is cloned. 85 * 86 * @param context The XPath runtime context for this 87 * transformation. 88 */ 89 public void setRoot(int context, Object environment) 90 { 91 super.setRoot(context, environment); 92 m_traverser = m_cdtm.getAxisTraverser(m_axis); 93 94 } 95 96// /** 97// * Return the first node out of the nodeset, if this expression is 98// * a nodeset expression. This is the default implementation for 99// * nodesets. 100// * <p>WARNING: Do not mutate this class from this function!</p> 101// * @param xctxt The XPath runtime context. 102// * @return the first node out of the nodeset, or DTM.NULL. 103// */ 104// public int asNode(XPathContext xctxt) 105// throws javax.xml.transform.TransformerException 106// { 107// if(getPredicateCount() > 0) 108// return super.asNode(xctxt); 109// 110// int current = xctxt.getCurrentNode(); 111// 112// DTM dtm = xctxt.getDTM(current); 113// DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis); 114// 115// String localName = getLocalName(); 116// String namespace = getNamespace(); 117// int what = m_whatToShow; 118// 119// // System.out.println("what: "); 120// // NodeTest.debugWhatToShow(what); 121// if(DTMFilter.SHOW_ALL == what 122// || ((DTMFilter.SHOW_ELEMENT & what) == 0) 123// || localName == NodeTest.WILD 124// || namespace == NodeTest.WILD) 125// { 126// return traverser.first(current); 127// } 128// else 129// { 130// int type = getNodeTypeTest(what); 131// int extendedType = dtm.getExpandedTypeID(namespace, localName, type); 132// return traverser.first(current, extendedType); 133// } 134// } 135 136 /** 137 * Get the next node via getFirstAttribute && getNextAttribute. 138 */ 139 protected int getNextNode() 140 { 141 m_lastFetched = (DTM.NULL == m_lastFetched) 142 ? m_traverser.first(m_context) 143 : m_traverser.next(m_context, m_lastFetched); 144 return m_lastFetched; 145 } 146 147 /** 148 * Returns the axis being iterated, if it is known. 149 * 150 * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple 151 * types. 152 */ 153 public int getAxis() 154 { 155 return m_axis; 156 } 157 158 /** 159 * @see Expression#deepEquals(Expression) 160 */ 161 public boolean deepEquals(Expression expr) 162 { 163 if(!super.deepEquals(expr)) 164 return false; 165 166 if(m_axis != ((OneStepIteratorForward)expr).m_axis) 167 return false; 168 169 return true; 170 } 171 172 173} 174