KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jicengine.operation;
2
3 /**
4  *
5  * <p>
6  * Copyright (C) 2004 Timo Laitinen
7  * </p>
8  *
9  * @author Timo Laitinen
10  * @created 2004-09-20
11  * @since JICE-0.10
12  *
13  */

14
15 public class VariableValueOperation implements Operation {
16
17     String JavaDoc name;
18
19     public VariableValueOperation(String JavaDoc objectName)
20     {
21         // todo: check that the name is valid?
22
this.name = objectName;
23     }
24
25     public String JavaDoc getName()
26     {
27         return this.name;
28     }
29
30     public boolean needsParameters()
31     {
32         return true;
33     }
34
35     public boolean needsParameter(String JavaDoc name)
36     {
37         return (this.name.equals(name));
38     }
39
40     public static Object JavaDoc lookup(String JavaDoc name, Context context) throws OperationException
41     {
42         try {
43             return context.getObject(name);
44         } catch (Exception JavaDoc e2){
45             throw new OperationException("Failed to find object '" + name + "'.",e2);
46         }
47     }
48
49     public Object JavaDoc execute(Context context) throws OperationException
50     {
51         Object JavaDoc 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 JavaDoc toString()
61     {
62         return getName();
63     }
64 }
65
Popular Tags