Package groovy.lang

Examples of groovy.lang.Binding


    try {
      // Read the script into a string.
      String script = GroovyActionProcessor.getScriptFromClasspath(getScriptPath());

      // Bind objects into the Groovy context.
      Binding binding = new Binding();
      binding.setVariable("filename", filename);
      binding.setVariable("message", message);

      // Create a shell and evaluate
      GroovyShell shell = new GroovyShell(Thread.currentThread().getContextClassLoader(),
          binding);
      Object result = shell.evaluate(script);
View Full Code Here


    }

    protected void doInitialise() throws ManagedLifecycleException {
        try {
            // Configure the groovy script....
            Binding binding = new Binding();
            UncomposedMessageDeliveryAdapter deliveryAdapter = createDeliveryAdapter();

            binding.setVariable("config", getConfig());
            binding.setVariable("gateway", this);
            binding.setVariable("listener", this);
            if(deliveryAdapter != null) {
                binding.setVariable("deliveryAdapter", deliveryAdapter);
            }
            script.setBinding(binding);
        } catch (ConfigurationException e) {
           throw new ManagedLifecycleException("Unable to construct message delivery adapter.", e);
        }
View Full Code Here

    public static UtilCache<String, Class> parsedScripts = new UtilCache<String, Class>("script.GroovyLocationParsedCache", 0, 0, false);

    public static GroovyClassLoader groovyClassLoader = new GroovyClassLoader();

    public static Binding getBinding(Map<String, ? extends Object> context) {
        Binding binding = new Binding();
        if (context != null) {
            Set<String> keySet = context.keySet();
            for (Object key : keySet) {
                binding.setVariable((String) key, context.get(key));
            }

            // include the context itself in for easier access in the scripts
            binding.setVariable("context", context);
        }

        return binding;
    }
View Full Code Here

            if (Debug.verboseOn())
                Debug.logVerbose("Evaluated to -- " + o, module);

            // read back the context info
            Binding binding = shell.getContext();
            context.putAll(binding.getVariables());

        } catch (CompilationFailedException e) {
            Debug.logError(e, "Groovy Evaluation error.", module);
            throw e;
        }
View Full Code Here

  /**
   * This will provide a new instance of {@link groovy.lang.Binding} for
   * variable setting/resolution.
   */
  public StandardBuilder() { this(new Binding()); }
View Full Code Here

      else if (mc.getTheClass() != Object.class) mc = GroovySystem.getMetaClassRegistry().getMetaClass(mc.getTheClass().getSuperclass());
      else break;
    }
    if (method == null) {
      try {
        Binding dsl = GroovyDSLBinding.getInstance();
        if (dsl != null) return dsl.invokeMethod(methodName, arguments); else throw me;
      } catch (MissingMethodException eee) {
        throw me;
      }
    }
    try {
View Full Code Here

        else break;
      }
     
      if (property == null) {
        try {
          Binding dsl = GroovyDSLBinding.getInstance();
          if (dsl != null) {
            if (isGetter) return dsl.getVariable(propertyName); else dsl.setVariable(propertyName, optionalValue);
          } else throw e;
        } catch (MissingPropertyException ee) {
          throw e;
        }
      }
View Full Code Here

        while (true) {
            System.out.print("groovy> ");
            if ((line = br.readLine()) == null || line.equals("quit"))
                break;
            try {
                System.out.println(gse.run(line, new Binding()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
View Full Code Here

     * @return a <code>toString()</code> representation of the result of the execution of the script
     * @throws ResourceException if there is a problem accessing the script
     * @throws ScriptException if there is a problem parsing the script
     */
    public String run(String scriptName, String argument) throws ResourceException, ScriptException {
        Binding binding = new Binding();
        binding.setVariable("arg", argument);
        Object result = run(scriptName, binding);
        return result == null ? "" : result.toString();
    }
View Full Code Here

     * @param in The input stream to use
     * @param out The output stream to use
     * @param err The error stream to use
     */
    public InteractiveShell(final InputStream in, final PrintStream out, final PrintStream err) throws IOException {
        this(null, new Binding(), in, out, err);
    }
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.