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


Java Binding类代码示例

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


Binding类属于groovy.lang包,在下文中一共展示了Binding类的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: executeScript

import groovy.lang.Binding; //导入依赖的package包/类
/**
 * Executes any script.
 *
 * @param scriptResourceKey        current script resource key
 * @param proceedingLep            method proceed for Around scripts
 * @param method                   LEP method
 * @param managerService           LEP manager service
 * @param resourceExecutorSupplier LEP resource script executor supplier
 * @param methodResult             LEP method result
 * @param overrodeArgValues        arg values to override (can be {@code null})
 * @return Groovy script binding
 * @throws LepInvocationCauseException when exception in script occurs
 */
static Object executeScript(UrlLepResourceKey scriptResourceKey,
                            ProceedingLep proceedingLep, // can be null
                            LepMethod method,
                            LepManagerService managerService,
                            Supplier<GroovyScriptRunner> resourceExecutorSupplier,
                            LepMethodResult methodResult, // can be null
                            Object... overrodeArgValues) throws LepInvocationCauseException {

    GroovyScriptRunner runner = resourceExecutorSupplier.get();
    String scriptName = runner.getResourceKeyMapper().map(scriptResourceKey);

    Binding binding = buildBinding(scriptResourceKey, managerService, method, proceedingLep, methodResult,
                                   overrodeArgValues);

    return runner.runScript(scriptResourceKey, method, managerService, scriptName, binding);

}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:31,代码来源:LepScriptUtils.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: interpret

import groovy.lang.Binding; //导入依赖的package包/类
public static EObject interpret(String groovyScript) {
		EDataType data =  EcorePackage.eINSTANCE.getEString();				
		Binding binding = new Binding();

		//Binding setVariable allow to pass a variable from the moonti arc model to the groovy interpreter
		//binding.setVariable(name, value);
		
		 GroovyShell shell = new GroovyShell(binding);		    
		    Object result = shell.evaluate(groovyScript);
		    
		    //Binding.getVariable get the new value of this variable. 
//		    binding.getVariable(name)

		    
		    //		data.setName(""+(rand.nextInt(100)+1));
		data.setName(""+result);
		return data;
	}
 
开发者ID:awortmann,项目名称:xmontiarc,代码行数:19,代码来源:GroovyInterpreter.java

示例10: getBinding

import groovy.lang.Binding; //导入依赖的package包/类
/** Returns a <code>Binding</code> instance initialized with the
 * variables contained in <code>context</code>. If <code>context</code>
 * is <code>null</code>, an empty <code>Binding</code> is returned.
 * <p>The <code>context Map</code> is added to the <code>Binding</code>
 * as a variable called "context" so that variables can be passed
 * back to the caller. Any variables that are created in the script
 * are lost when the script ends unless they are copied to the
 * "context" <code>Map</code>.</p>
 * 
 * @param context A <code>Map</code> containing initial variables
 * @return A <code>Binding</code> instance
 */
public static Binding getBinding(Map<String, Object> context) {
    Map<String, Object> vars = new HashMap<String, Object>();
    if (context != null) {
        vars.putAll(context);
        vars.put("context", context);
        if (vars.get(ScriptUtil.SCRIPT_HELPER_KEY) == null) {
            ScriptContext scriptContext = ScriptUtil.createScriptContext(context);
            ScriptHelper scriptHelper = (ScriptHelper)scriptContext.getAttribute(ScriptUtil.SCRIPT_HELPER_KEY);
            if (scriptHelper != null) {
                vars.put(ScriptUtil.SCRIPT_HELPER_KEY, scriptHelper);
            }
        }
    }
    return new Binding(vars);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:28,代码来源:GroovyUtil.java

示例11: GroovyScript

import groovy.lang.Binding; //导入依赖的package包/类
/**
 * Instantiates a new groovy script.
 * 
 * @param script
 *            the script
 * @param timeout
 * @throws IOException
 * @throws CompilationFailedException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
public GroovyScript(final String script, final String id,
		final WrappedProcess process, final String[] args,
		final int timeout, final InternalLogger logger, String encoding,
		boolean reload, int maxConcInvocations)
		throws CompilationFailedException, IOException,
		InstantiationException, IllegalAccessException,
		ClassNotFoundException
{
	super(script, id, process, args, timeout, maxConcInvocations);
	_reload = reload;
	_encoding = encoding;

	// let's call some method on an instance
	_script = getScriptInstance(script, encoding);
	binding = (Binding) _script.invokeMethod("getBinding", null);
	binding.setVariable("args", args);
	binding.setVariable("callCount", 0);
	binding.setVariable("context", context);
	if (process != null && logger == null)
		_logger = process.getInternalWrapperLogger();
	else
		_logger = logger;
	binding.setVariable("logger", _logger);
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:37,代码来源:GroovyScript.java

示例12: evaluate

import groovy.lang.Binding; //导入依赖的package包/类
@Override
protected boolean evaluate(Object object, Binding parameters) {
	if (object instanceof GameCharacter) {
		GameCharacter character = (GameCharacter) object;
		Skill skill = Skill.valueOf(getParameter(XML_SKILL_NAME).toUpperCase(Locale.ENGLISH));
		int rank = character.stats().skills().getSkillRank(skill);
		if (Boolean.valueOf(getParameter(XML_MINUMUM_SKILL_LEVEL))) {
			if (rank < character.stats().skills().getBaseSkillRank(skill)) {
				rank = character.stats().skills().getBaseSkillRank(skill);
			}
		}
		String minRank = getParameter(XML_MINUMUM_SKILL_LEVEL);
		if (minRank == null)  {
			return rank > 0;
		} else {
			return rank >= Integer.parseInt(minRank);
		}
	}
	return false;
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:21,代码来源:HasSkill.java

示例13: applyConfigurationScript

import groovy.lang.Binding; //导入依赖的package包/类
private static void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
  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);

  try {
    new GroovyShell(binding, configuratorConfig).evaluate(configScript);
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DependentGroovycRunner.java

示例14: evaluate

import groovy.lang.Binding; //导入依赖的package包/类
@Override
protected boolean evaluate(Object object, Binding parameters) {
	String itemId = getParameter(XML_ITEM_NAME);
	InventoryItem item = null;
	if (object instanceof GameCharacter) {
		item = ((GameCharacter) object).getInventory().getItem(itemId);
	} else if (object instanceof CharacterGroup) {
		for (GameCharacter character : ((CharacterGroup)object).getMembers()) {
			item = character.getInventory().getItem(itemId);
		}
		
	}
	if (item != null && item.getInventoryBag() == BagType.EQUIPPED) {
		return true;
	}
	return false;
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:18,代码来源:HasItemEquipped.java

示例15: runGroovy

import groovy.lang.Binding; //导入依赖的package包/类
public static void runGroovy(int xmax, int ymax, int zmax) {
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    String expression = "x + y*2 - z";
    Integer result = 0;
    Date start = new Date();
    for (int xval = 0; xval < xmax; xval++) {
        for (int yval = 0; yval < ymax; yval++) {
            for (int zval = 0; zval <= zmax; zval++) {
                binding.setVariable("x", xval);
                binding.setVariable("y", yval);
                binding.setVariable("z", zval);
                Integer cal = (Integer) shell.evaluate(expression);
                result += cal;
            }
        }
    }
    Date end = new Date();
    System.out.println("Groovy:time is : " + (end.getTime() - start.getTime()) + ",result is " + result);
}
 
开发者ID:brucefengnju,项目名称:eldemo,代码行数:21,代码来源:RunPerform.java


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