Debian Codegraph @

net/sf/saxon/expr/instruct/ApplyImports.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
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 * An xsl:apply-imports element in the stylesheet.
27 */
28
29 public class ApplyImports extends ApplyNextMatchingTemplate implements ITemplateCall {
30
31 public ApplyImports() {
32 }
33
34 /**
35 * Get the name of this instruction for diagnostic and tracing purposes
36 */
37 public int getInstructionNameCode() {
38 return StandardNames.XSL_APPLY_IMPORTS;
39 }
40
41 /**
42 * Copy an expression. This makes a deep copy.
43 *
44 * @return the copy of the original expression
45 * @param rebindings
46 */
47
48 /*@NotNull*/
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 // handle parameters if any
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) { // use the default action for the node
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 //c2.setOriginatingConstructType(Location.TEMPLATE);
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 // We never treat apply-imports as a tail call, though we could
103 }
104
105 /**
106 * Diagnostic print of expression structure. The abstract expression tree
107 * is written to the supplied output destination.
108 */
109
110 public void export(ExpressionPresenter out) throws XPathException {
111 out.startElement("applyImports", this);
112 out.emitAttribute("flags", "i"); // used to mean "allow any item" i.e. non-nodes
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 * Get the (partial) name of a class that supports streaming of this kind of expression
125 *
126 * @return the partial name of a class that can be instantiated to provide streaming support in Saxon-EE,
127 * or null if there is no such class
128 */
129 @Override
130 public String getStreamerName() {
131 return "ApplyImports";
132 }
133
134
135 }
136