01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.trans.XPathException;
05:
06: import java.io.Serializable;
07:
08: /**
09: * A FunctionLibrary handles the binding of function calls in XPath (or XQuery) expressions.
10: * There are a number of implementations of this
11: * class to handle different kinds of function: system functions, constructor functions, vendor-defined
12: * functions, Java extension functions, stylesheet functions, and so on. There is also an implementation
13: * {@link net.sf.saxon.functions.FunctionLibraryList} that allows a FunctionLibrary
14: * to be constructed by combining other FunctionLibrary objects.
15: */
16:
17: public interface FunctionLibrary extends Serializable {
18:
19: /**
20: * Test whether an extension function with a given name and arity is available. This supports
21: * the function-available() function in XSLT. This method may be called either at compile time
22: * or at run time. If the function library is to be used only in an XQuery or free-standing XPath
23: * environment, this method may throw an UnsupportedOperationException.
24: * @param fingerprint The namepool fingerprint of the function name. This must match the
25: * uri and localName; the information is provided redundantly to avoid repeated lookups in the name pool.
26: * @param uri The URI of the function name
27: * @param local The local part of the function name
28: * @param arity The number of arguments. This is set to -1 in the case of the single-argument
29: * function-available() function; in this case the method should return true if there is some
30: * matching extension function, regardless of its arity.
31: */
32:
33: public boolean isAvailable(int fingerprint, String uri,
34: String local, int arity);
35:
36: /**
37: * Bind an extension function, given the URI and local parts of the function name,
38: * and the list of expressions supplied as arguments. This method is called at compile
39: * time.
40: * @param nameCode The namepool nameCode of the function name. The uri and local name are also
41: * supplied (redundantly) to avoid fetching them from the name pool.
42: * @param uri The URI of the function name
43: * @param local The local part of the function name
44: * @param staticArgs The expressions supplied statically in arguments to the function call.
45: * The length of this array represents the arity of the function. The intention is
46: * that the static type of the arguments (obtainable via getItemType() and getCardinality()) may
47: * be used as part of the binding algorithm. In some cases it may be possible for the function
48: * to be pre-evaluated at compile time, for example if these expressions are all constant values.
49: * <p>
50: * The conventions of the XPath language demand that the results of a function depend only on the
51: * values of the expressions supplied as arguments, and not on the form of those expressions. For
52: * example, the result of f(4) is expected to be the same as f(2+2). The actual expression is supplied
53: * here to enable the binding mechanism to select the most efficient possible implementation (including
54: * compile-time pre-evaluation where appropriate).
55: * @return An object representing the function to be called, if one is found;
56: * null if no function was found matching the required name and arity.
57: * @throws net.sf.saxon.trans.XPathException if a function is found with the required name and arity, but
58: * the implementation of the function cannot be loaded or used; or if an error occurs
59: * while searching for the function.
60: */
61:
62: public Expression bind(int nameCode, String uri, String local,
63: Expression[] staticArgs) throws XPathException;
64:
65: /**
66: * This method creates a copy of a FunctionLibrary: if the original FunctionLibrary allows
67: * new functions to be added, then additions to this copy will not affect the original, or
68: * vice versa.
69: * @return a copy of this function library. This must be an instance of the original class.
70: */
71:
72: public FunctionLibrary copy();
73:
74: }
75: //
76: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
77: // you may not use this file except in compliance with the License. You may obtain a copy of the
78: // License at http://www.mozilla.org/MPL/
79: //
80: // Software distributed under the License is distributed on an "AS IS" basis,
81: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
82: // See the License for the specific language governing rights and limitations under the License.
83: //
84: // The Original Code is: all this file.
85: //
86: // The Initial Developer of the Original Code is Michael H. Kay.
87: //
88: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
89: //
90: // Contributor(s): none.
91: //
|