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


Java Binding.setVariable方法代码示例

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


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

示例1: process

import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public void process(Network network, ComputationManager computationManager) throws Exception {
    if (Files.exists(script)) {
        LOGGER.debug("Execute groovy post processor {}", script);
        try (Reader reader = Files.newBufferedReader(script, StandardCharsets.UTF_8)) {
            CompilerConfiguration conf = new CompilerConfiguration();

            Binding binding = new Binding();
            binding.setVariable("network", network);
            binding.setVariable("computationManager", computationManager);

            GroovyShell shell = new GroovyShell(binding, conf);
            shell.evaluate(reader);
        }
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:GroovyScriptPostProcessor.java

示例2: applyConfigurationScript

import groovy.lang.Binding; //导入方法依赖的package包/类
private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
    VersionNumber version = parseGroovyVersion();
    if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
        throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
    }
    Binding binding = new Binding();
    binding.setVariable("configuration", configuration);

    CompilerConfiguration configuratorConfig = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();
    customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
    configuratorConfig.addCompilationCustomizers(customizer);

    GroovyShell shell = new GroovyShell(binding, configuratorConfig);
    try {
        shell.evaluate(configScript);
    } catch (Exception e) {
        throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:ApiGroovyCompiler.java

示例3: getGroovyAttributeValue

import groovy.lang.Binding; //导入方法依赖的package包/类
private static Object getGroovyAttributeValue(final String groovyScript,
                                              final Map<String, Object> resolvedAttributes) {
    try {
        final Binding binding = new Binding();
        final GroovyShell shell = new GroovyShell(binding);
        binding.setVariable("attributes", resolvedAttributes);
        binding.setVariable("logger", LOGGER);

        LOGGER.debug("Executing groovy script [{}] with attributes binding of [{}]",
                StringUtils.abbreviate(groovyScript, groovyScript.length() / 2), resolvedAttributes);
        final Object res = shell.evaluate(groovyScript);
        return res;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:ReturnMappedAttributeReleasePolicy.java

示例4: getValue

import groovy.lang.Binding; //导入方法依赖的package包/类
@Nonnull
@Override
public Object getValue(@Nonnull CpsScript script) throws Exception {
    Binding binding = script.getBinding();
    script.println();
    Object openshift;
    if (binding.hasVariable(getName())) {
        openshift = binding.getVariable(getName());
    } else {
        // Note that if this were a method rather than a constructor, we
        // would need to mark it @NonCPS lest it throw
        // CpsCallableInvocation.
        openshift = script.getClass().getClassLoader()
                .loadClass("com.openshift.jenkins.plugins.OpenShiftDSL")
                .getConstructor(CpsScript.class).newInstance(script);
        binding.setVariable(getName(), openshift);
    }
    return openshift;

}
 
开发者ID:openshift,项目名称:jenkins-client-plugin,代码行数:21,代码来源:OpenShiftGlobalVariable.java

示例5: createBinding

import groovy.lang.Binding; //导入方法依赖的package包/类
private Binding createBinding(Map<String, Object> objects, OutputStream out, OutputStream err)
	throws UnsupportedEncodingException {
	Binding binding = new Binding();

	if (objects != null)
		for (Map.Entry<String, Object> row : objects.entrySet())
			binding.setVariable(row.getKey(), row.getValue());

	binding.setVariable("out", createPrintStream(out));
	binding.setVariable("err", createPrintStream(err));
	binding.setVariable("activeSessions", new Closure<List<AbstractSession>>(this) {
		@Override
		public List<AbstractSession> call() {
			return sshd.getActiveSessions();
		}
	});

	return binding;
}
 
开发者ID:jesse-gallagher,项目名称:xsp-groovy-shell,代码行数:20,代码来源:GroovyShellCommand.java

示例6: initClassStubData

import groovy.lang.Binding; //导入方法依赖的package包/类
@BeforeClass
public static void initClassStubData() throws IOException {
  GroovyEvaluator groovyEvaluator = new GroovyEvaluator("123", "345");

  GroovyDefaultVariables var = new GroovyDefaultVariables();
  HashMap<String, Object> params = new HashMap<>();
  params.put(KernelControlSetShellHandler.IMPORTS, var.getImports());
  params.put(KernelControlSetShellHandler.CLASSPATH, var.getClassPath());
  KernelParameters kernelParameters = new KernelParameters(params);

  groovyEvaluator.setShellOptions(kernelParameters);
  groovyClassLoader = groovyEvaluator.newEvaluator();
  scriptBinding = new Binding();
  scriptBinding.setVariable("beaker", NamespaceClient.getBeaker("345"));
  groovyKernel = new GroovyKernelMock();
  KernelManager.register(groovyKernel);
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:18,代码来源:GroovyEvaluatorTest.java

示例7: buildBinding

import groovy.lang.Binding; //导入方法依赖的package包/类
private Binding buildBinding(LepManagerService managerService,
                             LepMethod method) {
    Binding binding = new Binding();

    // add execution context values
    ScopedContext executionContext = managerService.getContext(ContextScopes.EXECUTION);
    if (executionContext != null) {
        executionContext.getValues().forEach(binding::setVariable);
    }

    // add method arg values
    final String[] parameterNames = method.getMethodSignature().getParameterNames();
    final Object[] methodArgValues = method.getMethodArgValues();
    for (int i = 0; i < parameterNames.length; i++) {
        String paramName = parameterNames[i];
        Object paramValue = methodArgValues[i];

        binding.setVariable(paramName, paramValue);
    }

    return binding;
}
 
开发者ID:xm-online,项目名称:xm-lep,代码行数:23,代码来源:GroovyLepExecutor.java

示例8: canBeAddedTo

import groovy.lang.Binding; //导入方法依赖的package包/类
/**
 * Returns how many times the supplied item can be added to the given slot
 * in the given bag by the given container. 0 means the item cannot be added
 * to the slot at all.
 * 
 * @param slot
 * @return
 */
public int canBeAddedTo(BagType bag, int slot, InventoryContainer container) {
	if (BagType.EQUIPPED.equals(bag)) {
		if (!checkEquippedSlot(slot, container)) {
			return 0;
		}
		
		if (s_equipCondition != null) {
			Binding binding = new Binding();
			binding.setVariable("slot", slot);
			binding.setVariable("item", this);
			return s_equipCondition.execute(container.getInventory().getConditionTarget(), binding) ? getStackSize() : 0;
		}
	} else if (BagType.QUICKUSE.equals(bag)) {
		if (!Condition.areResultsOk(canBeAddedToQuickUse(container))) {
			return 0;
		}
	}
	
	InventoryCheckResult checkResult = container.getInventory().canAddItem(this);
	if (checkResult.getError() != null) {
		Log.log(checkResult.getError(), LogType.INVENTORY);
	}
	
	return checkResult.getAllowedStackSize();
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:34,代码来源:InventoryItem.java

示例9: main

import groovy.lang.Binding; //导入方法依赖的package包/类
public static void main(String[] args) {
    List<String> rules = Lists.newArrayList();
    rules.add("S <= 10");
    rules.add("S + A <= 20");
    rules.add("S + A + BP <= 55");
    rules.add("C >= 5");

    Binding binding = new Binding();
    binding.setVariable("S", 5.0);
    binding.setVariable("A", 5.0);
    binding.setVariable("BP", 30.0);
    binding.setVariable("B", 30.0);
    binding.setVariable("C", 30.0);
    GroovyShell shell = new GroovyShell(binding);
    for (String rule : rules) {
        Object result = shell.evaluate(rule);
        System.out.println(result);
    }
}
 
开发者ID:yongli82,项目名称:dsl,代码行数:20,代码来源:CheckRuleDsl.java

示例10: loadFolderQuantity

import groovy.lang.Binding; //导入方法依赖的package包/类
protected boolean loadFolderQuantity(Binding binding, AppFolder folder) {
    if (!StringUtils.isBlank(folder.getQuantityScript())) {
        binding.setVariable("folder", folder);

        String styleVariable = "style";
        binding.setVariable(styleVariable, null);

        try {
            Number qty = runScript(folder.getQuantityScript(), binding);
            folder.setItemStyle((String) binding.getVariable(styleVariable));
            folder.setQuantity(qty == null ? null : qty.intValue());
        } catch (Exception e) {
            log.warn("Unable to evaluate AppFolder quantity script for folder: id: {} , name: {}",
                    folder.getId(), folder.getName(), e);
            return false;
        }
    }

    return true;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:FoldersServiceBean.java

示例11: run

import groovy.lang.Binding; //导入方法依赖的package包/类
/**
 * Standalone execution for Designer and Gradle.
 */
public void run() {
    startExecution();

    CompilerConfiguration compilerConfig = new CompilerConfiguration(System.getProperties());
    compilerConfig.setScriptBaseClass(TestCaseScript.class.getName());
    Binding binding = new Binding();
    binding.setVariable("testCaseRun", this);

    ClassLoader classLoader = this.getClass().getClassLoader();
    GroovyShell shell = new GroovyShell(classLoader, binding, compilerConfig);
    shell.setProperty("out", getLog());
    setupContextClassLoader(shell);
    try {
        shell.run(new GroovyCodeSource(getTestCase().file()), new String[0]);
        finishExecution(null);
    }
    catch (IOException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:24,代码来源:StandaloneTestCaseRun.java

示例12: runGroovyScript

import groovy.lang.Binding; //导入方法依赖的package包/类
@Authenticated
@Override
public String runGroovyScript(String scriptName) {
    try {
        Binding binding = new Binding();
        binding.setVariable("persistence", persistence);
        binding.setVariable("metadata", metadata);
        binding.setVariable("configuration", configuration);
        binding.setVariable("dataManager", dataManager);
        Object result = scripting.runGroovyScript(scriptName, binding);
        return String.valueOf(result);
    } catch (Exception e) {
        log.error("Error runGroovyScript", e);
        return ExceptionUtils.getStackTrace(e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:ScriptingManager.java

示例13: evaluate

import groovy.lang.Binding; //导入方法依赖的package包/类
public Object evaluate(String expression, Map<String, Object> bindings)
throws ExecutionException {
    binding = new Binding();

    for (String bindName : bindings.keySet()) {
        Object value = bindings.get(bindName);
        DocumentReferenceTranslator docRefTranslator = getDocRefTranslator(value);
        if (docRefTranslator != null) {
            try {
                if (!(docRefTranslator instanceof XmlBeanWrapperTranslator)) {
                    value = new XmlSlurper().parseText(docRefTranslator.realToString(value));
                }
            }
            catch (Exception ex) {
                throw new ExecutionException("Cannot parse document content: '" + bindName + "'", ex);
            }
        }
        binding.setVariable(bindName, value);
    }

    return runScript(expression);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:23,代码来源:GroovyExecutor.java

示例14: getValue

import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public String getValue(String orginData)
{
	String value;
	
	Binding binding = new Binding();
	GroovyShell shell = new GroovyShell(binding);
	
	binding.setVariable("globalMap", globalMap);
	Object resObj = null;
	try
	{
		resObj = shell.evaluate(groovyCls + orginData);
		if(resObj != null)
		{
			value = resObj.toString();
		}
		else
	 	{
			value = "groovy not return!";
		}
	}
	catch(CompilationFailedException e)
	{
		value = e.getMessage();
           logger.error("Groovy动态数据语法错误!", e);
	}
	
	return value;
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:31,代码来源:GroovyDynamicData.java

示例15: main

import groovy.lang.Binding; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
	{
		Binding binding = new Binding();
		binding.setVariable("language", "Groovy");
		
		GroovyShell shell = new GroovyShell(binding);
		
		GroovyScriptEngine engine = new GroovyScriptEngine(new URL[]{GroovyTest.class.getClassLoader().getResource("/")});
		Script script = shell.parse(GroovyTest.class.getClassLoader().getResource("random.groovy").toURI());
		
//		System.out.println(script);
//		script.invokeMethod("new SuRenRandom()", null);
//		script.evaluate("new SuRenRandom()");
//		engine.run("random.groovy", binding);
		
		InputStream stream = GroovyTest.class.getClassLoader().getResource("random.groovy").openStream();
		StringBuffer buf = new StringBuffer();
		byte[] bf = new byte[1024];
		int len = -1;
		while((len = stream.read(bf)) != -1)
		{
			buf.append(new String(bf, 0, len));
		}
		buf.append("\n");
		
		for(int i = 0; i < 30; i++)
		{
			System.out.println(shell.evaluate(buf.toString() + "new SuRenRandom().randomPhoneNum()"));
			System.out.println(shell.evaluate(buf.toString() + "new SuRenRandom().randomEmail()"));
			System.out.println(shell.evaluate(buf.toString() + "new SuRenRandom().randomZipCode()"));
		}
	}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:33,代码来源:GroovyTest.java


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