本文整理汇总了Java中groovy.lang.Binding.getVariable方法的典型用法代码示例。如果您正苦于以下问题:Java Binding.getVariable方法的具体用法?Java Binding.getVariable怎么用?Java Binding.getVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类groovy.lang.Binding
的用法示例。
在下文中一共展示了Binding.getVariable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: execute
import groovy.lang.Binding; //导入方法依赖的package包/类
/**
* Evaluates this condition on the supplied object and with the supplied parameters.
*
* The supplied parameters can contain special keys (see the PARAM_
* constants in this class).
*
* If such parameters are provided and this condition has a targetObject
* param specified, one of these will be used when evaluating instead of
* whatever was passed in as the object.
*
* @param object
* - on which object his should be executed. Depending on the
* parameters passed, this might not actually be used
* @param parameters
* @return true if the condition evaluated as true, false otherwise
*/
public final boolean execute(Object object, Binding parameters) {
if (getParameter(PARAM_TARGET_OBJECT) != null) {
String testObject = getParameter(PARAM_TARGET_OBJECT);
if (PARAM_PC_AT_DIALOGUE.equals(testObject)) {
object = parameters.getVariable(testObject);
} else if (PARAM_NPC_AT_DIALOGUE.equals(testObject)) {
object = parameters.getVariable(testObject);
} else if (PARAM_ENTERING_CHARACTER.equals(testObject)) {
object = parameters.getVariable(testObject);
} else if (PARAM_USER.equals(testObject)) {
object = parameters.getVariable(testObject);
} else if (PARAM_PLAYER.equals(testObject)) {
object = GameState.getPlayerCharacterGroup();
} else if (PARAM_GLOBAL.equals(testObject)) {
object = gameState.variables();
} else {
object = GameState.getGameObjectById(testObject);
}
}
boolean returnValue = evaluate(object, parameters);
Log.log("Evaluated {0} with parameters {1} on object {2}, condition returned {3}", Log.LogType.CONDITION, this.getClass().getName(), Arrays.toString(conditionParameters), object, returnValue);
return returnValue;
}
示例3: run
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
protected void run(Object object, Binding parameters) {
GameCharacter targetCharacter, sourceCharacter;
GameCharacter npc = (GameCharacter) parameters.getVariable(PARAM_NPC_AT_DIALOGUE);
GameCharacter pc = (GameCharacter) parameters.getVariable(PARAM_PC_AT_DIALOGUE);
if (CoreUtil.equals(object, pc)) {
targetCharacter = npc;
sourceCharacter = pc;
} else {
targetCharacter = pc;
sourceCharacter = npc;
}
String itemId = getParameter(XML_ITEM);
InventoryItem item = sourceCharacter != null ? sourceCharacter.getInventory().getItem(itemId) : null;
if (item == null) {
item = InventoryItem.getItem(itemId);
}
targetCharacter.getInventory().addItem(item);
Log.logLocalized("itemReceived", LogType.INVENTORY, item.getName(), targetCharacter.getName());
}
示例4: getValue
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override public Object getValue(CpsScript script) throws Exception {
Binding binding = script.getBinding();
Object gerrit;
if (binding.hasVariable(getName())) {
gerrit = 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.
gerrit = script.getClass().getClassLoader().loadClass("jenkins.plugins.gerrit.workflow.Gerrit").getConstructor(CpsScript.class).newInstance(script);
binding.setVariable(getName(), gerrit);
}
return gerrit;
}
示例5: getGroovyRenderer
import groovy.lang.Binding; //导入方法依赖的package包/类
private PrimitiveRenderer getGroovyRenderer() throws IOException, ResourceException, ScriptException {
if (this.groovyRenderer == null) {
GroovyScriptEngine gse = this.getGroovyScriptEngine();
Binding binding = this.getBinding();
gse.run(this.groovyFile.getName(), binding);
this.groovyRenderer = (PrimitiveRenderer) binding.getVariable("renderer");
}
return this.groovyRenderer;
}
示例6: executeGPath
import groovy.lang.Binding; //导入方法依赖的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);
}
示例7: run
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
protected void run(Object object, Binding parameters) {
GameCharacter pc = (GameCharacter) parameters.getVariable(PARAM_PC_AT_DIALOGUE);
GameCharacter npc = (GameCharacter) parameters.getVariable(PARAM_NPC_AT_DIALOGUE);
if (npc.canTradeWith(Faction.PLAYER_FACTION)) {
UIManager.displayTradingInventory(pc, npc);
} else {
UIManager.displayMessage(npc.getName(), Strings.getString(Faction.STRING_TABLE,"CannotTrade"));
}
}
示例8: run
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
protected void run(Object object, Binding parameters) {
if (object instanceof AbstractGameCharacter) {
String talkerId = getParameter(XML_DIALOGUE_NPC);
String dialogueId = getParameter(XML_DIALOGUE_ID);
if (dialogueId == null) {
Object initialObject = parameters.getVariable(PARAM_INITIAL_OBJECT);
if (initialObject instanceof ThingWithId) {
dialogueId = ((ThingWithId)initialObject).getId();
}
}
if (dialogueId == null) {
Log.log("No dialogue id found for object .", LogType.ERROR, object);
return;
}
if (talkerId != null && talkerId.startsWith("__")) {
Object talkerIdObject = parameters.getVariable(talkerId);
if (talkerIdObject instanceof ThingWithId) {
talkerId = ((ThingWithId)talkerIdObject).getId();
}
}
final GameCharacter talker = talkerId != null ? (GameCharacter) GameState.getGameObjectById(talkerId, GameCharacter.class)
: null;
UIManager.displayDialogue(((AbstractGameCharacter) object).getRepresentative(), talker, dialogueId,
new DialogueCallback() {
@Override
public void onDialogueEnd(PCTalk dialogueStopper) {
if (talker != null) {
talker.setMetNPCBefore(true);
}
}
}, null);
}
}
示例9: getProperty
import groovy.lang.Binding; //导入方法依赖的package包/类
/**
* This method overrides property retrieval in the scope of the
* GroovyBeanDefinitionReader to either:
* <ul>
* <li>Retrieve a variable from the bean builder's binding if it exists
* <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
* <li>Otherwise just delegate to MetaClass.getProperty which will resolve
* properties from the GroovyBeanDefinitionReader itself
* </ul>
*/
public Object getProperty(String name) {
Binding binding = getBinding();
if (binding != null && binding.hasVariable(name)) {
return binding.getVariable(name);
}
else {
if (this.namespaces.containsKey(name)) {
return createDynamicElementReader(name);
}
if (getRegistry().containsBeanDefinition(name)) {
GroovyBeanDefinitionWrapper beanDefinition = (GroovyBeanDefinitionWrapper)
getRegistry().getBeanDefinition(name).getAttribute(GroovyBeanDefinitionWrapper.class.getName());
if (beanDefinition != null) {
return new GroovyRuntimeBeanReference(name, beanDefinition, false);
}
else {
return new RuntimeBeanReference(name, false);
}
}
// This is to deal with the case where the property setter is the last
// statement in a closure (hence the return value)
else if (this.currentBeanDefinition != null) {
MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
if (pvs.contains(name)) {
return pvs.get(name);
}
else {
DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
if (dp != null) {
return dp.value;
}
else {
return getMetaClass().getProperty(this, name);
}
}
}
else {
return getMetaClass().getProperty(this, name);
}
}
}
示例10: getProperty
import groovy.lang.Binding; //导入方法依赖的package包/类
/**
* This method overrides property retrieval in the scope of the
* {@code GroovyBeanDefinitionReader} to either:
* <ul>
* <li>Retrieve a variable from the bean builder's binding if it exists
* <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
* <li>Otherwise just delegate to MetaClass.getProperty which will resolve
* properties from the {@code GroovyBeanDefinitionReader} itself
* </ul>
*/
public Object getProperty(String name) {
Binding binding = getBinding();
if (binding != null && binding.hasVariable(name)) {
return binding.getVariable(name);
}
else {
if (this.namespaces.containsKey(name)) {
return createDynamicElementReader(name);
}
if (getRegistry().containsBeanDefinition(name)) {
GroovyBeanDefinitionWrapper beanDefinition = (GroovyBeanDefinitionWrapper)
getRegistry().getBeanDefinition(name).getAttribute(GroovyBeanDefinitionWrapper.class.getName());
if (beanDefinition != null) {
return new GroovyRuntimeBeanReference(name, beanDefinition, false);
}
else {
return new RuntimeBeanReference(name, false);
}
}
// This is to deal with the case where the property setter is the last
// statement in a closure (hence the return value)
else if (this.currentBeanDefinition != null) {
MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
if (pvs.contains(name)) {
return pvs.get(name);
}
else {
DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
if (dp != null) {
return dp.value;
}
else {
return getMetaClass().getProperty(this, name);
}
}
}
else {
return getMetaClass().getProperty(this, name);
}
}
}