1 package org.jicengine.operation; 2 3 14 15 public class VariableValueOperation implements Operation { 16 17 String name; 18 19 public VariableValueOperation(String objectName) 20 { 21 this.name = objectName; 23 } 24 25 public String getName() 26 { 27 return this.name; 28 } 29 30 public boolean needsParameters() 31 { 32 return true; 33 } 34 35 public boolean needsParameter(String name) 36 { 37 return (this.name.equals(name)); 38 } 39 40 public static Object lookup(String name, Context context) throws OperationException 41 { 42 try { 43 return context.getObject(name); 44 } catch (Exception e2){ 45 throw new OperationException("Failed to find object '" + name + "'.",e2); 46 } 47 } 48 49 public Object execute(Context context) throws OperationException 50 { 51 Object value = lookup(getName(), context); 52 if( value != null ){ 53 return value; 54 } 55 else { 56 throw new OperationException("Object named '" + getName() + "' not found in context " + context); 57 } 58 } 59 60 public String toString() 61 { 62 return getName(); 63 } 64 } 65 | Popular Tags |