01: /*
02: * %W% %E% %U%
03: *
04: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
05: * SUN PROPRIETARY/CONFIDENTAIL. Use is subject to license terms.
06: */
07:
08: package javax.script;
09:
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 procedure compiled during a previous script execution, which is retained in
22: * 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: * If classes are not supported in the scripting language or
31: * if the procedure is not a member function of any class, the argument must be
32: * <code>null</code>.
33: *
34: * @param args Arguments to pass to the procedure. The rules for converting
35: * the arguments to scripting variables are implementation-specific.
36: *
37: * @return The value returned by the procedure. The rules for converting the scripting variable returned by the procedure to a Java Object are implementation-specific.
38: *
39: * @throws ScriptException if an error occurrs during invocation of the method.
40: * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
41: * @throws NullPointerException if method name is null.
42: */
43: public Object invoke(Object thiz, String name, Object... args)
44: throws ScriptException, NoSuchMethodException;
45:
46: /**
47: * Same as invoke(Object, String, Object...) with <code>null</code> as the first
48: * argument. Used to call top-level procedures defined in scripts.
49: *
50: * @param args Arguments to pass to the procedure
51: * @return The value returned by the procedure
52: *
53: * @throws ScriptException if an error occurrs during invocation of the method.
54: * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
55: * @throws NullPointerException if method name is null.
56: */
57: public Object invoke(String name, Object... args)
58: throws ScriptException, NoSuchMethodException;
59:
60: /**
61: * Returns an implementation of an interface using procedures compiled in
62: * the interpreter. The methods of the interface
63: * may be implemented using the <code>invoke</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 methods 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: * does not exist or is not an interface.
73: */
74: public <T> T getInterface(Class<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 invoke(Object, String, Object...)
80: * method.
81: *
82: * @param thiz The scripting object whose member functions are used to implement the methods of the interface.
83: * @param clasz The <code>Class</code> object of the interface to return.
84: *
85: * @return An instance of requested interface - null if the requested interface is unavailable,
86: * i. e. if compiled methods in the <code>ScriptEngine</code> cannot be found matching
87: * the ones in the requested interface.
88: *
89: * @throws IllegalArgumentException if the specified <code>Class</code> object
90: * does not exist or is not an interface, or if the specified Object is
91: * null or does not represent a scripting object.
92: */
93: public <T> T getInterface(Object thiz, Class<T> clasz);
94:
95: }
|