1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.om.NamePool; 4 import net.sf.saxon.om.SequenceIterator; 5 import net.sf.saxon.trans.DynamicError; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.AnyItemType; 8 import net.sf.saxon.type.ItemType; 9 10 import java.io.PrintStream ; 11 12 13 18 19 public class ErrorExpression extends ComputedExpression { 20 21 private XPathException exception; 23 27 28 public ErrorExpression(XPathException exception) { 29 this.exception = exception; 30 exception.setLocator(this); }; 32 33 36 37 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 38 return this; 39 } 40 41 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 42 return this; 43 } 44 45 49 50 public Item evaluateItem(XPathContext context) throws XPathException { 51 DynamicError err = new DynamicError(exception.getMessage()); 53 err.setLocator(ExpressionTool.getLocator(this)); 54 err.setErrorCode(exception.getErrorCodeLocalPart()); 55 err.setXPathContext(context); 56 throw err; 57 } 58 59 63 64 public SequenceIterator iterate(XPathContext context) throws XPathException { 65 evaluateItem(context); 66 return null; } 68 69 73 74 public ItemType getItemType() { 75 return AnyItemType.getInstance(); 76 } 77 78 81 82 public int computeCardinality() { 83 return StaticProperty.ALLOWS_ZERO_OR_MORE; 84 } 87 88 91 92 public void display(int level, NamePool pool, PrintStream out) { 93 out.println(ExpressionTool.indent(level) + "**ERROR** (" + exception.getMessage() + ')'); 94 } 95 96 } 97 98 | Popular Tags |