public interface Script { public int computeResult(int value); }and:
public interface Script2 { public String getMessage(); }Normally you must define two different ScriptWrappers, one for each interface, and use the right one for each script. The combiner allows you to define only one wrapper and let the wrapper choose the right interface for you.
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; ScriptWrapper<Script> wrapper2 = new GroovyScriptWrapper<Script2>() { };Then we will create a combiner and add the two wrappers to it:
ScriptWrapperCombiner combiner = new ScriptWrapperCombiner(); combiner.addScriptWrapper(wrapper); combiner.addScriptWrapper(wrapper2);
File file = new File(<our script file>); wrapper.installScript(file);The only difference from the regular wrappers is that the ScriptWrapper.getScript() will only return a non null result after the script has been installed, because the effective interface depends on the script signature. For example, suppose the following script:
public getMessage() { return "Hello World!"; }Then after installing the script, the following code will print "Hello World!" on the console:
Script2 script = (Script2)wrapper.getProxy(); String message = script.getMessage(); System.out.println(message);
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence