KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.Configuration;
4
5 import java.io.Serializable JavaDoc;
6 import java.lang.reflect.AccessibleObject JavaDoc;
7
8 /**
9 * This class acts as a factory for creating expressions that call extension functions.
10  * A different factory may be registered with the Configuration in order to customize the
11  * behaviour. Alternatively, this factory class can be customized by calling setExtensionFunctionClass
12  * to nominate a subclass of ExtensionFunctionCall to be used to implement calls on extension functions.
13 */

14
15 public class ExtensionFunctionFactory implements Serializable JavaDoc {
16
17     public ExtensionFunctionFactory(Configuration config) {
18         this.config = config;
19     }
20
21     private Class JavaDoc extensionFunctionCallClass = ExtensionFunctionCall.class;
22     private Configuration config;
23
24     /**
25      * Set the class to be used to represent extension function calls. This must be a subclass
26      * of {@link ExtensionFunctionCall}
27      * @param subclass the subclass of ExtensionFunctionCall to be used
28      */

29
30     public void setExtensionFunctionClass(Class JavaDoc subclass) {
31         extensionFunctionCallClass = subclass;
32     }
33
34     /**
35      * Factory method to create an expression that calls a Java extension function.
36      * This is always called at XPath compile time.
37      * @param nameCode the name of the function name, as represented in the name pool
38      * @param theClass the Java class containing the extension function
39      * @param method The "accessibleObject" representing a constructor, method, or field corresponding
40      * to the extension function
41      * @param arguments Array containing the expressions supplied as arguments to the function call.
42      * @return the constructed ExtensionFunctionCall object (a subclass might return any expression
43      * representing the extension function call).
44      */

45
46     public Expression makeExtensionFunctionCall(
47         int nameCode, Class JavaDoc theClass, AccessibleObject JavaDoc method, Expression[] arguments) {
48         ExtensionFunctionCall fn;
49         try {
50             fn = (ExtensionFunctionCall)(extensionFunctionCallClass.newInstance());
51         } catch (InstantiationException JavaDoc e) {
52             throw new IllegalArgumentException JavaDoc(e.getMessage());
53         } catch (IllegalAccessException JavaDoc e) {
54             throw new IllegalArgumentException JavaDoc(e.getMessage());
55         }
56         fn.init(nameCode, theClass, method, config);
57         fn.setArguments(arguments);
58         return fn;
59     }
60
61 }
62
63 //
64
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
65
// you may not use this file except in compliance with the License. You may obtain a copy of the
66
// License at http://www.mozilla.org/MPL/
67
//
68
// Software distributed under the License is distributed on an "AS IS" basis,
69
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
70
// See the License for the specific language governing rights and limitations under the License.
71
//
72
// The Original Code is: all this file.
73
//
74
// The Initial Developer of the Original Code is Michael H. Kay.
75
//
76
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
77
//
78
// Contributor(s): Gunther Schadow (changes to allow access to public fields; also wrapping
79
// of extensions and mapping of null to empty sequence).
80
//
81
Popular Tags