KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > FunctionLibrary


1 package net.sf.saxon.functions;
2
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.trans.XPathException;
5
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * 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 JavaDoc {
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 JavaDoc uri, String JavaDoc local, int arity);
34
35     /**
36      * Bind an extension function, given the URI and local parts of the function name,
37      * and the list of expressions supplied as arguments. This method is called at compile
38      * time.
39      * @param nameCode The namepool nameCode of the function name. The uri and local name are also
40      * supplied (redundantly) to avoid fetching them from the name pool.
41      * @param uri The URI of the function name
42      * @param local The local part of the function name
43      * @param staticArgs The expressions supplied statically in arguments to the function call.
44      * The length of this array represents the arity of the function. The intention is
45      * that the static type of the arguments (obtainable via getItemType() and getCardinality()) may
46      * be used as part of the binding algorithm. In some cases it may be possible for the function
47      * to be pre-evaluated at compile time, for example if these expressions are all constant values.
48      * <p>
49      * The conventions of the XPath language demand that the results of a function depend only on the
50      * values of the expressions supplied as arguments, and not on the form of those expressions. For
51      * example, the result of f(4) is expected to be the same as f(2+2). The actual expression is supplied
52      * here to enable the binding mechanism to select the most efficient possible implementation (including
53      * compile-time pre-evaluation where appropriate).
54      * @return An object representing the function to be called, if one is found;
55      * null if no function was found matching the required name and arity.
56      * @throws net.sf.saxon.trans.XPathException if a function is found with the required name and arity, but
57      * the implementation of the function cannot be loaded or used; or if an error occurs
58      * while searching for the function.
59      */

60
61     public Expression bind(int nameCode, String JavaDoc uri, String JavaDoc local, Expression[] staticArgs)
62             throws XPathException;
63
64     /**
65      * This method creates a copy of a FunctionLibrary: if the original FunctionLibrary allows
66      * new functions to be added, then additions to this copy will not affect the original, or
67      * vice versa.
68      * @return a copy of this function library. This must be an instance of the original class.
69      */

70
71     public FunctionLibrary copy();
72
73 }
74 //
75
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
76
// you may not use this file except in compliance with the License. You may obtain a copy of the
77
// License at http://www.mozilla.org/MPL/
78
//
79
// Software distributed under the License is distributed on an "AS IS" basis,
80
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
81
// See the License for the specific language governing rights and limitations under the License.
82
//
83
// The Original Code is: all this file.
84
//
85
// The Initial Developer of the Original Code is Michael H. Kay.
86
//
87
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
88
//
89
// Contributor(s): none.
90
//
Popular Tags