Debian Codegraph @

net/sf/saxon/trans/rules/ShallowSkipRuleSet.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.trans.rules;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.expr.XPathContextMajor;
12 import net.sf.saxon.expr.instruct.ParameterSet;
13 import net.sf.saxon.expr.instruct.TailCall;
14 import net.sf.saxon.expr.parser.Location;
15 import net.sf.saxon.ma.arrays.ArrayFunctionSet;
16 import net.sf.saxon.ma.arrays.ArrayItem;
17 import net.sf.saxon.om.*;
18 import net.sf.saxon.trans.XPathException;
19 import net.sf.saxon.type.Type;
20
21 /**
22 * A built-in set of template rules that ignores the current node and does an apply-templates
23 * to its children.
24 */
25 public class ShallowSkipRuleSet implements BuiltInRuleSet {
26
27 private static ShallowSkipRuleSet THE_INSTANCE = new ShallowSkipRuleSet();
28
29 /**
30 * Get the singleton instance of this class
31 *
32 * @return the singleton instance
33 */
34
35 public static ShallowSkipRuleSet getInstance() {
36 return THE_INSTANCE;
37 }
38
39 private ShallowSkipRuleSet() {
40 }
41
42 /**
43 * Perform the built-in template action for a given item.
44 *
45 * @param item the item to be processed
46 * @param parameters the parameters supplied to apply-templates
47 * @param tunnelParams the tunnel parameters to be passed through
48 * @param context the dynamic evaluation context
49 * @param locationId location of the instruction (apply-templates, apply-imports etc) that caused
50 * the built-in template to be invoked
51 * @throws XPathException if any dynamic error occurs
52 */
53
54 public void process(Item item, ParameterSet parameters,
55 ParameterSet tunnelParams, /*@NotNull*/ XPathContext context,
56 Location locationId) throws XPathException {
57 if (item instanceof NodeInfo) {
58 NodeInfo node = (NodeInfo) item;
59 switch (node.getNodeKind()) {
60 case Type.ELEMENT: {
61 XPathContextMajor c2 = context.newContext();
62 c2.setOrigin(this);
63 c2.trackFocus(node.iterateAxis(AxisInfo.ATTRIBUTE));
64 c2.setCurrentComponent(c2.getCurrentMode()); // Bug 3508
65 TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId);
66 while (tc != null) {
67 tc = tc.processLeavingTail();
68 }
69 } // fall through!
70 case Type.DOCUMENT: {
71 XPathContextMajor c2 = context.newContext();
72 c2.setOrigin(this);
73 c2.trackFocus(node.iterateAxis(AxisInfo.CHILD));
74 c2.setCurrentComponent(c2.getCurrentMode()); // Bug 3508
75 TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId);
76 while (tc != null) {
77 tc = tc.processLeavingTail();
78 }
79 return;
80 }
81 case Type.TEXT:
82 case Type.ATTRIBUTE:
83 case Type.COMMENT:
84 case Type.PROCESSING_INSTRUCTION:
85 case Type.NAMESPACE:
86 // no action
87 }
88 } else if (item instanceof ArrayItem) {
89 Sequence<?> seq = ArrayFunctionSet.ArrayToSequence.toSequence((ArrayItem) item);
90 SequenceIterator<?> members = seq.iterate();
91 XPathContextMajor c2 = context.newContext();
92 c2.setOrigin(this);
93 c2.trackFocus(members);
94 c2.setCurrentComponent(c2.getCurrentMode()); // Bug 3508
95 TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId);
96 while (tc != null) {
97 tc = tc.processLeavingTail();
98 }
99 } else {
100 // no action (e.g. for atomic values and function items
101 }
102 }
103
104
105 /**
106 * Identify this built-in rule set
107 *
108 * @return "shallow-skip"
109 */
110
111 @Override
112 public String getName() {
113 return "shallow-skip";
114 }
115
116 /**
117 * Get the default action for unmatched nodes
118 *
119 * @param nodeKind the node kind
120 * @return the default action for unmatched nodes: one of DEEP_COPY, APPLY_TEMPLATES, DEEP_SKIP, FAIL
121 */
122 public int[] getActionForParentNodes(int nodeKind) {
123 return new int[]{APPLY_TEMPLATES_TO_ATTRIBUTES, APPLY_TEMPLATES_TO_CHILDREN};
124 }
125 }
126