Debian Codegraph @

net/sf/saxon/functions/FunctionLibrary.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.Configuration;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.StaticContext;
13 import net.sf.saxon.om.Function;
14 import net.sf.saxon.trans.SymbolicName;
15 import net.sf.saxon.trans.XPathException;
16
17 import java.util.List;
18
19 /**
20 * A FunctionLibrary handles the binding of function calls in XPath (or XQuery) expressions.
21 * There are a number of implementations of this
22 * class to handle different kinds of function: system functions, constructor functions, vendor-defined
23 * functions, Java extension functions, stylesheet functions, and so on. There is also an implementation
24 * {@link net.sf.saxon.functions.FunctionLibraryList} that allows a FunctionLibrary
25 * to be constructed by combining other FunctionLibrary objects.
26 */
27
28 public interface FunctionLibrary {
29
30 default void setConfiguration(Configuration config) {}
31
32 /**
33 * Test whether a function with a given name and arity is available
34 * <p>This supports the function-available() function in XSLT.</p>
35 *
36 * @param functionName the qualified name of the function being called, together with its arity.
37 * For legacy reasons, the arity may be set to -1 to mean any arity will do
38 * @return true if a function of this name and arity is available for calling
39 */
40
41 /*@Nullable*/
42 boolean isAvailable(SymbolicName.F functionName);
43
44
45 /**
46 * Bind a function, given the URI and local parts of the function name,
47 * and the list of expressions supplied as arguments. This method is called at compile
48 * time.
49 *
50 * @param functionName the QName of the function being called
51 * @param staticArgs May be null; if present, the length of the array must match the
52 * value of arity. Contains the expressions supplied statically in arguments to the function call.
53 * The intention is
54 * that the static type of the arguments (obtainable via getItemType() and getCardinality()) may
55 * be used as part of the binding algorithm. In some cases it may be possible for the function
56 * to be pre-evaluated at compile time, for example if these expressions are all constant values.
57 * <p>The conventions of the XPath language demand that the results of a function depend only on the
58 * values of the expressions supplied as arguments, and not on the form of those expressions. For
59 * example, the result of f(4) is expected to be the same as f(2+2). The actual expression is supplied
60 * here to enable the binding mechanism to select the most efficient possible implementation (including
61 * compile-time pre-evaluation where appropriate).</p>
62 * @param env The static context of the function call
63 * @param reasons If no matching function is found by the function library, it may add
64 * a diagnostic explanation to this list explaining why none of the available
65 * functions could be used.
66 * @return An expression equivalent to a call on the specified function, if one is found;
67 * null if no function was found matching the required name and arity.
68 */
69
70 /*@Nullable*/
71 Expression bind(SymbolicName.F functionName, Expression[] staticArgs, StaticContext env, List<String> reasons);
72
73 /**
74 * This method creates a copy of a FunctionLibrary: if the original FunctionLibrary allows
75 * new functions to be added, then additions to this copy will not affect the original, or
76 * vice versa.
77 *
78 * @return a copy of this function library. This must be an instance of the original class.
79 */
80
81 FunctionLibrary copy();
82
83 //#ifdefined HOF
84
85 /**
86 * Test whether a function with a given name and arity is available; if so, return a function
87 * item that can be dynamically called.
88 * <p>This supports the function-lookup() function in XPath 3.0.</p>
89 *
90 * @param functionName the qualified name of the function being called
91 * @param staticContext the static context to be used by the function, in the event that
92 * it is a system function with dependencies on the static context
93 * @return if a function of this name and arity is available for calling, then a corresponding
94 * function item; or null if the function does not exist
95 * @throws XPathException in the event of certain errors, for example attempting to get a function
96 * that is private
97 */
98
99 /*@Nullable*/
100 Function getFunctionItem(SymbolicName.F functionName, StaticContext staticContext)
101 throws XPathException;
102 //#endif
103
104
105 }