1 package net.sf.saxon.instruct; 2 3 import net.sf.saxon.Controller; 4 import net.sf.saxon.expr.*; 5 import net.sf.saxon.om.Item; 6 import net.sf.saxon.om.NamePool; 7 import net.sf.saxon.om.SequenceIterator; 8 import net.sf.saxon.trace.TraceListener; 9 import net.sf.saxon.trans.XPathException; 10 import net.sf.saxon.type.ItemType; 11 12 import java.io.PrintStream ; 13 import java.util.Iterator ; 14 15 19 20 public class TraceWrapper extends Instruction { 21 Expression child; 23 31 32 public Expression simplify(StaticContext env) throws XPathException { 33 child = child.simplify(env); 34 return this; 35 } 36 37 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 38 child = child.typeCheck(env, contextItemType); 39 adoptChildExpression(child); 40 return this; 41 } 42 43 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 44 child = child.optimize(opt, env, contextItemType); 45 adoptChildExpression(child); 46 return this; 47 } 48 49 63 64 public Expression promote(PromotionOffer offer) throws XPathException { 65 Expression newChild = child.promote(offer); 68 if (newChild != child) { 69 child = newChild; 70 adoptChildExpression(child); 71 return this; 72 } 73 return this; 74 } 75 76 84 public TailCall processLeavingTail(XPathContext context) throws XPathException { 85 Controller controller = context.getController(); 86 TraceListener listener = controller.getTraceListener(); 87 if (controller.isTracing()) { 88 listener.enter(getInstructionInfo(), context); 89 } 90 child.process(context); 92 if (controller.isTracing()) { 93 listener.leave(getInstructionInfo()); 94 } 95 return null; 96 } 97 98 102 103 public ItemType getItemType() { 104 return child.getItemType(); 105 } 106 107 118 119 public int getCardinality() { 120 return child.getCardinality(); 121 } 122 123 135 136 public int getDependencies() { 137 return child.getDependencies(); 138 } 139 140 145 146 public final boolean createsNewNodes() { 147 return (child.getSpecialProperties() & StaticProperty.NON_CREATIVE) == 0; 148 } 149 150 157 158 public int computeDependencies() { 159 if (child instanceof ComputedExpression) { 160 return ((ComputedExpression)child).computeDependencies(); 161 } else { 162 return 0; 163 } 164 } 165 166 180 181 public Item evaluateItem(XPathContext context) throws XPathException { 182 Controller controller = context.getController(); 183 if (controller.isTracing()) { 184 controller.getTraceListener().enter(getInstructionInfo(), context); 185 } 186 Item result = child.evaluateItem(context); 187 if (controller.isTracing()) { 188 controller.getTraceListener().leave(getInstructionInfo()); 189 } 190 return result; 191 } 192 193 206 207 public SequenceIterator iterate(XPathContext context) throws XPathException { 208 Controller controller = context.getController(); 209 if (controller.isTracing()) { 210 controller.getTraceListener().enter(getInstructionInfo(), context); 211 } 212 SequenceIterator result = child.iterate(context); 213 if (controller.isTracing()) { 214 controller.getTraceListener().leave(getInstructionInfo()); 215 } 216 return result; 217 } 218 219 public Iterator iterateSubExpressions() { 220 return new MonoIterator(child); 221 } 222 223 public int getInstructionNameCode() { 224 if (child instanceof Instruction) { 225 return ((Instruction)child).getInstructionNameCode(); 226 } else { 227 return -1; 228 } 229 } 230 231 238 239 public void display(int level, NamePool pool, PrintStream out) { 240 child.display(level, pool, out); 241 } 242 } 243 | Popular Tags |