本文整理匯總了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);
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}