Codota Logo
Script.setBinding
Code IndexAdd Codota to your IDE (free)

How to use
setBinding
method
in
groovy.lang.Script

Best Java code snippets using groovy.lang.Script.setBinding (Showing top 20 results out of 423)

  • Common ways to obtain Script
private void myMethod () {
Script s =
  • Codota IconGroovyShell shell;String scriptText;shell.parse(scriptText)
  • Codota IconClass scriptClass;(Script) scriptClass.newInstance()
  • Codota IconClass scriptClass;Binding context;InvokerHelper.createScript(scriptClass, context)
  • Smart code suggestions by Codota
}
origin: org.codehaus.groovy/groovy

public static Script newScript(Class<?> scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException {
  Script script;
  try {
    Constructor constructor = scriptClass.getConstructor(Binding.class);
    script = (Script) constructor.newInstance(context);
  } catch (NoSuchMethodException e) {
    // Fallback for non-standard "Script" classes.
    script = (Script) scriptClass.newInstance();
    script.setBinding(context);
  }
  return script;
}
origin: org.codehaus.groovy/groovy

public void setProperty(String property, Object newValue) {
  if ("binding".equals(property))
    setBinding((Binding) newValue);
  else if("metaClass".equals(property))
    setMetaClass((MetaClass)newValue);
  else
    binding.setVariable(property, newValue);
}
origin: twosigma/beakerx

 public Object parseClassFromScript(String script) {
  Class<?> parsedClass = groovyClassLoader.parseClass(script);
  Script instance = null;
  try {
   instance = (Script) parsedClass.newInstance();
   instance.setBinding(scriptBinding);
  } catch (InstantiationException e) {
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  }
  return instance.run();
 }
}
origin: twosigma/beakerx

private Object runScript(Script script) {
 groovyEvaluator.getScriptBinding().setVariable(Evaluator.BEAKER_VARIABLE_NAME, groovyEvaluator.getBeakerX());
 script.setBinding(groovyEvaluator.getScriptBinding());
 return script.run();
}
origin: org.codehaus.groovy/groovy

public Object build(Script script) {
  // this used to be synchronized, but we also used to remove the
  // metaclass.  Since adding the metaclass is now a side effect, we
  // don't need to ensure the meta-class won't be observed and don't
  // need to hide the side effect.
  MetaClass scriptMetaClass = script.getMetaClass();
  script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this));
  script.setBinding(this);
  Object oldScriptName = getProxyBuilder().getVariables().get(SCRIPT_CLASS_NAME);
  try {
    getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, script.getClass().getName());
    return script.run();
  } finally {
    if(oldScriptName != null) {
      getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, oldScriptName);
    } else {
      getProxyBuilder().getVariables().remove(SCRIPT_CLASS_NAME);
    }
  }
}
origin: groovy/groovy-core

/**
 * When a method is not found in the current script, checks that it's possible to call a method closure from the binding.
 *
 * @throws IOException
 * @throws CompilationFailedException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public void testInvokeMethodFallsThroughToMethodClosureInBinding() throws IOException, CompilationFailedException, IllegalAccessException, InstantiationException {
  String text = "if (method() == 3) { println 'succeeded' }";
  GroovyCodeSource codeSource = new GroovyCodeSource(text, "groovy.script", "groovy.script");
  GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
  Class clazz = loader.parseClass(codeSource);
  Script script = ((Script) clazz.newInstance());
  Binding binding = new Binding();
  binding.setVariable("method", new MethodClosure(new Dummy(), "method"));
  script.setBinding(binding);
  script.run();
}
origin: spring-projects/spring-integration

@Override
public void customize(GroovyObject goo) {
  Assert.state(goo instanceof Script, "Expected a Script");
  ((Script) goo).setBinding(this.binding);
  super.customize(goo);
}
origin: org.fujion/fujion-script-groovy

@Override
public Object run(Map<String, Object> variables) {
  script.setBinding(variables == null ? null : new Binding(variables));
  return script.run();
}
origin: freeplane/freeplane

@Override
public void setBinding(Binding binding) {
  super.setBinding(binding);
  updateBoundVariables();
}
origin: org.carewebframework/org.carewebframework.web.script.groovy

@Override
public Object run(Map<String, Object> variables) {
  script.setBinding(variables == null ? null : new Binding(variables));
  return script.run();
}
origin: org.elasticsearch.module/lang-groovy

/**
 * Return a script object with the given vars from the compiled script object
 */
@SuppressWarnings("unchecked")
private Script createScript(Object compiledScript, Map<String, Object> vars) throws InstantiationException, IllegalAccessException {
  Class scriptClass = (Class) compiledScript;
  Script scriptObject = (Script) scriptClass.newInstance();
  Binding binding = new Binding();
  binding.getVariables().putAll(vars);
  scriptObject.setBinding(binding);
  return scriptObject;
}
origin: de.dfki.cos.basys.common/de.dfki.cos.basys.common.scxml

@Override
public void setBinding(final Binding binding) {
  super.setBinding(binding);
  this.context = ((GroovyContextBinding) binding).getContext();
}
origin: org.codehaus.groovy/groovy-jdk14

public void setProperty(String property, Object newValue) {
  if ("binding".equals(property))
    setBinding((Binding) newValue);
  else if("metaClass".equals(property))
    setMetaClass((MetaClass)newValue);
  else
    binding.setVariable(property, newValue);
}
origin: org.kohsuke.droovy/groovy

public void setProperty(String property, Object newValue) {
  if ("binding".equals(property))
    setBinding((Binding) newValue);
  else if("metaClass".equals(property))
    setMetaClass((MetaClass)newValue);
  else
    binding.setVariable(property, newValue);
}
origin: org.elasticsearch/elasticsearch-lang-groovy

@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);
  }
}
origin: net.tirasa.connid/connector-framework-internal

  @Override
  public Object execute(Map<String, Object> arguments) throws Exception {
    Map<String, Object> args = CollectionUtil.nullAsEmpty(arguments);
    groovyScript.setBinding(new Binding(args));
    return groovyScript.run();
  }
}
origin: io.ratpack/ratpack-groovy

public RatpackDslClosures apply(Path file, String scriptContent) throws Exception {
 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 ScriptEngine<Script> scriptEngine = new ScriptEngine<>(classLoader, compileStatic, Script.class);
 return RatpackDslClosures.capture(function, file, () -> {
  Script script = scriptEngine.create(file.getFileName().toString(), file, scriptContent);
  script.setBinding(new Binding(args));
  script.run();
 });
}
origin: org.jenkins-ci.plugins/matrix-project

/**
 * @param context
 *      Variables the script will see.
 */
private boolean evaluate(Binding context) {
  script.setBinding(context);
  try {
    return TRUE.equals(GroovySandbox.run(script, Whitelist.all()));
  } catch (RejectedAccessException x) {
    throw ScriptApproval.get().accessRejected(x, ApprovalContext.create());
  }
}
origin: org.codehaus.groovy/groovy-all-minimal

public Object build(Script script) {
  synchronized (script) {
    MetaClass scriptMetaClass = script.getMetaClass();
    try {
      script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this));
      script.setBinding(this);
      return script.run();
    } finally {
      script.setMetaClass(scriptMetaClass);
    }
  }
}
origin: org.apache.camel/camel-groovy

public <T> T evaluate(Exchange exchange, Class<T> type) {
  Script script = instantiateScript(exchange);
  script.setBinding(createBinding(exchange));
  Object value = script.run();
  return exchange.getContext().getTypeConverter().convertTo(type, value);
}
groovy.langScriptsetBinding

Popular methods of Script

  • run
    A helper method to allow scripts to be run taking command line arguments
  • getProperty
  • getBinding
  • setProperty
  • invokeMethod
    Invoke a method (or closure in the binding) defined.
  • getMetaClass
  • setMetaClass
  • evaluate
    A helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onRequestPermissionsResult (Fragment)
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • URLConnection (java.net)
    The abstract class URLConnection is the superclass of all classes that represent a communications li
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now