Debian Codegraph @

net/sf/saxon/style/XSLMap.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.Literal;
12 import net.sf.saxon.expr.StaticProperty;
13 import net.sf.saxon.expr.instruct.SequenceInstr;
14 import net.sf.saxon.expr.parser.RoleDiagnostic;
15 import net.sf.saxon.expr.parser.TypeChecker;
16 import net.sf.saxon.lib.Feature;
17 import net.sf.saxon.ma.map.HashTrieMap;
18 import net.sf.saxon.ma.map.MapFunctionSet;
19 import net.sf.saxon.ma.map.MapType;
20 import net.sf.saxon.om.AttributeCollection;
21 import net.sf.saxon.trans.XPathException;
22 import net.sf.saxon.type.ItemType;
23 import net.sf.saxon.value.SequenceType;
24 import net.sf.saxon.value.StringValue;
25
26 /**
27 * Handler for xsl:map instructions in an XSLT 3.0 stylesheet. <br>
28 */
29
30 public class XSLMap extends StyleElement {
31
32 Expression select = null;
33
34 /**
35 * Determine whether this node is an instruction.
36 *
37 * @return true - it is an instruction
38 */
39
40 public boolean isInstruction() {
41 return true;
42 }
43
44 /**
45 * Determine the type of item returned by this instruction (only relevant if
46 * it is an instruction).
47 *
48 * @return the item type returned
49 */
50
51 protected ItemType getReturnedItemType() {
52 return MapType.ANY_MAP_TYPE;
53 }
54
55 /**
56 * Determine whether this type of element is allowed to contain a sequence constructor
57 *
58 * @return true: yes, it may contain a sequence constructor
59 */
60
61 public boolean mayContainSequenceConstructor() {
62 return true;
63 }
64
65 public void prepareAttributes() throws XPathException {
66 AttributeCollection atts = getAttributeList();
67
68 for (int a = 0; a < atts.getLength(); a++) {
69 String f = atts.getQName(a);
70 checkUnknownAttribute(atts.getNodeName(a));
71 }
72 }
73
74 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
75 select = compileSequenceConstructor(exec, decl, false);
76 select = select.simplify();
77 // Custom type-checking; the checking performed by map:merge() gives poor diagnostics
78 TypeChecker tc = getConfiguration().getTypeChecker(false);
79 RoleDiagnostic role = new RoleDiagnostic(RoleDiagnostic.MISC, "xsl:map sequence constructor", 0);
80 role.setErrorCode("XTTE3375");
81 select = tc.staticTypeCheck(
82 select,
83 SequenceType.makeSequenceType(MapType.ANY_MAP_TYPE, StaticProperty.ALLOWS_ZERO_OR_MORE),
84 role, makeExpressionVisitor());
85 HashTrieMap options = new HashTrieMap();
86 options.initialPut(new StringValue("duplicates"), new StringValue("reject"));
87 options.initialPut(new StringValue("duplicates-error-code"), new StringValue("XTDE3365"));
88 Expression exp = MapFunctionSet.getInstance().makeFunction("merge", 2).makeFunctionCall(select, Literal.makeLiteral(options));
89 if (getConfiguration().getBooleanProperty(Feature.STRICT_STREAMABILITY)) {
90 exp = new SequenceInstr(exp);
91 }
92 return exp;
93 }
94
95 }