1 package org.jicengine.operation; 2 3 4 11 12 public class FieldValueOperation implements Operation { 13 14 15 private Operation actor; 16 private String field; 17 private String signature; 18 19 public FieldValueOperation(String signature, Operation actor, String field) 20 { 21 this.signature = signature; 22 this.actor = actor; 23 this.field = field; 24 } 25 26 public boolean needsParameters() 27 { 28 return this.actor.needsParameters(); 29 } 30 31 public boolean needsParameter(String name) 32 { 33 return this.actor.needsParameter(name); 34 } 35 36 public Object execute(Context context) throws OperationException 37 { 38 Object actorObject = this.actor.execute(context); 39 40 try { 41 if( actorObject instanceof Class ){ 42 return ReflectionUtils.getFieldValue(null, (Class )actorObject, this.field); 44 } 45 else { 46 return ReflectionUtils.getFieldValue(actorObject, actorObject.getClass(), this.field); 48 } 49 } catch (java.lang.reflect.InvocationTargetException e){ 50 throw new OperationException("'" + toString() + "' resulted in exception", e.getTargetException()); 53 } catch (Exception e2){ 54 throw new OperationException("'" + toString() + "': " + e2.getMessage(), e2); 55 } 56 } 57 58 public String toString() 59 { 60 return this.signature; 61 } 62 } 63
| Popular Tags
|