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: Expression.java 468655 2006-10-28 07:12:06Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xpath; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.ErrorListener; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException; 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTM; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMIterator; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.XMLString; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XNodeSet; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XObject; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.res.XPATHErrorResources; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.ContentHandler; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This abstract class serves as the base for all expression objects. An 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Expression can be executed to return a {@link org.apache.xpath.objects.XObject}, 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * normally has a location within a document or DOM, can send error and warning 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * events, and normally do not hold state and are meant to be immutable once 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * construction has completed. An exception to the immutibility rule is iterators 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and walkers, which must be cloned in order to be used -- the original must 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * still be immutable. 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic abstract class Expression implements java.io.Serializable, ExpressionNode, XPathVisitable 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static final long serialVersionUID = 565665869777906902L; 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The location where this expression was built from. Need for diagnostic 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * messages. May be null. 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @serial 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private ExpressionNode m_parent; 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell if this expression or it's subexpressions can traverse outside 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the current subtree. 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if traversal outside the context node's subtree can occur. 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean canTraverseOutsideSubtree() 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// /** 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// * Set the location where this expression was built from. 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// * 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// * 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// * @param locator the location where this expression was built from, may be 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// * null. 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// */ 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// public void setSourceLocator(SourceLocator locator) 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// { 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// m_slocator = locator; 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// } 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute an expression in the XPath runtime context, and return the 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * result of the expression. 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param currentNode The currentNode. 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The result of the expression in the form of a <code>XObject</code>. 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if a runtime exception 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * occurs. 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XObject execute(XPathContext xctxt, int currentNode) 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // For now, the current node is already pushed. 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt); 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute an expression in the XPath runtime context, and return the 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * result of the expression. 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param currentNode The currentNode. 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param dtm The DTM of the current node. 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param expType The expanded type ID of the current node. 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The result of the expression in the form of a <code>XObject</code>. 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if a runtime exception 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * occurs. 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XObject execute( 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPathContext xctxt, int currentNode, DTM dtm, int expType) 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // For now, the current node is already pushed. 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt); 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute an expression in the XPath runtime context, and return the 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * result of the expression. 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The result of the expression in the form of a <code>XObject</code>. 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if a runtime exception 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * occurs. 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public abstract XObject execute(XPathContext xctxt) 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException; 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute an expression in the XPath runtime context, and return the 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * result of the expression, but tell that a "safe" object doesn't have 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to be returned. The default implementation just calls execute(xctxt). 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param destructiveOK true if a "safe" object doesn't need to be returned. 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The result of the expression in the form of a <code>XObject</code>. 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if a runtime exception 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * occurs. 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XObject execute(XPathContext xctxt, boolean destructiveOK) 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt); 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Evaluate expression to a number. 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The expression evaluated as a double. 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public double num(XPathContext xctxt) 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt).num(); 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Evaluate expression to a boolean. 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return false 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean bool(XPathContext xctxt) 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt).bool(); 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Cast result object to a string. 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The string this wraps or the empty string if null 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XMLString xstr(XPathContext xctxt) 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt).xstr(); 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell if the expression is a nodeset expression. In other words, tell 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if you can execute {@link #asNode(XPathContext) asNode} without an exception. 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if the expression can be represented as a nodeset. 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isNodesetExpr() 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the first node out of the nodeset, if this expression is 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a nodeset expression. 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return the first node out of the nodeset, or DTM.NULL. 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int asNode(XPathContext xctxt) 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTMIterator iter = execute(xctxt).iter(); 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return iter.nextNode(); 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Given an select expression and a context, evaluate the XPath 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and return the resulting iterator. 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The execution context. 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param contextNode The node that "." expresses. 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A valid DTMIterator. 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException thrown if the active ProblemListener decides 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the error condition is severe enough to halt processing. 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage experimental 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMIterator asIterator(XPathContext xctxt, int contextNode) 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xctxt.pushCurrentNodeAndExpression(contextNode, contextNode); 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return execute(xctxt).iter(); 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson finally 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xctxt.popCurrentNodeAndExpression(); 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Given an select expression and a context, evaluate the XPath 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and return the resulting iterator, but do not clone. 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The execution context. 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param contextNode The node that "." expresses. 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A valid DTMIterator. 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException thrown if the active ProblemListener decides 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the error condition is severe enough to halt processing. 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage experimental 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode) 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xctxt.pushCurrentNodeAndExpression(contextNode, contextNode); 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XNodeSet nodeset = (XNodeSet)execute(xctxt); 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return nodeset.iterRaw(); 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson finally 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xctxt.popCurrentNodeAndExpression(); 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute an expression in the XPath runtime context, and return the 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * result of the expression. 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NEEDSDOC @param handler 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The result of the expression in the form of a <code>XObject</code>. 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException if a runtime exception 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * occurs. 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws org.xml.sax.SAXException 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void executeCharsToContentHandler( 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPathContext xctxt, ContentHandler handler) 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException, 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson org.xml.sax.SAXException 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XObject obj = execute(xctxt); 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson obj.dispatchCharactersEvents(handler); 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson obj.detach(); 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell if this expression returns a stable number that will not change during 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * iterations within the expression. This is used to determine if a proximity 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * position predicate can indicate that no more searching has to occur. 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if the expression represents a stable number. 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isStableNumber() 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This function is used to fixup variables from QNames to stack frame 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * indexes at stylesheet build time. 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param vars List of QNames that correspond to variables. This list 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * should be searched backwards for the first qualified name that 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * corresponds to the variable reference qname. The position of the 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * QName in the vector from the start of the vector will be its position 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in the stack frame (but variables above the globalsTop value will need 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to be offset to the current stack frame). 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NEEDSDOC @param globalsSize 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public abstract void fixupVariables(java.util.Vector vars, int globalsSize); 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compare this object with another object and see 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if they are equal, include the sub heararchy. 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param expr Another expression object. 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if this objects class and the expr 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * object's class are the same, and the data contained 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * within both objects are considered equal. 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public abstract boolean deepEquals(Expression expr); 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This is a utility method to tell if the passed in 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * class is the same class as this. It is to be used by 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the deepEquals method. I'm bottlenecking it here 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * because I'm not totally confident that comparing the 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * class objects is the best way to do this. 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true of the passed in class is the exact same 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * class as this class. 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected final boolean isSameClass(Expression expr) 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == expr) 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (getClass() == expr.getClass()); 3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Warn the user of an problem. 3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg An error msgkey that corresponds to one of the conststants found 3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in {@link org.apache.xpath.res.XPATHErrorResources}, which is 3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a key for a format string. 3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args An array of arguments represented in the format string, which 3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may be null. 3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if the current ErrorListoner determines to 3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * throw an exception. 3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void warn(XPathContext xctxt, String msg, Object[] args) 3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String fmsg = XSLMessages.createXPATHWarning(msg, args); 3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != xctxt) 3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener eh = xctxt.getErrorListener(); 3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // TO DO: Need to get stylesheet Locator from here. 3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson eh.warning(new TransformerException(fmsg, xctxt.getSAXLocator())); 4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an assertion error, and probably throw an 4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param b If false, a runtime exception will be thrown. 4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg The assertion message, which should be informative. 4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws RuntimeException if the b argument is false. 4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void assertion(boolean b, java.lang.String msg) 4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!b) 4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String fMsg = XSLMessages.createXPATHMessage( 4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, 4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ msg }); 4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new RuntimeException(fMsg); 4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an error, and probably throw an 4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime context. 4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg An error msgkey that corresponds to one of the constants found 4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in {@link org.apache.xpath.res.XPATHErrorResources}, which is 4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a key for a format string. 4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args An array of arguments represented in the format string, which 4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may be null. 4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws TransformerException if the current ErrorListoner determines to 4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * throw an exception. 4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void error(XPathContext xctxt, String msg, Object[] args) 4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args); 4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != xctxt) 4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener eh = xctxt.getErrorListener(); 4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerException te = new TransformerException(fmsg, this); 4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson eh.fatalError(te); 4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the first non-Expression parent of this node. 4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return null or first ancestor that is not an Expression. 4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public ExpressionNode getExpressionOwner() 4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ExpressionNode parent = exprGetParent(); 4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while((null != parent) && (parent instanceof Expression)) 4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson parent = parent.exprGetParent(); 4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return parent; 4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //=============== ExpressionNode methods ================ 4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** This pair of methods are used to inform the node of its 4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson parent. */ 4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void exprSetParent(ExpressionNode n) 4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson assertion(n != this, "Can not parent an expression to itself!"); 4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_parent = n; 4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public ExpressionNode exprGetParent() 4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_parent; 4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** This method tells the node to add its argument to the node's 4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson list of children. */ 4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void exprAddChild(ExpressionNode n, int i) 4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson assertion(false, "exprAddChild method not implemented!"); 4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** This method returns a child node. The children are numbered 4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson from zero, left to right. */ 4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public ExpressionNode exprGetChild(int i) 4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** Return the number of children the node has. */ 5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int exprGetNumChildren() 5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return 0; 5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //=============== SourceLocator methods ================ 5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the public identifier for the current document event. 5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The return value is the public identifier of the document 5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * entity or of the external parsed entity in which the markup that 5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * triggered the event appears.</p> 5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A string containing the public identifier, or 5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * null if none is available. 5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see #getSystemId 5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getPublicId() 5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == m_parent) 5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_parent.getPublicId(); 5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the system identifier for the current document event. 5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The return value is the system identifier of the document 5299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * entity or of the external parsed entity in which the markup that 5309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * triggered the event appears.</p> 5319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>If the system identifier is a URL, the parser must resolve it 5339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * fully before passing it to the application.</p> 5349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A string containing the system identifier, or null 5369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if none is available. 5379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see #getPublicId 5389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getSystemId() 5409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == m_parent) 5429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 5439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_parent.getSystemId(); 5449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the line number where the current document event ends. 5489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p><strong>Warning:</strong> The return value from the method 5509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is intended only as an approximation for the sake of error 5519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * reporting; it is not intended to provide sufficient information 5529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to edit the character content of the original XML document.</p> 5539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The return value is an approximation of the line number 5559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in the document entity or external parsed entity where the 5569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * markup that triggered the event appears.</p> 5579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The line number, or -1 if none is available. 5599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see #getColumnNumber 5609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getLineNumber() 5629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == m_parent) 5649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return 0; 5659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_parent.getLineNumber(); 5669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the character position where the current document event ends. 5709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p><strong>Warning:</strong> The return value from the method 5729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is intended only as an approximation for the sake of error 5739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * reporting; it is not intended to provide sufficient information 5749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to edit the character content of the original XML document.</p> 5759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The return value is an approximation of the column number 5779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in the document entity or external parsed entity where the 5789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * markup that triggered the event appears.</p> 5799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 5809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The column number, or -1 if none is available. 5819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see #getLineNumber 5829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getColumnNumber() 5849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 5859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if(null == m_parent) 5869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return 0; 5879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return m_parent.getColumnNumber(); 5889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 590