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: Compiler.java 468655 2006-10-28 07:12:06Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xpath.compiler; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.ErrorListener; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.SourceLocator; 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.Axis; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMFilter; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMIterator; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.PrefixResolver; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.QName; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.SAXSourceLocator; 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.Expression; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.axes.UnionPathIterator; 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.axes.WalkerFactory; 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.FuncExtFunction; 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.FuncExtFunctionAvailable; 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.Function; 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.WrongNumberArgsException; 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XNumber; 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XString; 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.And; 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Div; 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Equals; 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Gt; 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Gte; 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Lt; 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Lte; 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Minus; 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Mod; 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Mult; 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Neg; 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.NotEquals; 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Operation; 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Or; 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Plus; 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.UnaryOperation; 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.operations.Variable; 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.patterns.FunctionPattern; 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.patterns.NodeTest; 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.patterns.StepPattern; 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.patterns.UnionPattern; 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.res.XPATHErrorResources; 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * An instance of this class compiles an XPath string expression into 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a Expression object. This class compiles the string into a sequence 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of operation codes (op map) and then builds from that into an Expression 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * tree. 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class Compiler extends OpMap 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Construct a Compiler object with a specific ErrorListener and 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * SourceLocator where the expression is located. 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param errorHandler Error listener where messages will be sent, or null 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if messages should be sent to System err. 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param locator The location object where the expression lives, which 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may be null, but which, if not null, must be valid over 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the long haul, in other words, it will not be cloned. 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param fTable The FunctionTable object where the xpath build-in 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * functions are stored. 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Compiler(ErrorListener errorHandler, SourceLocator locator, 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson FunctionTable fTable) 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_errorHandler = errorHandler; 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_locator = locator; 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_functionTable = fTable; 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Construct a Compiler instance that has a null error listener and a 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * null source locator. 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Compiler() 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_errorHandler = null; 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_locator = null; 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute the XPath object from a given opcode position. 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the xpath.m_opMap array. 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The result of the XPath. 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if there is a syntax or other error. 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression compile(int opPos) throws TransformerException 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int op = getOp(opPos); 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Expression expr = null; 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println(getPatternString()+"op: "+op); 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (op) 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_XPATH : 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = compile(opPos + 2); break; 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_OR : 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = or(opPos); break; 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_AND : 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = and(opPos); break; 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_NOTEQUALS : 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = notequals(opPos); break; 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_EQUALS : 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = equals(opPos); break; 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_LTE : 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = lte(opPos); break; 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_LT : 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = lt(opPos); break; 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_GTE : 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = gte(opPos); break; 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_GT : 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = gt(opPos); break; 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_PLUS : 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = plus(opPos); break; 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_MINUS : 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = minus(opPos); break; 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_MULT : 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = mult(opPos); break; 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_DIV : 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = div(opPos); break; 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_MOD : 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = mod(opPos); break; 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// case OpCodes.OP_QUO : 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// expr = quo(opPos); break; 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_NEG : 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = neg(opPos); break; 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_STRING : 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = string(opPos); break; 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_BOOL : 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = bool(opPos); break; 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_NUMBER : 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = number(opPos); break; 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_UNION : 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = union(opPos); break; 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_LITERAL : 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = literal(opPos); break; 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_VARIABLE : 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = variable(opPos); break; 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_GROUP : 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = group(opPos); break; 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_NUMBERLIT : 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = numberlit(opPos); break; 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_ARGUMENT : 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = arg(opPos); break; 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_EXTFUNCTION : 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = compileExtension(opPos); break; 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_FUNCTION : 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = compileFunction(opPos); break; 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_LOCATIONPATH : 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = locationPath(opPos); break; 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_PREDICATE : 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = null; break; // should never hit this here. 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_MATCHPATTERN : 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = matchPattern(opPos + 2); break; 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_LOCATIONPATHPATTERN : 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson expr = locationPathPattern(opPos); break; 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_QUO: 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(XPATHErrorResources.ER_UNKNOWN_OPCODE, 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ "quo" }); //"ERROR! Unknown op code: "+m_opMap[opPos]); 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default : 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(XPATHErrorResources.ER_UNKNOWN_OPCODE, 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ Integer.toString(getOp(opPos)) }); //"ERROR! Unknown op code: "+m_opMap[opPos]); 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// if(null != expr) 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// expr.setSourceLocator(m_locator); 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return expr; 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Bottle-neck compilation of an operation with left and right operands. 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param operation non-null reference to parent operation. 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The op map position of the parent operation. 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Operation} instance. 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if there is a syntax or other error. 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Expression compileOperation(Operation operation, int opPos) 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int leftPos = getFirstChildPos(opPos); 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int rightPos = getNextOpPos(leftPos); 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson operation.setLeftRight(compile(leftPos), compile(rightPos)); 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return operation; 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Bottle-neck compilation of a unary operation. 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param unary The parent unary operation. 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The position in the op map of the parent operation. 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The unary argument. 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if syntax or other error occurs. 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Expression compileUnary(UnaryOperation unary, int opPos) 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int rightPos = getFirstChildPos(opPos); 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson unary.setRight(compile(rightPos)); 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return unary; 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile an 'or' operation. 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Or} instance. 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression or(int opPos) throws TransformerException 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Or(), opPos); 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile an 'and' operation. 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.And} instance. 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression and(int opPos) throws TransformerException 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new And(), opPos); 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '!=' operation. 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.NotEquals} instance. 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression notequals(int opPos) throws TransformerException 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new NotEquals(), opPos); 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '=' operation. 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Equals} instance. 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression equals(int opPos) throws TransformerException 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Equals(), opPos); 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '<=' operation. 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Lte} instance. 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression lte(int opPos) throws TransformerException 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Lte(), opPos); 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '<' operation. 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Lt} instance. 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression lt(int opPos) throws TransformerException 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Lt(), opPos); 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '>=' operation. 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Gte} instance. 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression gte(int opPos) throws TransformerException 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Gte(), opPos); 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '>' operation. 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Gt} instance. 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression gt(int opPos) throws TransformerException 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Gt(), opPos); 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '+' operation. 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Plus} instance. 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression plus(int opPos) throws TransformerException 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Plus(), opPos); 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '-' operation. 3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Minus} instance. 3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression minus(int opPos) throws TransformerException 3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Minus(), opPos); 3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a '*' operation. 3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Mult} instance. 3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression mult(int opPos) throws TransformerException 3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Mult(), opPos); 3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a 'div' operation. 3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Div} instance. 4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression div(int opPos) throws TransformerException 4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Div(), opPos); 4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a 'mod' operation. 4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Mod} instance. 4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression mod(int opPos) throws TransformerException 4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileOperation(new Mod(), opPos); 4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /* 4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a 'quo' operation. 4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Quo} instance. 4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// protected Expression quo(int opPos) throws TransformerException 4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// { 4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// return compileOperation(new Quo(), opPos); 4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// } 4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a unary '-' operation. 4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Neg} instance. 4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression neg(int opPos) throws TransformerException 4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileUnary(new Neg(), opPos); 4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a 'string(...)' operation. 4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.String} instance. 4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression string(int opPos) throws TransformerException 4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileUnary(new org.apache.xpath.operations.String(), opPos); 4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a 'boolean(...)' operation. 4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Bool} instance. 4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression bool(int opPos) throws TransformerException 4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileUnary(new org.apache.xpath.operations.Bool(), opPos); 4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a 'number(...)' operation. 4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Number} instance. 4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression number(int opPos) throws TransformerException 4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compileUnary(new org.apache.xpath.operations.Number(), opPos); 4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a literal string value. 4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.objects.XString} instance. 5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression literal(int opPos) 5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPos(opPos); 5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (XString) getTokenQueue().elementAt(getOp(opPos)); 5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a literal number value. 5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.objects.XNumber} instance. 5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression numberlit(int opPos) 5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPos(opPos); 5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (XNumber) getTokenQueue().elementAt(getOp(opPos)); 5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a variable reference. 5309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 5329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.operations.Variable} instance. 5349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 5369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression variable(int opPos) throws TransformerException 5389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Variable var = new Variable(); 5419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPos(opPos); 5439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int nsPos = getOp(opPos); 5459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String namespace 5469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson = (OpCodes.EMPTY == nsPos) ? null 5479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson : (java.lang.String) getTokenQueue().elementAt(nsPos); 5489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String localname 5499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson = (java.lang.String) getTokenQueue().elementAt(getOp(opPos+1)); 5509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson QName qname = new QName(namespace, localname); 5519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson var.setQName(qname); 5539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return var; 5559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile an expression group. 5599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 5619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to the contained expression. 5639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 5659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression group(int opPos) throws TransformerException 5679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // no-op 5709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compile(opPos + 2); 5719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a function argument. 5759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 5779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to the argument expression. 5799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 5819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression arg(int opPos) throws TransformerException 5839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // no-op 5869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compile(opPos + 2); 5879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a location path union. The UnionPathIterator itself may create 5919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link org.apache.xpath.axes.LocPathIterator} children. 5929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 5949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.axes.LocPathIterator} instance. 5969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 5989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression union(int opPos) throws TransformerException 6009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locPathDepth++; 6029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 6039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return UnionPathIterator.createUnionIterator(this, opPos); 6059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson finally 6079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locPathDepth--; 6099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private int locPathDepth = -1; 6139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the level of the location path or union being constructed. 6169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return 0 if it is a top-level path. 6179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getLocationPathDepth() 6199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return locPathDepth; 6219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the function table 6259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson FunctionTable getFunctionTable() 6279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_functionTable; 6299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a location path. The LocPathIterator itself may create 6339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link org.apache.xpath.axes.AxesWalker} children. 6349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 6369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.axes.LocPathIterator} instance. 6389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 6409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression locationPath(int opPos) throws TransformerException 6429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locPathDepth++; 6449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 6459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTMIterator iter = WalkerFactory.newDTMIterator(this, opPos, (locPathDepth == 0)); 6479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (Expression)iter; // cast OK, I guess. 6489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson finally 6509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locPathDepth--; 6529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a location step predicate expression. 6579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 6599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return the contained predicate expression. 6619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 6639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression predicate(int opPos) throws TransformerException 6659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compile(opPos + 2); 6679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile an entire match pattern expression. 6719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 6739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.patterns.UnionPattern} instance. 6759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 6769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 6779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected Expression matchPattern(int opPos) throws TransformerException 6799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locPathDepth++; 6819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 6829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // First, count... 6849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int nextOpPos = opPos; 6859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int i; 6869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (i = 0; getOp(nextOpPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++) 6889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 6899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson nextOpPos = getNextOpPos(nextOpPos); 6909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (i == 1) 6939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return compile(opPos); 6949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson UnionPattern up = new UnionPattern(); 6969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StepPattern[] patterns = new StepPattern[i]; 6979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (i = 0; getOp(opPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++) 6999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson nextOpPos = getNextOpPos(opPos); 7019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson patterns[i] = (StepPattern) compile(opPos); 7029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = nextOpPos; 7039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson up.setPatterns(patterns); 7069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return up; 7089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson finally 7109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson locPathDepth--; 7129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 7169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a location match pattern unit expression. 7179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 7199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.patterns.StepPattern} instance. 7219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 7239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 7249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression locationPathPattern(int opPos) 7259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 7269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPos(opPos); 7299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return stepPattern(opPos, 0, null); 7319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 7349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get a {@link org.w3c.dom.traversal.NodeFilter} bit set that tells what 7359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to show for a given node test. 7369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos the op map position for the location step. 7389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 7399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return {@link org.w3c.dom.traversal.NodeFilter} bit set that tells what 7409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to show for a given node test. 7419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 7429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getWhatToShow(int opPos) 7439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int axesType = getOp(opPos); 7469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int testType = getOp(opPos + 3); 7479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("testType: "+testType); 7499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (testType) 7509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODETYPE_COMMENT : 7529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_COMMENT; 7539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODETYPE_TEXT : 7549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// return DTMFilter.SHOW_TEXT | DTMFilter.SHOW_COMMENT; 7559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_TEXT | DTMFilter.SHOW_CDATA_SECTION ; 7569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODETYPE_PI : 7579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_PROCESSING_INSTRUCTION; 7589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODETYPE_NODE : 7599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// return DTMFilter.SHOW_ALL; 7609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (axesType) 7619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_NAMESPACE: 7639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_NAMESPACE; 7649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_ATTRIBUTES : 7659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_ATTRIBUTE : 7669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_ATTRIBUTE; 7679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_SELF: 7689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_ANCESTORS_OR_SELF: 7699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_DESCENDANTS_OR_SELF: 7709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_ALL; 7719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default: 7729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getOp(0) == OpCodes.OP_MATCHPATTERN) 7739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ~DTMFilter.SHOW_ATTRIBUTE 7749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson & ~DTMFilter.SHOW_DOCUMENT 7759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson & ~DTMFilter.SHOW_DOCUMENT_FRAGMENT; 7769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 7779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ~DTMFilter.SHOW_ATTRIBUTE; 7789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 7799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODETYPE_ROOT : 7809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT; 7819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODETYPE_FUNCTEST : 7829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return NodeTest.SHOW_BYFUNCTION; 7839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.NODENAME : 7849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (axesType) 7859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 7869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_NAMESPACE : 7879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_NAMESPACE; 7889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_ATTRIBUTES : 7899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_ATTRIBUTE : 7909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_ATTRIBUTE; 7919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // break; 7939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_ANY_ANCESTOR : 7949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_IMMEDIATE_ANCESTOR : 7959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_ELEMENT; 7969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 7979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // break; 7989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default : 7999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_ELEMENT; 8009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default : 8029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.err.println("We should never reach here."); 8039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return DTMFilter.SHOW_ALL; 8049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonprivate static final boolean DEBUG = false; 8089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 8109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a step pattern unit expression, used for both location paths 8119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and match patterns. 8129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 8149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param stepCount The number of steps to expect. 8159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param ancestorPattern The owning StepPattern, which may be null. 8169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.patterns.StepPattern} instance. 8189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 8199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 8209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 8219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected StepPattern stepPattern( 8229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int opPos, int stepCount, StepPattern ancestorPattern) 8239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 8249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int startOpPos = opPos; 8279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int stepType = getOp(opPos); 8289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (OpCodes.ENDOP == stepType) 8309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 8329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 8339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean addMagicSelf = true; 8359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int endStep = getNextOpPos(opPos); 8379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // int nextStepType = getOpMap()[endStep]; 8399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StepPattern pattern; 8409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // boolean isSimple = ((OpCodes.ENDOP == nextStepType) && (stepCount == 0)); 8429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int argLen; 8439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 8449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (stepType) 8459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 8469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.OP_FUNCTION : 8479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(DEBUG) 8489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println("MATCH_FUNCTION: "+m_currentPattern); 8499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson addMagicSelf = false; 8509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson argLen = getOp(opPos + OpMap.MAPINDEX_LENGTH); 8519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern = new FunctionPattern(compileFunction(opPos), Axis.PARENT, Axis.CHILD); 8529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 8539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.FROM_ROOT : 8549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(DEBUG) 8559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println("FROM_ROOT, "+m_currentPattern); 8569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson addMagicSelf = false; 8579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson argLen = getArgLengthOfStep(opPos); 8589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPosOfStep(opPos); 8599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern = new StepPattern(DTMFilter.SHOW_DOCUMENT | 8609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTMFilter.SHOW_DOCUMENT_FRAGMENT, 8619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Axis.PARENT, Axis.CHILD); 8629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 8639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_ATTRIBUTE : 8649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(DEBUG) 8659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println("MATCH_ATTRIBUTE: "+getStepLocalName(startOpPos)+", "+m_currentPattern); 8669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson argLen = getArgLengthOfStep(opPos); 8679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPosOfStep(opPos); 8689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern = new StepPattern(DTMFilter.SHOW_ATTRIBUTE, 8699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStepNS(startOpPos), 8709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStepLocalName(startOpPos), 8719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Axis.PARENT, Axis.ATTRIBUTE); 8729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 8739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_ANY_ANCESTOR : 8749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(DEBUG) 8759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println("MATCH_ANY_ANCESTOR: "+getStepLocalName(startOpPos)+", "+m_currentPattern); 8769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson argLen = getArgLengthOfStep(opPos); 8779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPosOfStep(opPos); 8789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int what = getWhatToShow(startOpPos); 8799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // bit-o-hackery, but this code is due for the morgue anyway... 8809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(0x00000500 == what) 8819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson addMagicSelf = false; 8829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern = new StepPattern(getWhatToShow(startOpPos), 8839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStepNS(startOpPos), 8849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStepLocalName(startOpPos), 8859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Axis.ANCESTOR, Axis.CHILD); 8869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 8879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case OpCodes.MATCH_IMMEDIATE_ANCESTOR : 8889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(DEBUG) 8899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println("MATCH_IMMEDIATE_ANCESTOR: "+getStepLocalName(startOpPos)+", "+m_currentPattern); 8909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson argLen = getArgLengthOfStep(opPos); 8919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPosOfStep(opPos); 8929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern = new StepPattern(getWhatToShow(startOpPos), 8939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStepNS(startOpPos), 8949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson getStepLocalName(startOpPos), 8959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Axis.PARENT, Axis.CHILD); 8969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 8979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default : 8989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(XPATHErrorResources.ER_UNKNOWN_MATCH_OPERATION, null); //"unknown match operation!"); 8999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 9019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern.setPredicates(getCompiledPredicates(opPos + argLen)); 9049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == ancestorPattern) 9059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // This is the magic and invisible "." at the head of every 9079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // match pattern, and corresponds to the current node in the context 9089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // list, from where predicates are counted. 9099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // So, in order to calculate "foo[3]", it has to count from the 9109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // current node in the context list, so, from that current node, 9119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // the full pattern is really "self::node()/child::foo[3]". If you 9129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // translate this to a select pattern from the node being tested, 9139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // which is really how we're treating match patterns, it works out to 9149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // self::foo/parent::node[child::foo[3]]", or close enough. 9159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /* if(addMagicSelf && pattern.getPredicateCount() > 0) 9169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StepPattern selfPattern = new StepPattern(DTMFilter.SHOW_ALL, 9189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Axis.PARENT, Axis.CHILD); 9199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // We need to keep the new nodetest from affecting the score... 9209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XNumber score = pattern.getStaticScore(); 9219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern.setRelativePathPattern(selfPattern); 9229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern.setStaticScore(score); 9239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson selfPattern.setStaticScore(score); 9249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson }*/ 9259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 9279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("Setting "+ancestorPattern+" as relative to "+pattern); 9299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern.setRelativePathPattern(ancestorPattern); 9309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StepPattern relativePathPattern = stepPattern(endStep, stepCount + 1, 9339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson pattern); 9349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (null != relativePathPattern) ? relativePathPattern : pattern; 9369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 9399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a zero or more predicates for a given match pattern. 9409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The position of the first predicate the m_opMap array. 9429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to array of {@link org.apache.xpath.Expression} instances. 9449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 9469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 9479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Expression[] getCompiledPredicates(int opPos) 9489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 9499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int count = countPredicates(opPos); 9529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (count > 0) 9549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Expression[] predicates = new Expression[count]; 9569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson compilePredicates(opPos, predicates); 9589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return predicates; 9609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 9639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 9669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Count the number of predicates in the step. 9679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The position of the first predicate the m_opMap array. 9699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The number of predicates for this step. 9719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 9739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 9749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int countPredicates(int opPos) throws TransformerException 9759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int count = 0; 9789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while (OpCodes.OP_PREDICATE == getOp(opPos)) 9809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 9819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson count++; 9829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getNextOpPos(opPos); 9849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return count; 9879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 9889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 9899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 9909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compiles predicates in the step. 9919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The position of the first predicate the m_opMap array. 9939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param predicates An empty pre-determined array of 9949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link org.apache.xpath.Expression}s, that will be filled in. 9959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 9969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException 9979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 9989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private void compilePredicates(int opPos, Expression[] predicates) 9999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 10009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i = 0; OpCodes.OP_PREDICATE == getOp(opPos); i++) 10039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson predicates[i] = predicate(opPos); 10059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getNextOpPos(opPos); 10069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile a built-in XPath function. 10119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 10139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.functions.Function} instance. 10159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 10179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Expression compileFunction(int opPos) throws TransformerException 10199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int endFunc = opPos + getOp(opPos + 1) - 1; 10229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPos(opPos); 10249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int funcID = getOp(opPos); 10269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos++; 10289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (-1 != funcID) 10309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Function func = m_functionTable.getFunction(funcID); 10329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * It is a trick for function-available. Since the function table is an 10359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * instance field, insert this table at compilation time for later usage 10369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (func instanceof FuncExtFunctionAvailable) 10399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((FuncExtFunctionAvailable) func).setFunctionTable(m_functionTable); 10409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson func.postCompileStep(this); 10429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 10449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int i = 0; 10469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int p = opPos; p < endFunc; p = getNextOpPos(p), i++) 10489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("argPos: "+ p); 10519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("argCode: "+ m_opMap[p]); 10529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson func.setArg(compile(p), i); 10539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson func.checkNumberArgs(i); 10569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (WrongNumberArgsException wnae) 10589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String name = m_functionTable.getFunctionName(funcID); 10609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_errorHandler.fatalError( new TransformerException( 10629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ONLY_ALLOWS, 10639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{name, wnae.getMessage()}), m_locator)); 10649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //"name + " only allows " + wnae.getMessage() + " arguments", m_locator)); 10659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return func; 10689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 10709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(XPATHErrorResources.ER_FUNCTION_TOKEN_NOT_FOUND, null); //"function token not found."); 10729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 10749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // The current id for extension functions. 10789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private static long s_nextMethodId = 0; 10799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the next available method id 10829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 10839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson synchronized private long getNextMethodId() 10849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 10859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (s_nextMethodId == Long.MAX_VALUE) 10869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson s_nextMethodId = 0; 10879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return s_nextMethodId++; 10899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 10909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 10919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 10929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compile an extension function. 10939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param opPos The current position in the m_opMap array. 10959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return reference to {@link org.apache.xpath.functions.FuncExtFunction} instance. 10979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 10989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if a error occurs creating the Expression. 10999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Expression compileExtension(int opPos) 11019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws TransformerException 11029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int endExtFunc = opPos + getOp(opPos + 1) - 1; 11059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = getFirstChildPos(opPos); 11079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String ns = (java.lang.String) getTokenQueue().elementAt(getOp(opPos)); 11099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos++; 11119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String funcName = 11139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson (java.lang.String) getTokenQueue().elementAt(getOp(opPos)); 11149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos++; 11169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // We create a method key to uniquely identify this function so that we 11189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // can cache the object needed to invoke it. This way, we only pay the 11199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // reflection overhead on the first call. 11209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Function extension = new FuncExtFunction(ns, funcName, String.valueOf(getNextMethodId())); 11229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 11249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int i = 0; 11269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while (opPos < endExtFunc) 11289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int nextOpPos = getNextOpPos(opPos); 11309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson extension.setArg(this.compile(opPos), i); 11329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson opPos = nextOpPos; 11349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson i++; 11369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (WrongNumberArgsException wnae) 11399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ; // should never happen 11419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return extension; 11449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Warn the user of an problem. 11489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg An error msgkey that corresponds to one of the constants found 11509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in {@link org.apache.xpath.res.XPATHErrorResources}, which is 11519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a key for a format string. 11529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args An array of arguments represented in the format string, which 11539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may be null. 11549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if the current ErrorListoner determines to 11569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * throw an exception. 11579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void warn(String msg, Object[] args) throws TransformerException 11599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String fmsg = XSLMessages.createXPATHWarning(msg, args); 11629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != m_errorHandler) 11649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_errorHandler.warning(new TransformerException(fmsg, m_locator)); 11669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 11689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println(fmsg 11709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson +"; file "+m_locator.getSystemId() 11719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson +"; line "+m_locator.getLineNumber() 11729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson +"; column "+m_locator.getColumnNumber()); 11739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an assertion error, and probably throw an 11789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 11799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param b If false, a runtime exception will be thrown. 11819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg The assertion message, which should be informative. 11829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 11839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws RuntimeException if the b argument is false. 11849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 11859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void assertion(boolean b, java.lang.String msg) 11869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!b) 11899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 11909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String fMsg = XSLMessages.createXPATHMessage( 11919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, 11929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ msg }); 11939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new RuntimeException(fMsg); 11959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 11979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 11989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 11999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an error, and probably throw an 12009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 12019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg An error msgkey that corresponds to one of the constants found 12039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in {@link org.apache.xpath.res.XPATHErrorResources}, which is 12049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a key for a format string. 12059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args An array of arguments represented in the format string, which 12069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may be null. 12079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if the current ErrorListoner determines to 12099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * throw an exception. 12109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void error(String msg, Object[] args) throws TransformerException 12129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args); 12159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != m_errorHandler) 12189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_errorHandler.fatalError(new TransformerException(fmsg, m_locator)); 12209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 12229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println(te.getMessage() 12259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // +"; file "+te.getSystemId() 12269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // +"; line "+te.getLineNumber() 12279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // +"; column "+te.getColumnNumber()); 12289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException(fmsg, (SAXSourceLocator)m_locator); 12299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The current prefixResolver for the execution context. 12349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private PrefixResolver m_currentPrefixResolver = null; 12369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current namespace context for the xpath. 12399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The current prefix resolver, *may* be null, though hopefully not. 12419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public PrefixResolver getNamespaceContext() 12439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_currentPrefixResolver; 12459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the current namespace context for the xpath. 12499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 12509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param pr The resolver for prefixes in the XPath expression. 12519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setNamespaceContext(PrefixResolver pr) 12539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 12549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_currentPrefixResolver = pr; 12559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 12569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The error listener where errors will be sent. If this is null, errors 12589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and warnings will be sent to System.err. May be null. */ 12599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener m_errorHandler; 12609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The source locator for the expression being compiled. May be null. */ 12629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SourceLocator m_locator; 12639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 12649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 12659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The FunctionTable for all xpath build-in functions 12669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 12679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private FunctionTable m_functionTable; 12689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 1269