groovy.lang.Script.getBinding()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中groovy.lang.Script.getBinding()方法的一些代码示例,展示了Script.getBinding()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Script.getBinding()方法的具体详情如下:
包路径:groovy.lang.Script
类名称:Script
方法名:getBinding

Script.getBinding介绍

暂无

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

public void set(Object value) {
    script.getBinding().setVariable(variable, value);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

public Object get() {
  return script.getBinding().getVariable(variable);
}

代码示例来源:origin: org.codehaus.groovy/groovy

private Object invokePropertyOrMissing(Object object, String methodName, Object[] originalArguments, boolean fromInsideClass, boolean isCallToSuper) {
  // if no method was found, try to find a closure defined as a field of the class and run it
  Object value = null;
  final MetaProperty metaProperty = this.getMetaProperty(methodName, false);
  if (metaProperty != null)
   value = metaProperty.getProperty(object);
  else {
    if (object instanceof Map)
     value = ((Map)object).get(methodName);
  }
  if (value instanceof Closure) {  // This test ensures that value != this If you ever change this ensure that value != this
    Closure closure = (Closure) value;
    MetaClass delegateMetaClass = closure.getMetaClass();
    return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass);
  }
  if (object instanceof Script) {
    Object bindingVar = ((Script) object).getBinding().getVariables().get(methodName);
    if (bindingVar != null) {
      MetaClass bindingVarMC = ((MetaClassRegistryImpl) registry).getMetaClass(bindingVar);
      return bindingVarMC.invokeMethod(bindingVar, CLOSURE_CALL_METHOD, originalArguments);
    }
  }
  return invokeMissingMethod(object, methodName, originalArguments, null, isCallToSuper);
}

代码示例来源:origin: groovy/groovy-core

public void testCreateScriptWithNullClass() {
  Script script = InvokerHelper.createScript(null, new Binding(bindingVariables));
  assertEquals(bindingVariables, script.getBinding().getVariables());
}

代码示例来源:origin: apache/nifi

Map bindings = script.getBinding().getVariables();

代码示例来源:origin: groovy/groovy-core

public void testCreateScriptWithScriptClass() {
    GroovyClassLoader classLoader = new GroovyClassLoader();
    String controlProperty = "text";
    String controlValue = "I am a script";
    String code = controlProperty + " = '" + controlValue + "'";
    GroovyCodeSource codeSource = new GroovyCodeSource(code, "testscript", "/groovy/shell");
    Class scriptClass = classLoader.parseClass(codeSource, false);
    Script script = InvokerHelper.createScript(scriptClass, new Binding(bindingVariables));
    assertEquals(bindingVariables, script.getBinding().getVariables());
    script.run();
    assertEquals(controlValue, script.getProperty(controlProperty));
  }
}

代码示例来源:origin: palantir/atlasdb

/**
 * Note on the System.setSecurityManager call:
 *
 * The main method of the Groovysh class initializes a SecurityManager to
 * prevent the use of System.exit. The SecurityManager is not actually
 * necessary for Groovysh, so this change removes it to allow JDBC
 * access (removes the need for users to create an explicit ~/.java.policy
 * file).
 */
public static void callback(Script script, boolean mutationsEnabled) throws CompilationFailedException, IOException {
  System.setSecurityManager(null);
  setupBinding(script.getBinding(), mutationsEnabled);
}

代码示例来源:origin: spring-projects/spring-integration

public void customize(GroovyObject goo) {
  Assert.state(goo instanceof Script, "Expected a Script");
  if (this.variables != null) {
    Binding binding = ((Script) goo).getBinding();
    for (Map.Entry<String, ?> entry : this.variables.entrySet()) {
      binding.setVariable(entry.getKey(), entry.getValue());
    }
  }
  if (this.customizer != null) {
    this.customizer.customize(goo);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch-lang-groovy

@SuppressWarnings({"unchecked"})
@Override
public void setNextScore(float score) {
  script.getBinding().getVariables().put("_score", score);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-lang-groovy

@SuppressWarnings({"unchecked"})
@Override
public void setNextVar(String name, Object value) {
  script.getBinding().getVariables().put(name, value);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-lang-groovy

@SuppressWarnings({"unchecked"})
@Override
public void setNextVar(String name, Object value) {
  script.getBinding().getVariables().put(name, value);
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

public void set(Object value) {
    script.getBinding().setVariable(variable, value);
  }
}

代码示例来源:origin: org.kohsuke.droovy/groovy

public void set(Object value) {
    script.getBinding().setVariable(variable, value);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

public void set(Object value) {
    script.getBinding().setVariable(variable, value);
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

public void set(Object value) {
    script.getBinding().setVariable(variable, value);
  }
}

代码示例来源:origin: com.palantir.atlasdb/atlasdb-console

/**
 * Note on the System.setSecurityManager call:
 *
 * The main method of the Groovysh class initializes a SecurityManager to
 * prevent the use of System.exit. The SecurityManager is not actually
 * necessary for Groovysh, so this change removes it to allow JDBC
 * access (removes the need for users to create an explicit ~/.java.policy
 * file).
 */
public static void callback(Script script, boolean mutationsEnabled) throws CompilationFailedException, IOException {
  System.setSecurityManager(null);
  setupBinding(script.getBinding(), mutationsEnabled);
}

代码示例来源:origin: org.springframework.integration/spring-integration-groovy

public void customize(GroovyObject goo) {
  Assert.state(goo instanceof Script, "Expected a Script");
  if (this.variables != null) {
    Binding binding = ((Script) goo).getBinding();
    for (Map.Entry<String, ?> entry : this.variables.entrySet()) {
      binding.setVariable(entry.getKey(), entry.getValue());
    }
  }
  if (this.customizer != null) {
    this.customizer.customize(goo);
  }
}

代码示例来源:origin: com.disney.groovity/groovity-core

public void startRun(final Script script){
  final Binding oldBinding = THREAD_BINDING.get();
  final Binding scriptBinding = script.getBinding();
  if(oldBinding != scriptBinding){
    if(oldBinding!=null){
      scriptBinding.setVariable(THREAD_BINDING_PREVIOUS, oldBinding);
    }
    scriptBinding.setVariable(THREAD_BINDING_OWNER, script);
    THREAD_BINDING.set(scriptBinding);
  }
}

代码示例来源:origin: disney/groovity

public void startRun(final Script script){
  final Binding oldBinding = THREAD_BINDING.get();
  final Binding scriptBinding = script.getBinding();
  if(oldBinding != scriptBinding){
    if(oldBinding!=null){
      scriptBinding.setVariable(THREAD_BINDING_PREVIOUS, oldBinding);
    }
    scriptBinding.setVariable(THREAD_BINDING_OWNER, script);
    THREAD_BINDING.set(scriptBinding);
  }
}

代码示例来源:origin: org.elasticsearch.module/lang-groovy

@SuppressWarnings("unchecked")
public GroovyScript(CompiledScript compiledScript, Script script, @Nullable LeafSearchLookup lookup, ESLogger logger) {
  this.compiledScript = compiledScript;
  this.script = script;
  this.lookup = lookup;
  this.logger = logger;
  this.variables = script.getBinding().getVariables();
}

相关文章