Debian Codegraph @

net/sf/saxon/expr/instruct/AttributeSet.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.expr.StaticProperty;
11 import net.sf.saxon.expr.XPathContext;
12 import net.sf.saxon.om.StandardNames;
13 import net.sf.saxon.om.StructuredQName;
14 import net.sf.saxon.trace.ExpressionPresenter;
15 import net.sf.saxon.trace.LocationKind;
16 import net.sf.saxon.trans.SymbolicName;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.trans.XsltController;
19
20 import java.util.Stack;
21
22 /**
23 * The compiled form of an xsl:attribute-set element in the stylesheet.
24 */
25
26 public class AttributeSet extends Actor {
27
28 StructuredQName attributeSetName;
29 private boolean declaredStreamable;
30
31 /**
32 * Create an empty attribute set
33 */
34
35 public AttributeSet() {
36 }
37
38 /**
39 * Get the symbolic name of the component
40 *
41 * @return the symbolic name
42 */
43 @Override
44 public SymbolicName getSymbolicName() {
45 return new SymbolicName(StandardNames.XSL_ATTRIBUTE_SET, attributeSetName);
46 }
47
48 /**
49 * Set the name of the attribute-set
50 *
51 * @param attributeSetName the name of the attribute-set
52 */
53
54 public void setName(StructuredQName attributeSetName) {
55 this.attributeSetName = attributeSetName;
56 }
57
58 /**
59 * Say whether this attribute set is declared to be streamable
60 * @param value true if the attribute streamable="yes" is present
61 */
62
63 public void setDeclaredStreamable(boolean value) {
64 this.declaredStreamable = value;
65 }
66
67 /**
68 * Ask whether this attribute set is declared to be streamable
69 * @return true if the attribute streamable="yes" is present
70 */
71
72 public boolean isDeclaredStreamable() {
73 return this.declaredStreamable;
74 }
75
76 /**
77 * Set the stack frame map which allocates slots to variables declared in this attribute set
78 *
79 * @param stackFrameMap the stack frame map
80 */
81
82 public void setStackFrameMap(/*@Nullable*/ SlotManager stackFrameMap) {
83 if (stackFrameMap != null) {
84 super.setStackFrameMap(stackFrameMap);
85 }
86 }
87
88 /**
89 * Determine whether the attribute set has any dependencies on the focus
90 *
91 * @return the dependencies
92 */
93
94 public int getFocusDependencies() {
95 return body.getDependencies() & StaticProperty.DEPENDS_ON_FOCUS;
96 }
97
98 /**
99 * Evaluate an attribute set
100 *
101 * @param context the dynamic context
102 * @throws XPathException if any failure occurs
103 */
104
105 public void expand(XPathContext context) throws XPathException {
106 Stack<AttributeSet> stack = ((XsltController)context.getController()).getAttributeSetEvaluationStack();
107 if (stack.contains(this)) {
108 throw new XPathException("Attribute set " + getObjectName().getEQName() + " invokes itself recursively", "XTDE0640");
109 }
110 stack.push(this);
111 getBody().process(context);
112 stack.pop();
113 if (stack.isEmpty()) {
114 ((XsltController)context.getController()).releaseAttributeSetEvaluationStack();
115 }
116 }
117
118 /**
119 * Get the type of construct. This will either be the fingerprint of a standard XSLT instruction name
120 * (values in {@link net.sf.saxon.om.StandardNames}: all less than 1024)
121 * or it will be a constant in class {@link LocationKind}.
122 */
123
124 public int getConstructType() {
125 return StandardNames.XSL_ATTRIBUTE_SET;
126 }
127
128 /**
129 * Get a name identifying the object of the expression, for example a function name, template name,
130 * variable name, key name, element name, etc. This is used only where the name is known statically.
131 */
132
133 public StructuredQName getObjectName() {
134 return attributeSetName;
135 }
136
137 public int getComponentKind() {
138 return StandardNames.XSL_ATTRIBUTE_SET;
139 }
140
141 /**
142 * Diagnostic print of expression structure. The abstract expression tree
143 * is written to the supplied outputstream.
144 *
145 * @param presenter the expression presenter used to display the structure
146 */
147 @Override
148 public void export(ExpressionPresenter presenter) throws XPathException {
149 presenter.startElement("attributeSet");
150 presenter.emitAttribute("name", getObjectName());
151 presenter.emitAttribute("line", getLineNumber() + "");
152 presenter.emitAttribute("module", getSystemId());
153 presenter.emitAttribute("slots", getStackFrameMap().getNumberOfVariables() + "");
154 presenter.emitAttribute("binds", getDeclaringComponent().getComponentBindings().size() + "");
155 if (isDeclaredStreamable()) {
156 presenter.emitAttribute("flags", "s");
157 }
158 getBody().export(presenter);
159 presenter.endElement();
160 }
161
162
163 }
164