01: package org.jicengine.operation;
02:
03: /**
04: * <p> </p>
05: *
06: * <p> </p>
07: *
08: * <p> </p>
09: *
10: * <p> </p>
11: *
12: * @author timo laitinen
13: */
14: public class NegationOperation implements Operation {
15: private Operation operation;
16:
17: public NegationOperation(Operation operation) {
18: this .operation = operation;
19: }
20:
21: /**
22: * <p> executes the operation in a given context.
23: *
24: * @param context Context
25: * @throws OperationException
26: * @return Object
27: */
28: public Object execute(Context context) throws OperationException {
29: Object result = this .operation.execute(context);
30: if (result == null) {
31: // null means true to here.
32: return Boolean.TRUE;
33: } else if (result instanceof Boolean) {
34: // negate the boolean
35: return new Boolean(!((Boolean) result).booleanValue());
36: } else {
37: // non-null, non-boolean means false
38: return Boolean.FALSE;
39: }
40:
41: }
42:
43: /**
44: * <p> So clients may query if this operation needs a particular parameter.
45: *
46: * @param name String
47: * @return boolean
48: */
49: public boolean needsParameter(String name) {
50: return this .operation.needsParameter(name);
51: }
52:
53: /**
54: * So clients may query whether this operation needs any parameters at all.
55: *
56: * @return boolean
57: */
58: public boolean needsParameters() {
59: return this.operation.needsParameters();
60: }
61: }
|