01: package org.jicengine.operation;
02:
03: /**
04: * <p>
05: * Obtains a <code>Factory</code> instance from the context
06: * and executes it.
07: * </p>
08: *
09: *
10: * @author timo laitinen
11: */
12: public class FactoryInvocationOperation implements Operation {
13:
14: private String factoryName;
15: private Operation[] parameters;
16:
17: /**
18: *
19: * @param name the name that the factory is stored into the context.
20: * @param parameters the parameters given to the factory.
21: */
22: public FactoryInvocationOperation(String name,
23: Operation[] parameters) {
24: this .factoryName = name;
25: this .parameters = parameters;
26: }
27:
28: public boolean needsParameters() {
29: return this .parameters.length > 0;
30: }
31:
32: public boolean needsParameter(String name) {
33: for (int i = 0; i < this .parameters.length; i++) {
34: if (this .parameters[i].needsParameter(name)) {
35: return true;
36: }
37: }
38: return false;
39: }
40:
41: public Object execute(Context context) throws OperationException {
42: Factory factory = (Factory) context.getObject(this .factoryName);
43:
44: Object[] arguments = MethodInvocationOperation
45: .evaluateParameters(this .parameters, context);
46:
47: Object result = factory.invoke(arguments);
48:
49: return result;
50: }
51: }
|