congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Script.setBinding
Code IndexAdd Tabnine 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)

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

  • Finding current android device location
  • scheduleAtFixedRate (ScheduledExecutorService)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now