Debian Codegraph @

net/sf/saxon/style/XSLWithParam.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.style;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.expr.instruct.WithParam;
12 import net.sf.saxon.om.AxisInfo;
13 import net.sf.saxon.om.Item;
14 import net.sf.saxon.trans.XPathException;
15 import net.sf.saxon.tree.iter.AxisIterator;
16 import net.sf.saxon.value.SequenceType;
17
18 /**
19 * An xsl:with-param element in the stylesheet. <br>
20 * The xsl:with-param element has mandatory attribute name and optional attribute select
21 */
22
23 public class XSLWithParam extends XSLGeneralVariable {
24
25 private int allowedAttributes =
26 SourceBinding.SELECT | SourceBinding.AS | SourceBinding.TUNNEL;
27
28 @Override
29 protected void prepareAttributes() throws XPathException {
30 sourceBinding.prepareAttributes(allowedAttributes);
31 }
32
33 public boolean isTunnelParam() {
34 return sourceBinding.hasProperty(SourceBinding.TUNNEL);
35 }
36
37 public void validate(ComponentDeclaration decl) throws XPathException {
38 super.validate(decl);
39
40 // Check for duplicate parameter names
41
42 AxisIterator iter = iterateAxis(AxisInfo.PRECEDING_SIBLING);
43 Item prev;
44 while ((prev = iter.next()) != null) {
45 if (prev instanceof XSLWithParam) {
46 if (sourceBinding.getVariableQName().equals(((XSLWithParam) prev).sourceBinding.getVariableQName())) {
47 compileError("Duplicate parameter name", "XTSE0670");
48 }
49 }
50 }
51 }
52
53 public void checkAgainstRequiredType(SequenceType required) throws XPathException {
54 sourceBinding.checkAgainstRequiredType(required);
55 }
56
57 /*@NotNull*/
58 public WithParam compileWithParam(Expression parent, Compilation exec, ComponentDeclaration decl) throws XPathException {
59
60 sourceBinding.handleSequenceConstructor(exec, decl);
61
62 WithParam inst = new WithParam();
63 inst.setSelectExpression(parent, sourceBinding.getSelectExpression());
64 inst.setVariableQName(sourceBinding.getVariableQName());
65 inst.setRequiredType(sourceBinding.getInferredType(true));
66 return inst;
67 }
68
69 }
70