title: Access binding inside delegate object method in java groovy mix
body: <p>I have the following "java" class:</p>
  
  <pre><code>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&lt;String, Object&gt; params) {
              // String a = (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));
          }
      }
  }
  </code></pre>
  
  <p>and here is my DSL:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>I want to access the binding object (e.g get the "a" value) inside MyDSL's method. The problem is MyDSL class is written in java. How can I access the binding object, like the code commented above?</p>
  
  <p>P.S: I want to access binding in MyDSL class, because I put the script object in the cache, so there is only one script object and so only one instance for MyDSL class, but based on binding variable value, the execution for each method must be different.</p>