KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > script > Invocable


1 /*
2  * @(#)Invocable.java 1.4 06/06/19 20:34:27
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTAIL. Use is subject to license terms.
6  */

7
8 package javax.script;
9
10 /**
11  * The optional interface implemented by ScriptEngines whose methods allow the invocation of
12  * procedures in scripts that have previously been executed.
13  *
14  * @version 1.0
15  * @author Mike Grogan
16  * @author A. Sundararajan
17  * @since 1.6
18  */

19 public interface Invocable {
20     /**
21      * Calls a method on a script object compiled during a previous script execution,
22      * which is retained in the state of the <code>ScriptEngine</code>.
23      *
24      * @param name The name of the procedure to be called.
25      *
26      * @param thiz If the procedure is a member of a class
27      * defined in the script and thiz is an instance of that class
28      * returned by a previous execution or invocation, the named method is
29      * called through that instance.
30      *
31      * @param args Arguments to pass to the procedure. The rules for converting
32      * the arguments to scripting variables are implementation-specific.
33      *
34      * @return The value returned by the procedure. The rules for converting the scripting
35      * variable returned by the script method to a Java Object are implementation-specific.
36      *
37      * @throws ScriptException if an error occurrs during invocation of the method.
38      * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
39      * @throws NullPointerException if the method name is null.
40      * @throws IllegalArgumentException if the specified thiz is null or the specified Object is
41      * does not represent a scripting object.
42      */

43     public Object JavaDoc invokeMethod(Object JavaDoc thiz, String JavaDoc name, Object JavaDoc... args)
44         throws ScriptException, NoSuchMethodException JavaDoc;
45     
46     /**
47      * Used to call top-level procedures and functions defined in scripts.
48      *
49      * @param args Arguments to pass to the procedure or function
50      * @return The value returned by the procedure or function
51      *
52      * @throws ScriptException if an error occurrs during invocation of the method.
53      * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
54      * @throws NullPointerException if method name is null.
55      */

56      public Object JavaDoc invokeFunction(String JavaDoc name, Object JavaDoc... args)
57         throws ScriptException, NoSuchMethodException JavaDoc;
58      
59      
60      /**
61      * Returns an implementation of an interface using functions compiled in
62      * the interpreter. The methods of the interface
63      * may be implemented using the <code>invokeFunction</code> method.
64      *
65      * @param clasz The <code>Class</code> object of the interface to return.
66      *
67      * @return An instance of requested interface - null if the requested interface is unavailable,
68      * i. e. if compiled functions in the <code>ScriptEngine</code> cannot be found matching
69      * the ones in the requested interface.
70      *
71      * @throws IllegalArgumentException if the specified <code>Class</code> object
72      * is null or is not an interface.
73      */

74     public <T> T getInterface(Class JavaDoc<T> clasz);
75         
76     /**
77      * Returns an implementation of an interface using member functions of
78      * a scripting object compiled in the interpreter. The methods of the
79      * interface may be implemented using the <code>invokeMethod</code> method.
80      *
81      * @param thiz The scripting object whose member functions are used to implement the methods of the interface.
82      * @param clasz The <code>Class</code> object of the interface to return.
83      *
84      * @return An instance of requested interface - null if the requested interface is unavailable,
85      * i. e. if compiled methods in the <code>ScriptEngine</code> cannot be found matching
86      * the ones in the requested interface.
87      *
88      * @throws IllegalArgumentException if the specified <code>Class</code> object
89      * is null or is not an interface, or if the specified Object is
90      * null or does not represent a scripting object.
91      */

92      public <T> T getInterface(Object JavaDoc thiz, Class JavaDoc<T> clasz);
93      
94 }
95
Popular Tags