Access binding inside delegate object method in java groovy mix -
i have following "java" class:
public class gscript { public static void main(string[] args) throws exception { binding binding = new binding(); binding.setvariable("a", "a"); compilerconfiguration cc = new compilerconfiguration(); cc.setscriptbaseclass(delegatingscript.class.getname()); groovyshell sh = new groovyshell(classloader.getsystemclassloader(), binding, cc); delegatingscript script = (delegatingscript) sh.parse(gscript.class.getresource("/org/devocative/samples/groovy/my.dsl.txt").touri()); script.setdelegate(new mydsl()); script.run(); } public static class mydsl { public object exec(string commandname, map<string, object> params) { // string = (string)binding.getvariable("a"); how??? return string.format("cmd = %s, params = %s", commandname, params); } public object ssh(string prompt, string cmd, boolean force, string... stdin) { return string.format("prompt = %s, cmd = %s, force = %s, stdin = %s", prompt, cmd, force, arrays.tostring(stdin)); } } } and here dsl:
e = exec "withparam", [a:'a', b:1] println "e = $e" e = ssh "prompt", "exec oops!", true println "e = $e" e = ssh "prompt", "exec oops!", true, '1', '2', '3' println "e = $e" i want access binding object (e.g "a" value) inside mydsl's method. problem mydsl class written in java. how can access binding object, code commented above?
p.s: want access binding in mydsl class, because put script object in cache, there 1 script object , 1 instance mydsl class, based on binding variable value, execution each method must different.
Comments
Post a Comment