当前位置: 首页>>代码示例>>Java>>正文


Java Script.setBinding方法代码示例

本文整理汇总了Java中groovy.lang.Script.setBinding方法的典型用法代码示例。如果您正苦于以下问题:Java Script.setBinding方法的具体用法?Java Script.setBinding怎么用?Java Script.setBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在groovy.lang.Script的用法示例。


在下文中一共展示了Script.setBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
public Object run(String dsl, Binding binding) {
    CompilerConfiguration compilerConfiguration = prepareCompilerConfiguration();
    ClassLoader classLoader = prepareClassLoader(AbstractDSLLauncher.class.getClassLoader());
    GroovyCodeSource groovyCodeSource = prepareGroovyCodeSource(dsl);

    // Groovy shell
    GroovyShell shell = new GroovyShell(
            classLoader,
            new Binding(),
            compilerConfiguration
    );

    // Groovy script
    Script groovyScript = shell.parse(groovyCodeSource);

    // Binding
    groovyScript.setBinding(binding);

    // Runs the script
    return run(groovyScript);
}
 
开发者ID:jenkinsci,项目名称:ontrack-plugin,代码行数:23,代码来源:AbstractDSLLauncher.java

示例2: processScenario

import groovy.lang.Script; //导入方法依赖的package包/类
/**
 * Post process every stored request just before it get saved to disk
 *
 * @param sampler recorded http-request (sampler)
 * @param tree   HashTree (XML like data structure) that represents exact recorded sampler
 */
public void processScenario(HTTPSamplerBase sampler, HashTree tree, Arguments userVariables, JMeterRecorder recorder)
{
    Binding binding = new Binding();
    binding.setVariable(ScriptBindingConstants.LOGGER, LOG);
    binding.setVariable(ScriptBindingConstants.SAMPLER, sampler);
    binding.setVariable(ScriptBindingConstants.TREE, tree);
    binding.setVariable(ScriptBindingConstants.CONTEXT, recorder.getContext());
    binding.setVariable(ScriptBindingConstants.JSFLIGHT, JMeterJSFlightBridge.getInstance());
    binding.setVariable(ScriptBindingConstants.USER_VARIABLES, userVariables);
    binding.setVariable(ScriptBindingConstants.CLASSLOADER, classLoader);

    Script compiledProcessScript = ScriptEngine.getScript(getScenarioProcessorScript());
    if (compiledProcessScript == null)
    {
        return;
    }
    compiledProcessScript.setBinding(binding);
    LOG.info("Run compiled script");
    try {
        compiledProcessScript.run();
    } catch (Throwable throwable) {
        LOG.error(throwable.getMessage(), throwable);
    }
}
 
开发者ID:d0k1,项目名称:jsflight,代码行数:31,代码来源:JMeterScriptProcessor.java

示例3: evaluate

import groovy.lang.Script; //导入方法依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating Groovy expression: {1}", expression);
    try {
        final ObjectCache<String, Script> scriptCache = threadScriptCache.get();
        Script script = scriptCache.get(expression);
        if (script == null) {
            script = GROOVY_SHELL.parse(expression);
            scriptCache.put(expression, script);
        }

        final Binding binding = new Binding();
        for (final Entry<String, ?> entry : values.entrySet()) {
            binding.setVariable(entry.getKey(), entry.getValue());
        }
        script.setBinding(binding);
        return script.run();
    } catch (final Exception ex) {
        throw new ExpressionEvaluationException("Evaluating script with Groovy failed.", ex);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:21,代码来源:ExpressionLanguageGroovyImpl.java

示例4: build

import groovy.lang.Script; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:FactoryBuilderSupport.java

示例5: invoke

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
public SwampScriptInvokationResult invoke(SwampBinding binding) {
    Validate.notNull(binding, "Binding cannot be null.");
    GroovyInvokationResult result = new GroovyInvokationResult();
    try {
        Script invokableScript = compiledScript.getClass().newInstance();
        invokableScript.setBinding((GroovyBinding) binding);
        Object resultObject = invokableScript.run();
        result.setVariables(new HashMap<>(binding.getVariableMap()));
        result.getVariables().put(SCRIPT_RESULT, resultObject);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

    return result;
}
 
开发者ID:kibertoad,项目名称:swampmachine,代码行数:17,代码来源:GroovyScript.java

示例6: testGroovyShell

import groovy.lang.Script; //导入方法依赖的package包/类
@Test
public void testGroovyShell() throws Exception {
    GroovyShell groovyShell = new GroovyShell();
    final String s = "x  > 2  &&  y  > 1";
    Script script = groovyShell.parse(s);

    Binding binding = new Binding();
    binding.setProperty("x",5);
    binding.setProperty("y",3);
    script.setBinding(binding);

    Object result = script.run();
    Assert.assertEquals(true, result);
    log.debug("evaluating [{}] with (x,y)=({},{}) => {}\n", s,
            script.getBinding().getProperty("x"), script.getBinding().getProperty("y"), result);

    binding.setProperty("y",0);
    result = script.run();
    Assert.assertEquals(false, result);
    log.debug("evaluating [{}] with (x,y)=({},{}) => {}\n", s,
            binding.getProperty("x"), binding.getProperty("y"), result);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:23,代码来源:GroovyTest.java

示例7: testGroovyShell_goodBindingFollowedByBadBinding_Exception

import groovy.lang.Script; //导入方法依赖的package包/类
@Test(expected = groovy.lang.MissingPropertyException.class)
public void testGroovyShell_goodBindingFollowedByBadBinding_Exception() throws Exception {
    GroovyShell groovyShell = new GroovyShell();
    final String s = "x  > 2  &&  y  > 1";
    Script script = groovyShell.parse(s);

    Binding binding = new Binding();
    binding.setProperty("x", 5);
    binding.setProperty("y", 3);
    script.setBinding(binding);

    Object result = script.run();
    Assert.assertEquals(true, result);

    Assert.assertTrue(binding.hasVariable("x"));

    binding = new Binding();
    binding.setProperty("x1", 5);
    binding.setProperty("y1", 3);
    script.setBinding(binding);

    Assert.assertFalse(binding.hasVariable("x"));

    script.run();  // throws exception because no bindings for x, y
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:26,代码来源:GroovyTest.java

示例8: runScript

import groovy.lang.Script; //导入方法依赖的package包/类
private void runScript(String script) throws Exception {
  Vertx vertx = Vertx.vertx();
  try {
    GroovyShell gcl = new GroovyShell();
    Script s = gcl.parse(new File(script));
    Binding binding = new Binding();
    binding.setProperty("test", this);
    binding.setProperty("vertx", vertx);
    s.setBinding(binding);
    s.run();
  } finally {
    CountDownLatch latch = new CountDownLatch(1);
    vertx.close(v -> {
      latch.countDown();
    });
    latch.await();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:19,代码来源:GroovyIntegrationTest.java

示例9: runReport

import groovy.lang.Script; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void runReport(Map<String, Object> extra) {
    try
    {
        rows = new ArrayList<Map<String, Object>>();
        Script script = groovyShell.parse(groovyScript);
        script.setBinding(new Binding());
        script.getBinding().setVariable("rows", rows);
        script.getBinding().setVariable("columns", getColumns());
        script.getBinding().setVariable("page", getPage());
        script.getBinding().setVariable("pageLimit", getPageLimit());
        script.getBinding().setVariable("paramConfig", getParameterConfig());
        script.getBinding().setVariable("param", new HashMap<String, ParamConfig>() {{
            for (ParamConfig paramConfig : getParameterConfig()) {
                put(paramConfig.getId(), paramConfig);
            }
        }});
        script.getBinding().setVariable("extra", extra);
        script.run();
    } catch (Exception ex)
    {
        ex.printStackTrace();
        getErrors().add(ex.getMessage());
    }
}
 
开发者ID:base2Services,项目名称:kagura,代码行数:29,代码来源:GroovyDataReportConnector.java

示例10: doLoad

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
protected void doLoad(Reader reader, String fileName) {
    Script script = shell.parse(reader, fileName);
    script.setBinding(binding);
    script.run();

    // Add the last script as the first.
    scripts.add(0, script);
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:10,代码来源:GroovyKnowledgeBaseInterpreter.java

示例11: executeScript

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
public Object executeScript(String groovyScript, Map<String, Object> parameters) throws WorkflowException {
    try {
        Script script = scriptCache.get(groovyScript);
        script.setBinding(fromMap(parameters));
        return script.run();
    } catch (ExecutionException ex) {
        throw new WorkflowException("Error executing groovy script", ex);
    }
}
 
开发者ID:AndreyVMarkelov,项目名称:jira-groovioli,代码行数:11,代码来源:ScriptManagerImpl.java

示例12: execute

import groovy.lang.Script; //导入方法依赖的package包/类
private static final Object execute(String methodBody, Map<String, Object> bindings) throws Exception {
    Binding binding = new Binding();

    // Bind parameters
    if (bindings != null && bindings.size() > 0) {
        Set<String> keys = bindings.keySet();

        for (String key : keys) {
            binding.setVariable(key, bindings.get(key));
        }
    }

    String cacheKey = new StringBuilder(CACHE_KEY_PREFIX_MATCHER_CONDITION).append(Str.AT)
        .append(methodBody.hashCode()).toString();

    Script parsedScript = (Script) cache.get(cacheKey);

    if (parsedScript == null) {
        parsedScript = shell.parse(methodBody);
        Script cachedParsedScript = (Script) cache.putIfAbsent(cacheKey, parsedScript);

        if (cachedParsedScript != null)
            parsedScript = cachedParsedScript;
    }

    parsedScript.setBinding(binding);

    return parsedScript.run();
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:30,代码来源:Groovy.java

示例13: executeGPath

import groovy.lang.Script; //导入方法依赖的package包/类
private void executeGPath() throws ActivityException {
    String transform = (String) getAttributeValue(RULE);
    if (StringHelper.isEmpty(transform)) {
        logger.info("No transform defined for activity: " + getActivityName());
        return;
    }

    GroovyShell shell = new GroovyShell(getClass().getClassLoader());
    Script script = shell.parse(transform);
    Binding binding = new Binding();

    Variable inputVar = getMainProcessDefinition().getVariable(inputDocument);
    if (inputVar == null)
      throw new ActivityException("Input document variable not found: " + inputDocument);
    String inputVarName = inputVar.getName();
    Object inputVarValue = getGPathParamValue(inputVarName, inputVar.getType());
    binding.setVariable(inputVarName, inputVarValue);

    Variable outputVar = getMainProcessDefinition().getVariable(getOutputDocuments()[0]);
    String outputVarName = outputVar.getName();
    Object outputVarValue = getGPathParamValue(outputVarName, outputVar.getType());
    binding.setVariable(outputVarName, outputVarValue);

    script.setBinding(binding);

    script.run();

    Object groovyVarValue = binding.getVariable(outputVarName);
    setGPathParamValue(outputVarName, outputVar.getType(), groovyVarValue);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:31,代码来源:TransformActivity.java

示例14: execute

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
public ScriptExecutionResult execute(GameScript<Script> script, ScriptBindings bindings, boolean returnResult) throws Exception {
	Script groovyScript = script.getScript();
	groovyScript.setBinding(new Binding(bindings));
	groovyScript.run();
	
	return returnResult ? new ScriptExecutionResult(groovyScript.getBinding().getVariables()) : null;
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:9,代码来源:GroovyScriptExecutor.java

示例15: run

import groovy.lang.Script; //导入方法依赖的package包/类
public Action run(Binding binding) {
	Script script = getScript();
	if (script != null) {
		script.setBinding(binding);
		return (Action) script.run();
	}
	return null;
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:9,代码来源:AIScript.java


注:本文中的groovy.lang.Script.setBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。