1 package net.sf.saxon.instruct; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.expr.XPathContextMajor; 5 import net.sf.saxon.expr.ComputedExpression; 6 import net.sf.saxon.style.StandardNames; 7 import net.sf.saxon.trace.InstructionInfo; 8 import net.sf.saxon.trace.InstructionInfoProvider; 9 import net.sf.saxon.trans.XPathException; 10 11 14 15 public class Template extends Procedure implements InstructionInfoProvider { 16 17 20 private int precedence; 21 private int minImportPrecedence; 22 private int templateFingerprint; 23 private transient InstructionDetails details; 24 25 public Template () { } 26 27 public void init ( int templateFingerprint, 28 int precedence, 29 int minImportPrecedence) { 30 this.templateFingerprint = templateFingerprint; 31 this.precedence = precedence; 32 this.minImportPrecedence = minImportPrecedence; 33 } 34 35 39 40 public int getFingerprint() { 41 return templateFingerprint; 42 } 43 44 public int getPrecedence() { 45 return precedence; 46 } 47 48 public int getMinImportPrecedence() { 49 return minImportPrecedence; 50 } 51 52 57 58 public void process(XPathContext context) throws XPathException { 59 TailCall tc = processLeavingTail(context); 60 while (tc != null) { 61 tc = tc.processLeavingTail(context); 62 } 63 } 64 65 69 70 public TailCall processLeavingTail(XPathContext context) throws XPathException { 71 if (getBody()==null) { 72 return null; 74 } 75 XPathContextMajor c2 = context.newContext(); 76 c2.setOrigin(this); 77 c2.setCurrentTemplate(this); 78 79 TailCall tc = expand(c2); 80 return tc; 81 } 82 83 87 88 public TailCall expand(XPathContext context) throws XPathException { 89 Expression body = getBody(); 90 if (body==null) { 91 return null; 93 } 94 if (body instanceof TailCallReturner) { 95 return ((TailCallReturner)body).processLeavingTail(context); 96 } else { 97 body.process(context); 98 return null; 99 } 100 } 101 102 106 107 public InstructionInfo getInstructionInfo() { 108 if (details==null) { 109 details = new InstructionDetails(); 110 details.setSystemId(getSystemId()); 111 details.setLineNumber(getLineNumber()); 112 details.setConstructType(StandardNames.XSL_TEMPLATE); 113 details.setProperty("template", this); 114 } 115 return details; 116 } 117 118 122 123 public boolean hasBadParentPointer() { 124 return ((ComputedExpression)getBody()).hasBadParentPointer(); 125 } 126 } 127 128 | Popular Tags |