public interface Script { public int computeResult(int value) { } }The Groovy wrapper:
public class MyGroovyScriptWrapper extends GroovyScriptWrapper<Script> { }with
Script
being the interface you want to implement in the scripting language.
ScriptWrapper
has several methods allowing to configure it. For example:ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; Script Script = wrapper.getScript();After installing the script, you will be able to use it exactly as the interface:
File file = new File(<our script file>); wrapper.installScript(file); int value = script.computeResult(10);
public interface Script { }
executeScriptImpl()
method. For example, for the computeResult(int value)
method of the following interface:public interface Script { public int computeResult(int value); }you will have:
public class MethodWrapperImpl extends AbstractScriptMethodWrapper<Script, Integer> { public MethodWrapperImpl(ScriptWrapper<Script> wrapper) { super(wrapper); } protected Integer executeScriptImpl(Object... arguments) { Integer i = (Integer)arguments[0]; return script.computeResult(i); } }
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence