01: package org.jicengine.operation;
02:
03: /**
04: *
05: * <p>
06: * Copyright (C) 2004 Timo Laitinen
07: * </p>
08: *
09: * @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 name;
18:
19: public VariableValueOperation(String objectName) {
20: // todo: check that the name is valid?
21: this .name = objectName;
22: }
23:
24: public String getName() {
25: return this .name;
26: }
27:
28: public boolean needsParameters() {
29: return true;
30: }
31:
32: public boolean needsParameter(String name) {
33: return (this .name.equals(name));
34: }
35:
36: public static Object lookup(String name, Context context)
37: throws OperationException {
38: try {
39: return context.getObject(name);
40: } catch (Exception e2) {
41: throw new OperationException("Failed to find object '"
42: + name + "'.", e2);
43: }
44: }
45:
46: public Object execute(Context context) throws OperationException {
47: Object value = lookup(getName(), context);
48: if (value != null) {
49: return value;
50: } else {
51: throw new OperationException("Object named '" + getName()
52: + "' not found in context " + context);
53: }
54: }
55:
56: public String toString() {
57: return getName();
58: }
59: }
|