Debian Codegraph @

net/sf/saxon/functions/CurrentMergeKey.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.functions;
9
10 import net.sf.saxon.expr.Callable;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.SystemFunctionCall;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.expr.sort.GroupIterator;
15 import net.sf.saxon.expr.sort.MergeInstr;
16 import net.sf.saxon.om.Sequence;
17 import net.sf.saxon.om.SequenceIterator;
18 import net.sf.saxon.om.SequenceTool;
19 import net.sf.saxon.trans.XPathException;
20 import net.sf.saxon.value.AtomicValue;
21
22
23 /**
24 * Implements the XSLT function current-grouping-key()
25 */
26
27 public class CurrentMergeKey extends SystemFunction implements Callable {
28
29 private MergeInstr controllingInstruction = null; // may be unknown, when current group has dynamic scope
30
31 /**
32 * Set the containing xsl:for-each-group instruction, if there is one
33 *
34 * @param instruction the (innermost) containing xsl:for-each-group instruction
35 */
36
37 public void setControllingInstruction(MergeInstr instruction) {
38 this.controllingInstruction = instruction;
39 }
40
41 /**
42 * Get the innermost containing xsl:merge instruction, if there is one
43 *
44 * @return the innermost containing xsl:merge instruction
45 */
46
47 public MergeInstr getControllingInstruction() {
48 return controllingInstruction;
49 }
50
51
52 /**
53 * Make an expression that either calls this function, or that is equivalent to a call
54 * on this function
55 *
56 * @param arguments the supplied arguments to the function call
57 * @return either a function call on this function, or an expression that delivers
58 * the same result
59 */
60 @Override
61 public Expression makeFunctionCall(Expression... arguments) {
62 return new SystemFunctionCall(this, arguments) {
63 @Override
64 public Expression getScopingExpression() {
65 return getControllingInstruction();
66 }
67 };
68 }
69
70 /**
71 * Evaluate the expression
72 */
73
74 /*@NotNull*/
75 //@Override
76 public SequenceIterator<AtomicValue> iterate(XPathContext c) throws XPathException {
77 GroupIterator gi = c.getCurrentMergeGroupIterator();
78 if (gi == null) {
79 throw new XPathException("There is no current merge key", "XTDE3510");
80 }
81 return gi.getCurrentGroupingKey().iterate();
82
83 }
84
85 /**
86 * Evaluate the expression
87 *
88 * @param context the dynamic evaluation context
89 * @param arguments the values of the arguments, supplied as SequenceIterators
90 * @return the result of the evaluation, in the form of a SequenceIterator
91 * @throws net.sf.saxon.trans.XPathException
92 * if a dynamic error occurs during the evaluation of the expression
93 */
94 public Sequence<AtomicValue> call(XPathContext context, Sequence[] arguments) throws XPathException {
95 return SequenceTool.toLazySequence(iterate(context));
96 }
97
98 }
99
100