Debian Codegraph @

net/sf/saxon/functions/StaticContextAccessor.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.Expression;
11 import net.sf.saxon.expr.Literal;
12 import net.sf.saxon.expr.XPathContext;
13 import net.sf.saxon.expr.parser.RetainedStaticContext;
14 import net.sf.saxon.om.Sequence;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.value.AnyURIValue;
17 import net.sf.saxon.value.AtomicValue;
18 import net.sf.saxon.value.StringValue;
19
20 /**
21 * A StaticContextAccessor is a function that takes no arguments, but operates implicitly on the
22 * static context. In the case of a dynamic call, the context that is used is the one at the point
23 * where the function item is created.
24 */
25
26 public abstract class StaticContextAccessor extends SystemFunction {
27
28 /**
29 * Method to do the actual evaluation, which must be implemented in a subclass
30 * @param rsc the retained static context
31 * @return the result of the evaluation
32 */
33
34 public abstract AtomicValue evaluate(RetainedStaticContext rsc);
35
36 /**
37 * Evaluate the expression
38 *
39 * @param context the dynamic evaluation context
40 * @param arguments the values of the arguments, supplied as Sequences
41 * @return the result of the evaluation, in the form of a Sequence
42 * @throws net.sf.saxon.trans.XPathException
43 * if a dynamic error occurs during the evaluation of the expression
44 */
45 public AtomicValue call(XPathContext context, Sequence[] arguments) throws XPathException {
46 return evaluate(getRetainedStaticContext());
47 }
48
49 @Override
50 public Expression makeFunctionCall(Expression[] arguments) {
51 return Literal.makeLiteral(evaluate(getRetainedStaticContext()));
52 }
53
54 /**
55 * Implement the XPath function static-base-uri()
56 */
57
58 public static class StaticBaseUri extends StaticContextAccessor {
59 @Override
60 public AtomicValue evaluate(RetainedStaticContext rsc) {
61 return new AnyURIValue(rsc.getStaticBaseUriString());
62 }
63 }
64
65 /**
66 * Implement the XPath function default-collation()
67 */
68
69 public static class DefaultCollation extends StaticContextAccessor {
70 @Override
71 public AtomicValue evaluate(RetainedStaticContext rsc) {
72 return new StringValue(rsc.getDefaultCollationName());
73 }
74 }
75
76 }
77