Package groovy.lang

Examples of groovy.lang.Binding


    @SuppressWarnings({"unchecked"})
    @Override public ExecutableScript executable(Object compiledScript, Map<String, Object> vars) {
        try {
            Class scriptClass = (Class) compiledScript;
            Script scriptObject = (Script) scriptClass.newInstance();
            Binding binding = new Binding();
            if (vars != null) {
                binding.getVariables().putAll(vars);
            }
            scriptObject.setBinding(binding);
            return new GroovyExecutableScript(scriptObject);
        } catch (Exception e) {
            throw new ScriptException("failed to build executable script", e);
View Full Code Here


    @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
        try {
            Class scriptClass = (Class) compiledScript;
            Script scriptObject = (Script) scriptClass.newInstance();
            Binding binding = new Binding();
            binding.getVariables().putAll(lookup.asMap());
            if (vars != null) {
                binding.getVariables().putAll(vars);
            }
            scriptObject.setBinding(binding);
            return new GroovySearchScript(scriptObject, lookup);
        } catch (Exception e) {
            throw new ScriptException("failed to build search script", e);
View Full Code Here

    @Override public Object execute(Object compiledScript, Map<String, Object> vars) {
        try {
            Class scriptClass = (Class) compiledScript;
            Script scriptObject = (Script) scriptClass.newInstance();
            Binding binding = new Binding(vars);
            scriptObject.setBinding(binding);
            return scriptObject.run();
        } catch (Exception e) {
            throw new ScriptException("failed to execute script", e);
        }
View Full Code Here

    String fullFile = readTemplate();
    int fullFileIndex = 0;
   
    try {
      GroovyShell shell = bindContextVariables(context);
      Binding b = shell.getContext();
      if (m_verbose) dumpBinding(b);
     
      while (fullFileIndex < fullFile.length()) {
        int startIndex = fullFile.indexOf(MARKER_START, fullFileIndex);
        if (-1 != startIndex) {
View Full Code Here

  }
 
  private void bindObject(GroovyShell shell, String name, Object value)
    throws SyntaxException, ClassNotFoundException, IOException
  {
    Binding b = shell.getContext();
    b.setVariable(name, value);
  }
View Full Code Here

  }
 
  private GroovyShell bindContextVariables(Context context)
    throws SyntaxException, ClassNotFoundException, IOException
  {
    Binding binding = new Binding();
    GroovyShell result = new GroovyShell(binding);
   
    for (Iterator it = context.keySet().iterator(); it.hasNext(); ) {
      Object oVariable = it.next();
      Object oValue = context.get(oVariable);
View Full Code Here

    System.out.println("Warning:" + s);
  }
 
  static public void main(String[] argv) {
  //call groovy expressions from Java code
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
 
    try {
      Object value =
        shell.evaluate("println 'Hello World!'; x = 123; return foo * 10", "TestScript");
      assert value.equals(new Integer(20));
      assert binding.getVariable("x").equals(new Integer(123));
      System.out.println("value:" + value);
    }
    catch (SyntaxException e) {
      // XXX Auto-generated catch block
      e.printStackTrace();
View Full Code Here

  protected ScriptSaver saver = new ScriptSaver();

  public SoapUIGroovyScriptEngine( ClassLoader parentClassLoader )
  {
    classLoader = new GroovyClassLoader( parentClassLoader );
    binding = new Binding();
    CompilerConfiguration config = new CompilerConfiguration();
    config.setDebug( true );
    config.setVerbose( true );
    shell = new GroovyShell( classLoader, binding, config );
  }
View Full Code Here

        try {
            parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            String[] roots = new String[] { file.getParentFile().getAbsolutePath() };
            GroovyScriptEngine gse = new GroovyScriptEngine(roots, parent.getClass().getClassLoader());
            Binding binding = new Binding();
            binding.setVariable("session", model.getClientSession().getSession());
            binding.setVariable("binding", model.getClientSession().getSession().getBinding());
            binding.setVariable("out", out);
            gse.run(file.getName(), binding);
        } catch (Exception ex) {
            ClientHelper.showError(null, ex);
        } finally {
            parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
View Full Code Here

        try {
            parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            String[] roots = new String[] { file.getParentFile().getAbsolutePath() };
            GroovyScriptEngine gse = new GroovyScriptEngine(roots, parent.getClass().getClassLoader());
            Binding binding = new Binding();
            binding.setVariable("session", model.getClientSession().getSession());
            binding.setVariable("binding", model.getClientSession().getSession().getBinding());
            binding.setVariable("out", out);
            gse.run(file.getName(), binding);
        } catch (Exception ex) {
            ClientHelper.showError(null, ex);
        } finally {
            parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
View Full Code Here

TOP

Related Classes of groovy.lang.Binding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.