19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: FilterExprWalker.java 469367 2006-10-31 04:41:08Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xpath.axes; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.Axis; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTM; 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMIterator; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.Expression; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.ExpressionOwner; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathContext; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathVisitor; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.compiler.Compiler; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.compiler.OpCodes; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XNodeSet; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Walker for the OP_VARIABLE, or OP_EXTFUNCTION, or OP_FUNCTION, or OP_GROUP, 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * op codes. 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xpath#NT-FilterExpr">XPath FilterExpr descriptions</a> 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class FilterExprWalker extends AxesWalker 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static final long serialVersionUID = 5457182471424488375L; 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Construct a FilterExprWalker using a LocPathIterator. 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param locPathIterator non-null reference to the parent iterator. 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public FilterExprWalker(WalkingIterator locPathIterator) 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super(locPathIterator, Axis.FILTEREDLIST); 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Init a FilterExprWalker. 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param compiler non-null reference to the Compiler that is constructing. 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos positive opcode position for this step. 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param stepType The type of step. 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void init(Compiler compiler, int opPos, int stepType) 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super.init(compiler, opPos, stepType); 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Smooth over an anomily in the opcode map... 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (stepType) 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_FUNCTION : 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_EXTFUNCTION : 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_mustHardReset = true; 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_GROUP : 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_VARIABLE : 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr = compiler.compile(opPos); 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr.exprSetParent(this); 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof org.apache.xalan.templates.FuncKey)) 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(m_expr instanceof org.apache.xpath.operations.Variable) 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // hack/temp workaround 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_canDetachNodeset = false; 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default : 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr = compiler.compile(opPos + 2); 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr.exprSetParent(this); 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// if(m_expr instanceof WalkingIterator) 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// { 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// WalkingIterator wi = (WalkingIterator)m_expr; 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// if(wi.getFirstWalker() instanceof FilterExprWalker) 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// { 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker(); 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// if(null == fw.getNextWalker()) 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// { 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// m_expr = fw.m_expr; 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// m_expr.exprSetParent(this); 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// } 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// } 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// } 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Detaches the walker from the set which it iterated over, releasing 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * any computational resources and placing the iterator in the INVALID 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * state. 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void detach() 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super.detach(); 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (m_canDetachNodeset) 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_exprObj.detach(); 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_exprObj = null; 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the root node of the TreeWalker. 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param root non-null reference to the root, or starting point of 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the query. 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setRoot(int root) 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super.setRoot(root); 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_exprObj = FilterExprIteratorSimple.executeFilterExpr(root, 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_lpi.getXPathContext(), m_lpi.getPrefixResolver(), 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_lpi.getIsTopLevel(), m_lpi.m_stackFrame, m_expr); 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get a cloned FilterExprWalker. 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A new FilterExprWalker that can be used without mutating this one. 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws CloneNotSupportedException 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object clone() throws CloneNotSupportedException 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson FilterExprWalker clone = (FilterExprWalker) super.clone(); 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != m_exprObj) 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson clone.m_exprObj = (XNodeSet) m_exprObj.clone(); 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return clone; 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method needs to override AxesWalker.acceptNode because FilterExprWalkers 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * don't need to, and shouldn't, do a node test. 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param n The node to check to see if it passes the filter or not. 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return a constant to determine whether the node is accepted, 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * rejected, or skipped, as defined above . 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public short acceptNode(int n) 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getPredicateCount() > 0) 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson countProximityPosition(0); 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!executePredicates(n, m_lpi.getXPathContext())) 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMIterator.FILTER_SKIP; 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMIterator.FILTER_ACCEPT; 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (javax.xml.transform.TransformerException se) 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new RuntimeException(se.getMessage()); 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Moves the <code>TreeWalker</code> to the next visible node in document 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * order relative to the current node, and returns the new node. If the 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * current node has no next node, or if the search for nextNode attempts 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to step upward from the TreeWalker's root node, returns 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>null</code> , and retains the current node. 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The new node, or <code>null</code> if the current node has no 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * next node in the TreeWalker's logical view. 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getNextNode() 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != m_exprObj) 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int next = m_exprObj.nextNode(); 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return next; 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTM.NULL; 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the index of the last node that can be itterated to. 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt XPath runtime context. 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return the index of the last node that can be itterated to. 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getLastPos(XPathContext xctxt) 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_exprObj.getLength(); 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The contained expression. Should be non-null. 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @serial */ 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Expression m_expr; 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The result of executing m_expr. Needs to be deep cloned on clone op. */ 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson transient private XNodeSet m_exprObj; 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_mustHardReset = false; 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean m_canDetachNodeset = true; 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This function is used to fixup variables from QNames to stack frame 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * indexes at stylesheet build time. 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param vars List of QNames that correspond to variables. This list 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * should be searched backwards for the first qualified name that 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * corresponds to the variable reference qname. The position of the 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * QName in the vector from the start of the vector will be its position 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in the stack frame (but variables above the globalsTop value will need 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to be offset to the current stack frame). 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void fixupVariables(java.util.Vector vars, int globalsSize) 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super.fixupVariables(vars, globalsSize); 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr.fixupVariables(vars, globalsSize); 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the inner contained expression of this filter. 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression getInnerExpression() 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_expr; 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the inner contained expression of this filter. 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setInnerExpression(Expression expr) 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr.exprSetParent(this); 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr = expr; 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the analysis bits for this walker, as defined in the WalkerFactory. 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return One of WalkerFactory#BIT_DESCENDANT, etc. 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getAnalysisBits() 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != m_expr && m_expr instanceof PathComponent) 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ((PathComponent) m_expr).getAnalysisBits(); 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return WalkerFactory.BIT_FILTER; 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns true if all the nodes in the iteration well be returned in document 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * order. 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Warning: This can only be called after setRoot has been called! 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true as a default. 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isDocOrdered() 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_exprObj.isDocOrdered(); 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the axis being iterated, if it is known. 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * types. 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getAxis() 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_exprObj.getAxis(); 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson class filterExprOwner implements ExpressionOwner 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see ExpressionOwner#getExpression() 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression getExpression() 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_expr; 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see ExpressionOwner#setExpression(Expression) 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setExpression(Expression exp) 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson exp.exprSetParent(FilterExprWalker.this); 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr = exp; 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This will traverse the heararchy, calling the visitor for 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * each member. If the called visitor method returns 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * false, the subtree should not be called. 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param visitor The visitor whose appropriate method will be called. 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void callPredicateVisitors(XPathVisitor visitor) 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_expr.callVisitors(new filterExprOwner(), visitor); 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super.callPredicateVisitors(visitor); 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see Expression#deepEquals(Expression) 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean deepEquals(Expression expr) 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!super.deepEquals(expr)) 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson FilterExprWalker walker = (FilterExprWalker)expr; 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(!m_expr.deepEquals(walker.m_expr)) 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return true; 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 350