| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.instruct; |
| 9 |
|
| 10 |
import net.sf.saxon.Controller; |
| 11 |
import net.sf.saxon.expr.Component; |
| 12 |
import net.sf.saxon.expr.Expression; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.expr.XPathContextMajor; |
| 15 |
import net.sf.saxon.expr.parser.ExpressionTool; |
| 16 |
import net.sf.saxon.expr.parser.RebindingMap; |
| 17 |
import net.sf.saxon.om.Item; |
| 18 |
import net.sf.saxon.om.StandardNames; |
| 19 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 20 |
import net.sf.saxon.trans.Mode; |
| 21 |
import net.sf.saxon.trans.rules.Rule; |
| 22 |
import net.sf.saxon.trans.XPathException; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class ApplyImports extends ApplyNextMatchingTemplate implements ITemplateCall { |
| 30 |
|
| 31 |
public ApplyImports() { |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public int getInstructionNameCode() { |
| 38 |
return StandardNames.XSL_APPLY_IMPORTS; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public Expression copy(RebindingMap rebindings) { |
| 50 |
ApplyImports ai2 = new ApplyImports(); |
| 51 |
ai2.setActualParams(WithParam.copy(ai2, getActualParams(), rebindings)); |
| 52 |
ai2.setTunnelParams(WithParam.copy(ai2, getTunnelParams(), rebindings)); |
| 53 |
ExpressionTool.copyLocationInfo(this, ai2); |
| 54 |
return ai2; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
public TailCall processLeavingTail(XPathContext context) throws XPathException { |
| 59 |
|
| 60 |
Controller controller = context.getController(); |
| 61 |
assert controller != null; |
| 62 |
|
| 63 |
|
| 64 |
ParameterSet params = assembleParams(context, getActualParams()); |
| 65 |
ParameterSet tunnels = assembleTunnelParams(context, getTunnelParams()); |
| 66 |
|
| 67 |
Rule currentTemplateRule = context.getCurrentTemplateRule(); |
| 68 |
if (currentTemplateRule == null) { |
| 69 |
XPathException e = new XPathException("There is no current template rule"); |
| 70 |
e.setXPathContext(context); |
| 71 |
e.setErrorCode("XTDE0560"); |
| 72 |
e.setLocation(getLocation()); |
| 73 |
throw e; |
| 74 |
} |
| 75 |
|
| 76 |
int min = currentTemplateRule.getMinImportPrecedence(); |
| 77 |
int max = currentTemplateRule.getPrecedence() - 1; |
| 78 |
Component.M modeComponent = context.getCurrentMode(); |
| 79 |
if (modeComponent == null) { |
| 80 |
throw new AssertionError("Current mode is null"); |
| 81 |
} |
| 82 |
Item currentItem = context.getCurrentIterator().current(); |
| 83 |
|
| 84 |
Mode mode = modeComponent.getActor(); |
| 85 |
Rule rule = mode.getRule(currentItem, min, max, context); |
| 86 |
if (rule == null) { |
| 87 |
mode.getBuiltInRuleSet().process(currentItem, params, tunnels, context, getLocation()); |
| 88 |
} else { |
| 89 |
XPathContextMajor c2 = context.newContext(); |
| 90 |
TemplateRule nh = (TemplateRule) rule.getAction(); |
| 91 |
nh.initialize(); |
| 92 |
c2.setOrigin(this); |
| 93 |
|
| 94 |
c2.setLocalParameters(params); |
| 95 |
c2.setTunnelParameters(tunnels); |
| 96 |
c2.openStackFrame(nh.getStackFrameMap()); |
| 97 |
c2.setCurrentTemplateRule(rule); |
| 98 |
c2.setCurrentComponent(modeComponent); |
| 99 |
nh.apply(c2); |
| 100 |
} |
| 101 |
return null; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public void export(ExpressionPresenter out) throws XPathException { |
| 111 |
out.startElement("applyImports", this); |
| 112 |
out.emitAttribute("flags", "i"); |
| 113 |
if (getActualParams().length != 0) { |
| 114 |
WithParam.exportParameters(getActualParams(), out, false); |
| 115 |
} |
| 116 |
if (getTunnelParams().length != 0) { |
| 117 |
WithParam.exportParameters(getTunnelParams(), out, true); |
| 118 |
} |
| 119 |
out.endElement(); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
@Override |
| 130 |
public String getStreamerName() { |
| 131 |
return "ApplyImports"; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
} |
| 136 |
|