KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > operation > FactoryInvocationOperation


1 package org.jicengine.operation;
2
3
4 /**
5  * <p>
6  * Obtains a <code>Factory</code> instance from the context
7  * and executes it.
8  * </p>
9  *
10  *
11  * @author timo laitinen
12  */

13 public class FactoryInvocationOperation implements Operation {
14
15     private String JavaDoc factoryName;
16     private Operation[] parameters;
17
18   /**
19    *
20    * @param name the name that the factory is stored into the context.
21    * @param parameters the parameters given to the factory.
22    */

23     public FactoryInvocationOperation(String JavaDoc name, Operation[] parameters)
24     {
25         this.factoryName = name;
26         this.parameters = parameters;
27     }
28
29     public boolean needsParameters()
30     {
31         return this.parameters.length > 0;
32     }
33
34     public boolean needsParameter(String JavaDoc name)
35     {
36         for (int i = 0; i < this.parameters.length; i++) {
37             if( this.parameters[i].needsParameter(name) ){
38                 return true;
39             }
40         }
41         return false;
42     }
43
44     public Object JavaDoc execute(Context context) throws OperationException
45     {
46         Factory factory = (Factory) context.getObject(this.factoryName);
47
48         Object JavaDoc[] arguments = MethodInvocationOperation.evaluateParameters(this.parameters,context);
49
50         Object JavaDoc result = factory.invoke(arguments);
51
52         return result;
53     }
54 }
55
56
Popular Tags