01: package org.jicengine.operation;
02:
03: /**
04: *
05: * <p>
06: * Copyright (C) 2004 Timo Laitinen
07: * </p>
08: * @author Timo Laitinen
09: * @created 2004-09-20
10: * @since JICE-0.10
11: *
12: */
13:
14: public class PushVariableOperation implements Operation {
15:
16: String localContextName;
17: String parentContextName;
18:
19: public PushVariableOperation(String localContextName,
20: String parentContextName) {
21: this .parentContextName = parentContextName;
22: this .localContextName = localContextName;
23: }
24:
25: public boolean needsParameters() {
26: return true;
27: }
28:
29: public boolean needsParameter(String name) {
30: return (this .localContextName.equals(name));
31: }
32:
33: public Object execute(Context context) throws OperationException {
34: Context parentContext;
35: try {
36: parentContext = ((LocalContext) context).getParent();
37: } catch (ClassCastException e) {
38: throw new RuntimeException("Expected "
39: + LocalContext.class.getName() + ", was "
40: + context.getClass().getName());
41: }
42:
43: try {
44: Object value = context.getObject(this .localContextName);
45:
46: parentContext.addObject(this .parentContextName, value);
47: return null;
48: } catch (ObjectNotFoundException e) {
49: throw new OperationException(e.getMessage(), e);
50: } catch (DuplicateNameException e2) {
51: throw new OperationException(e2.getMessage(), e2);
52: }
53: }
54: }
|