J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.script; |
| 27 | |
| 28 | /** |
| 29 | * The optional interface implemented by ScriptEngines whose methods allow the invocation of |
| 30 | * procedures in scripts that have previously been executed. |
| 31 | * |
| 32 | * @author Mike Grogan |
| 33 | * @author A. Sundararajan |
| 34 | * @since 1.6 |
| 35 | */ |
| 36 | public interface Invocable { |
| 37 | /** |
| 38 | * Calls a method on a script object compiled during a previous script execution, |
| 39 | * which is retained in the state of the <code>ScriptEngine</code>. |
| 40 | * |
| 41 | * @param name The name of the procedure to be called. |
| 42 | * |
| 43 | * @param thiz If the procedure is a member of a class |
| 44 | * defined in the script and thiz is an instance of that class |
| 45 | * returned by a previous execution or invocation, the named method is |
| 46 | * called through that instance. |
| 47 | * |
| 48 | * @param args Arguments to pass to the procedure. The rules for converting |
| 49 | * the arguments to scripting variables are implementation-specific. |
| 50 | * |
| 51 | * @return The value returned by the procedure. The rules for converting the scripting |
| 52 | * variable returned by the script method to a Java Object are implementation-specific. |
| 53 | * |
| 54 | * @throws ScriptException if an error occurrs during invocation of the method. |
| 55 | * @throws NoSuchMethodException if method with given name or matching argument types cannot be found. |
| 56 | * @throws NullPointerException if the method name is null. |
| 57 | * @throws IllegalArgumentException if the specified thiz is null or the specified Object is |
| 58 | * does not represent a scripting object. |
| 59 | */ |
| 60 | public Object invokeMethod(Object thiz, String name, Object... args) |
| 61 | throws ScriptException, NoSuchMethodException; |
| 62 | |
| 63 | /** |
| 64 | * Used to call top-level procedures and functions defined in scripts. |
| 65 | * |
| 66 | * @param args Arguments to pass to the procedure or function |
| 67 | * @return The value returned by the procedure or function |
| 68 | * |
| 69 | * @throws ScriptException if an error occurrs during invocation of the method. |
| 70 | * @throws NoSuchMethodException if method with given name or matching argument types cannot be found. |
| 71 | * @throws NullPointerException if method name is null. |
| 72 | */ |
| 73 | public Object invokeFunction(String name, Object... args) |
| 74 | throws ScriptException, NoSuchMethodException; |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * Returns an implementation of an interface using functions compiled in |
| 79 | * the interpreter. The methods of the interface |
| 80 | * may be implemented using the <code>invokeFunction</code> method. |
| 81 | * |
| 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 functions 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. |
| 90 | */ |
| 91 | public <T> T getInterface(Class<T> clasz); |
| 92 | |
| 93 | /** |
| 94 | * Returns an implementation of an interface using member functions of |
| 95 | * a scripting object compiled in the interpreter. The methods of the |
| 96 | * interface may be implemented using the <code>invokeMethod</code> method. |
| 97 | * |
| 98 | * @param thiz The scripting object whose member functions are used to implement the methods of the interface. |
| 99 | * @param clasz The <code>Class</code> object of the interface to return. |
| 100 | * |
| 101 | * @return An instance of requested interface - null if the requested interface is unavailable, |
| 102 | * i. e. if compiled methods in the <code>ScriptEngine</code> cannot be found matching |
| 103 | * the ones in the requested interface. |
| 104 | * |
| 105 | * @throws IllegalArgumentException if the specified <code>Class</code> object |
| 106 | * is null or is not an interface, or if the specified Object is |
| 107 | * null or does not represent a scripting object. |
| 108 | */ |
| 109 | public <T> T getInterface(Object thiz, Class<T> clasz); |
| 110 | |
| 111 | } |