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 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 toString() { 60 return "ExecutionContext["+ token + "]"; 61 } 62 63 65 68 public void setVariable(String name, Object value) { 69 getContextInstance().setVariable(name, value, token); 70 } 71 72 75 public Object getVariable(String name) { 76 return getContextInstance().getVariable(name, token); 77 } 78 79 84 public void leaveNode() { 85 getNode().leave(this); 86 } 87 92 public void leaveNode(String transitionName) { 93 getNode().leave(this, transitionName); 94 } 95 100 public void leaveNode(Transition transition) { 101 getNode().leave(this, transition); 102 } 103 104 public ModuleDefinition getDefinition(Class clazz) { 105 return getProcessDefinition().getDefinition(clazz); 106 } 107 108 public ModuleInstance getInstance(Class 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 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 getException() { 140 return exception; 141 } 142 public void setException(Throwable 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 |