KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > exe > ExecutionContext


1 package org.jbpm.graph.exe;
2
3 import org.jbpm.context.exe.ContextInstance;
4 import org.jbpm.graph.def.Action;
5 import org.jbpm.graph.def.Event;
6 import org.jbpm.graph.def.GraphElement;
7 import org.jbpm.graph.def.Node;
8 import org.jbpm.graph.def.ProcessDefinition;
9 import org.jbpm.graph.def.Transition;
10 import org.jbpm.module.def.ModuleDefinition;
11 import org.jbpm.module.exe.ModuleInstance;
12 import org.jbpm.scheduler.exe.SchedulerInstance;
13 import org.jbpm.taskmgmt.def.Task;
14 import org.jbpm.taskmgmt.exe.TaskInstance;
15 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
16
17 public class ExecutionContext {
18
19   protected Token token = null;
20   protected Event event = null;
21   protected GraphElement eventSource = null;
22   protected Action action = null;
23   protected Throwable JavaDoc exception = null;
24   protected Transition transition = null;
25   protected Node transitionSource = null;
26   protected Task task = null;
27   protected TaskInstance taskInstance = null;
28
29   public ExecutionContext( Token token ) {
30     this.token = token;
31   }
32
33   public ExecutionContext(ExecutionContext other) {
34     this.token = other.token;
35     this.event = other.event;
36     this.action = other.action;
37   }
38
39   public Node getNode() {
40     return token.getNode();
41   }
42
43   public ProcessDefinition getProcessDefinition() {
44     ProcessInstance processInstance = getProcessInstance();
45     return ( processInstance!=null ? processInstance.getProcessDefinition() : null );
46   }
47
48   public void setAction(Action action) {
49     this.action = action;
50     if (action!=null) {
51       this.event = action.getEvent();
52     }
53   }
54   
55   public ProcessInstance getProcessInstance() {
56     return token.getProcessInstance();
57   }
58   
59   public String JavaDoc toString() {
60     return "ExecutionContext["+ token + "]";
61   }
62
63   // convenience methods //////////////////////////////////////////////////////
64

65   /**
66    * set a process variable.
67    */

68   public void setVariable(String JavaDoc name, Object JavaDoc value) {
69     getContextInstance().setVariable(name, value, token);
70   }
71   
72   /**
73    * get a process variable.
74    */

75   public Object JavaDoc getVariable(String JavaDoc name) {
76     return getContextInstance().getVariable(name, token);
77   }
78   
79   /**
80    * leave this node over the default transition. This method is only available
81    * on node actions. Not on actions that are executed on events. Actions on
82    * events cannot change the flow of execution.
83    */

84   public void leaveNode() {
85     getNode().leave(this);
86   }
87   /**
88    * leave this node over the given transition. This method is only available
89    * on node actions. Not on actions that are executed on events. Actions on
90    * events cannot change the flow of execution.
91    */

92   public void leaveNode(String JavaDoc transitionName) {
93     getNode().leave(this, transitionName);
94   }
95   /**
96    * leave this node over the given transition. This method is only available
97    * on node actions. Not on actions that are executed on events. Actions on
98    * events cannot change the flow of execution.
99    */

100   public void leaveNode(Transition transition) {
101     getNode().leave(this, transition);
102   }
103   
104   public ModuleDefinition getDefinition(Class JavaDoc clazz) {
105     return getProcessDefinition().getDefinition(clazz);
106   }
107
108   public ModuleInstance getInstance(Class JavaDoc clazz) {
109     ProcessInstance processInstance = (token!=null ? token.getProcessInstance() : null);
110     return (processInstance!=null ? processInstance.getInstance(clazz): null);
111   }
112   
113   public ContextInstance getContextInstance() {
114     return (ContextInstance) getInstance(ContextInstance.class);
115   }
116
117   public TaskMgmtInstance getTaskMgmtInstance() {
118     return (TaskMgmtInstance) getInstance(TaskMgmtInstance.class);
119   }
120
121   public SchedulerInstance getSchedulerInstance() {
122     return (SchedulerInstance) getInstance(SchedulerInstance.class);
123   }
124
125   // getters and setters //////////////////////////////////////////////////////
126

127   public Token getToken() {
128     return token;
129   }
130   public Action getAction() {
131     return action;
132   }
133   public Event getEvent() {
134     return event;
135   }
136   public void setEvent(Event event) {
137     this.event = event;
138   }
139   public Throwable JavaDoc getException() {
140     return exception;
141   }
142   public void setException(Throwable JavaDoc exception) {
143     this.exception = exception;
144   }
145   public Transition getTransition() {
146     return transition;
147   }
148   public void setTransition(Transition transition) {
149     this.transition = transition;
150   }
151   public Node getTransitionSource() {
152     return transitionSource;
153   }
154   public void setTransitionSource(Node transitionSource) {
155     this.transitionSource = transitionSource;
156   }
157   public GraphElement getEventSource() {
158     return eventSource;
159   }
160   public void setEventSource(GraphElement eventSource) {
161     this.eventSource = eventSource;
162   }
163   public Task getTask() {
164     return task;
165   }
166   public void setTask(Task task) {
167     this.task = task;
168   }
169   public TaskInstance getTaskInstance() {
170     return taskInstance;
171   }
172   public void setTaskInstance(TaskInstance taskInstance) {
173     this.taskInstance = taskInstance;
174   }
175 }
176
Popular Tags