1 --- old/beanshell/engine/src/bsh/engine/BshScriptEngine.java
2 +++ new/beanshell/engine/src/bsh/engine/BshScriptEngine.java
7 + public Object invoke( Object thiz, String name, Object... args )
8 + throws ScriptException, NoSuchMethodException
10 + return invokeMethod( thiz, name, args );
14 * Same as invoke(Object, String, Object...) with <code>null</code> as the
15 * first argument. Used to call top-level procedures defined in scripts.
17 return invokeMethod( getGlobal(), name, args );
20 + public Object invoke( String name, Object... args )
21 + throws ScriptException, NoSuchMethodException
23 + return invokeFunction( name, args );
27 * Returns an implementation of an interface using procedures compiled in the
28 * interpreter. The methods of the interface may be implemented using the
29 --- old/beanshell/engine/src/TestBshScriptEngine.java
30 +++ new/beanshell/engine/src/TestBshScriptEngine.java
33 import javax.script.*;
34 import static javax.script.ScriptContext.*;
35 +import java.lang.reflect.*;
37 public class TestBshScriptEngine
39 public static void main( String [] args )
40 - throws ScriptException, NoSuchMethodException, IOException
41 + throws ScriptException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException
43 ScriptEngineManager manager =
44 new ScriptEngineManager( bsh.Interpreter.class.getClassLoader() );
46 assertTrue( engine.get("bar").equals("gee") );
47 assertTrue( engine.eval("bar").equals("gee") );
49 + // use reflection to pick available method
50 + Method invokeMe = null;
52 + invokeMe = Invocable.class.getMethod( "invokeFunction", String.class, Object[].class );
53 + } catch ( Exception e ) { }
54 + if (invokeMe == null)
57 + invokeMe = Invocable.class.getMethod( "invoke", String.class, Object[].class );
58 + } catch ( Exception e ) { }
61 // install and invoke a method
62 engine.eval("foo() { return foo+1; }");
64 Invocable invocable = (Invocable) engine;
65 - int foo = (Integer)invocable.invokeFunction( "foo" );
66 + int foo = (Integer)invokeMe.invoke( invocable, "foo", (Object) new Object[]{} );
67 assertTrue( foo == 43 );
72 "flag2=false; myObj() { run() { flag2=true; } return this; }");
73 assertTrue( (Boolean)engine.get("flag2") == false );
74 - Object scriptedObject = invocable.invokeFunction("myObj");
75 + Object scriptedObject = invokeMe.invoke( invocable, "myObj", (Object) new Object[]{} );
76 assertTrue( scriptedObject instanceof bsh.This );
78 (Runnable)invocable.getInterface( scriptedObject, Runnable.class );