Path: blob/master/src/java.scripting/share/classes/javax/script/Invocable.java
41149 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.script;2627/**28* The optional interface implemented by ScriptEngines whose methods allow the invocation of29* procedures in scripts that have previously been executed.30*31* @author Mike Grogan32* @author A. Sundararajan33* @since 1.634*/35public interface Invocable {36/**37* Calls a method on a script object compiled during a previous script execution,38* which is retained in the state of the <code>ScriptEngine</code>.39*40* @param name The name of the procedure to be called.41*42* @param thiz If the procedure is a member of a class43* defined in the script and thiz is an instance of that class44* returned by a previous execution or invocation, the named method is45* called through that instance.46*47* @param args Arguments to pass to the procedure. The rules for converting48* the arguments to scripting variables are implementation-specific.49*50* @return The value returned by the procedure. The rules for converting the scripting51* variable returned by the script method to a Java Object are implementation-specific.52*53* @throws ScriptException if an error occurs during invocation of the method.54* @throws NoSuchMethodException if method with given name or matching argument types cannot be found.55* @throws NullPointerException if the method name is null.56* @throws IllegalArgumentException if the specified thiz is null or the specified Object is57* does not represent a scripting object.58*/59public Object invokeMethod(Object thiz, String name, Object... args)60throws ScriptException, NoSuchMethodException;6162/**63* Used to call top-level procedures and functions defined in scripts.64*65* @param name of the procedure or function to call66* @param args Arguments to pass to the procedure or function67* @return The value returned by the procedure or function68*69* @throws ScriptException if an error occurs 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*/73public Object invokeFunction(String name, Object... args)74throws ScriptException, NoSuchMethodException;757677/**78* Returns an implementation of an interface using functions compiled in79* the interpreter. The methods of the interface80* may be implemented using the <code>invokeFunction</code> method.81*82* @param <T> the type of the interface to return83* @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 functions in the <code>ScriptEngine</code> cannot be found matching87* the ones in the requested interface.88*89* @throws IllegalArgumentException if the specified <code>Class</code> object90* is null or is not an interface.91*/92public <T> T getInterface(Class<T> clasz);9394/**95* Returns an implementation of an interface using member functions of96* a scripting object compiled in the interpreter. The methods of the97* interface may be implemented using the <code>invokeMethod</code> method.98*99* @param <T> the type of the interface to return100* @param thiz The scripting object whose member functions are used to implement the methods of the interface.101* @param clasz The <code>Class</code> object of the interface to return.102*103* @return An instance of requested interface - null if the requested interface is unavailable,104* i. e. if compiled methods in the <code>ScriptEngine</code> cannot be found matching105* the ones in the requested interface.106*107* @throws IllegalArgumentException if the specified <code>Class</code> object108* is null or is not an interface, or if the specified Object is109* null or does not represent a scripting object.110*/111public <T> T getInterface(Object thiz, Class<T> clasz);112113}114115116