public interface Script { public int computeResult(int value) { } }And the script:
public int computeResult(int value) { return value * 10; } public void doSomething() { context.echo("Hello!); }The
getInvocableMethods()
method will return at least two results:computeResult(int value)
methoddoSomething()
methodpublic interface Script { public int computeResult(int value); }And the creation of the ScriptWrapper:
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; File file = new File(<our script file>); wrapper.installScript(file);The basic way to use the wrapper is by calling the
computeResult(value)
method of the interface such as:Script script = wrapper.getScriptProxy(); int result = script.computeResult(10);Bu we can also call any method of the script, even those which don't be part of the interface signature. For example, suppose the following Groovy script:
public int computeResult(int value) { return value * 10; } public int myFunction(int value) { return value * 100; }We could perform in our java code:
int result = wrapper.invokeMethod("myFunction", 10);
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence