KickJava   Java API By Example, From Geeks To Geeks.

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


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

13
14 public class PushVariableOperation implements Operation {
15
16     String JavaDoc localContextName;
17     String JavaDoc parentContextName;
18
19     public PushVariableOperation(String JavaDoc localContextName, String JavaDoc parentContextName)
20     {
21         this.parentContextName = parentContextName;
22         this.localContextName = localContextName;
23     }
24
25     public boolean needsParameters()
26     {
27         return true;
28     }
29
30     public boolean needsParameter(String JavaDoc name)
31     {
32         return (this.localContextName.equals(name));
33     }
34
35     public Object JavaDoc execute(Context context) throws OperationException
36     {
37         Context parentContext;
38         try {
39             parentContext = ((LocalContext)context).getParent();
40         } catch (ClassCastException JavaDoc e){
41             throw new RuntimeException JavaDoc("Expected " + LocalContext.class.getName() + ", was " + context.getClass().getName());
42         }
43
44         try {
45             Object JavaDoc value = context.getObject(this.localContextName);
46
47             parentContext.addObject(this.parentContextName, value);
48             return null;
49         } catch (ObjectNotFoundException e){
50             throw new OperationException(e.getMessage(), e);
51         } catch (DuplicateNameException e2){
52             throw new OperationException(e2.getMessage(), e2);
53         }
54     }
55 }
56
Popular Tags