1 package org.jicengine.operation; 2 3 import java.util.List ; 4 import java.util.ArrayList ; 5 6 15 16 public abstract class InvocationOperation implements Operation { 17 18 Operation actor; 19 Operation[] parameters; 20 21 String signature; 22 23 public InvocationOperation(String signature, Operation actor, Operation[] parameters) 24 { 25 this.actor = actor; 26 this.parameters = parameters; 27 this.signature = signature; 28 } 29 30 public boolean needsParameters() 31 { 32 return this.parameters.length > 0; 33 } 34 35 public boolean needsParameter(String name) 36 { 37 if( this.actor.needsParameter(name) ){ 38 return true; 39 } 40 41 for (int i = 0; i < this.parameters.length; i++) { 42 if( this.parameters[i].needsParameter(name) ){ 43 return true; 44 } 45 } 46 47 return false; 48 } 49 50 public Object execute(Context context) throws OperationException 51 { 52 Object actorObject = this.actor.execute(context); 53 Object [] arguments = evaluateParameters(this.parameters, context); 54 return execute(actorObject, arguments); 55 } 56 57 public String toString() 58 { 59 return this.signature; 60 } 61 62 protected abstract Object execute(Object actor, Object [] arguments) throws OperationException; 63 64 public static Object [] evaluateParameters(Operation[] parameters, Context context) throws OperationException 65 { 66 Object [] params = new Object [parameters.length]; 67 for (int i = 0; i < parameters.length; i++) { 68 params[i] = parameters[i].execute(context); 69 } 70 return params; 71 } 72 73 } 74
| Popular Tags
|