1 16 19 package org.apache.xpath; 20 21 import javax.xml.transform.ErrorListener ; 22 import javax.xml.transform.TransformerException ; 23 24 import org.apache.xalan.res.XSLMessages; 25 import org.apache.xml.dtm.DTM; 26 import org.apache.xml.dtm.DTMIterator; 27 import org.apache.xml.utils.XMLString; 28 import org.apache.xpath.objects.XNodeSet; 29 import org.apache.xpath.objects.XObject; 30 import org.apache.xpath.res.XPATHErrorResources; 31 32 import org.xml.sax.ContentHandler ; 33 34 43 public abstract class Expression implements java.io.Serializable , ExpressionNode, XPathVisitable 44 { 45 46 51 private ExpressionNode m_parent; 52 53 59 public boolean canTraverseOutsideSubtree() 60 { 61 return false; 62 } 63 64 76 89 public XObject execute(XPathContext xctxt, int currentNode) 90 throws javax.xml.transform.TransformerException 91 { 92 93 return execute(xctxt); 95 } 96 97 112 public XObject execute( 113 XPathContext xctxt, int currentNode, DTM dtm, int expType) 114 throws javax.xml.transform.TransformerException 115 { 116 117 return execute(xctxt); 119 } 120 121 133 public abstract XObject execute(XPathContext xctxt) 134 throws javax.xml.transform.TransformerException ; 135 136 150 public XObject execute(XPathContext xctxt, boolean destructiveOK) 151 throws javax.xml.transform.TransformerException 152 { 153 return execute(xctxt); 154 } 155 156 157 166 public double num(XPathContext xctxt) 167 throws javax.xml.transform.TransformerException 168 { 169 return execute(xctxt).num(); 170 } 171 172 181 public boolean bool(XPathContext xctxt) 182 throws javax.xml.transform.TransformerException 183 { 184 return execute(xctxt).bool(); 185 } 186 187 196 public XMLString xstr(XPathContext xctxt) 197 throws javax.xml.transform.TransformerException 198 { 199 return execute(xctxt).xstr(); 200 } 201 202 207 public boolean isNodesetExpr() 208 { 209 return false; 210 } 211 212 220 public int asNode(XPathContext xctxt) 221 throws javax.xml.transform.TransformerException 222 { 223 DTMIterator iter = execute(xctxt).iter(); 224 return iter.nextNode(); 225 } 226 227 242 public DTMIterator asIterator(XPathContext xctxt, int contextNode) 243 throws javax.xml.transform.TransformerException 244 { 245 246 try 247 { 248 xctxt.pushCurrentNodeAndExpression(contextNode, contextNode); 249 250 return execute(xctxt).iter(); 251 } 252 finally 253 { 254 xctxt.popCurrentNodeAndExpression(); 255 } 256 } 257 258 273 public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode) 274 throws javax.xml.transform.TransformerException 275 { 276 277 try 278 { 279 xctxt.pushCurrentNodeAndExpression(contextNode, contextNode); 280 281 XNodeSet nodeset = (XNodeSet)execute(xctxt); 282 return nodeset.iterRaw(); 283 } 284 finally 285 { 286 xctxt.popCurrentNodeAndExpression(); 287 } 288 } 289 290 291 305 public void executeCharsToContentHandler( 306 XPathContext xctxt, ContentHandler handler) 307 throws javax.xml.transform.TransformerException , 308 org.xml.sax.SAXException 309 { 310 311 XObject obj = execute(xctxt); 312 313 obj.dispatchCharactersEvents(handler); 314 obj.detach(); 315 } 316 317 325 public boolean isStableNumber() 326 { 327 return false; 328 } 329 330 341 public abstract void fixupVariables(java.util.Vector vars, int globalsSize); 342 343 352 public abstract boolean deepEquals(Expression expr); 353 354 363 protected final boolean isSameClass(Expression expr) 364 { 365 if(null == expr) 366 return false; 367 368 return (getClass() == expr.getClass()); 369 } 370 371 386 public void warn(XPathContext xctxt, String msg, Object [] args) 387 throws javax.xml.transform.TransformerException 388 { 389 390 java.lang.String fmsg = XSLMessages.createXPATHWarning(msg, args); 391 392 if (null != xctxt) 393 { 394 ErrorListener eh = xctxt.getErrorListener(); 395 396 eh.warning(new TransformerException (fmsg, xctxt.getSAXLocator())); 398 } 399 } 400 401 412 public void assertion(boolean b, java.lang.String msg) 413 { 414 415 if (!b) 416 { 417 java.lang.String fMsg = XSLMessages.createXPATHMessage( 418 XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, 419 new Object []{ msg }); 420 421 throw new RuntimeException (fMsg); 422 } 423 } 424 425 441 public void error(XPathContext xctxt, String msg, Object [] args) 442 throws javax.xml.transform.TransformerException 443 { 444 445 java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args); 446 447 if (null != xctxt) 448 { 449 ErrorListener eh = xctxt.getErrorListener(); 450 TransformerException te = new TransformerException (fmsg, this); 451 452 eh.fatalError(te); 453 } 454 } 455 456 460 public ExpressionNode getExpressionOwner() 461 { 462 ExpressionNode parent = exprGetParent(); 463 while((null != parent) && (parent instanceof Expression)) 464 parent = parent.exprGetParent(); 465 return parent; 466 } 467 468 470 472 public void exprSetParent(ExpressionNode n) 473 { 474 assertion(n != this, "Can not parent an expression to itself!"); 475 m_parent = n; 476 } 477 478 public ExpressionNode exprGetParent() 479 { 480 return m_parent; 481 } 482 483 485 public void exprAddChild(ExpressionNode n, int i) 486 { 487 assertion(false, "exprAddChild method not implemented!"); 488 } 489 490 492 public ExpressionNode exprGetChild(int i) 493 { 494 return null; 495 } 496 497 498 public int exprGetNumChildren() 499 { 500 return 0; 501 } 502 503 505 516 public String getPublicId() 517 { 518 if(null == m_parent) 519 return null; 520 return m_parent.getPublicId(); 521 } 522 523 537 public String getSystemId() 538 { 539 if(null == m_parent) 540 return null; 541 return m_parent.getSystemId(); 542 } 543 544 559 public int getLineNumber() 560 { 561 if(null == m_parent) 562 return 0; 563 return m_parent.getLineNumber(); 564 } 565 566 581 public int getColumnNumber() 582 { 583 if(null == m_parent) 584 return 0; 585 return m_parent.getColumnNumber(); 586 } 587 } 588 | Popular Tags |