當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。