01: package org.jbpm.command;
02:
03: import java.util.Map;
04:
05: import org.jbpm.JbpmContext;
06: import org.jbpm.context.exe.VariableContainer;
07: import org.jbpm.graph.exe.ProcessInstance;
08: import org.jbpm.graph.exe.Token;
09: import org.jbpm.taskmgmt.exe.TaskInstance;
10:
11: public class VariablesCommand implements Command {
12:
13: private static final long serialVersionUID = 1L;
14:
15: long tokenId = 0;
16: long taskInstanceId = 0;
17: Map variables = null;
18:
19: ProcessInstance previousProcessInstance = null;
20: Token previousToken = null;
21: TaskInstance previousTaskInstance = null;
22:
23: public Object execute(JbpmContext jbpmContext) throws Exception {
24: VariableContainer variableContainer = getVariableContainer(jbpmContext);
25: if ((variableContainer != null) && (variables != null)) {
26: variableContainer.addVariables(variables);
27: }
28: return variableContainer;
29: }
30:
31: protected VariableContainer getVariableContainer(
32: JbpmContext jbpmContext) {
33: if (previousProcessInstance != null) {
34: return getVariableContainer(previousProcessInstance
35: .getRootToken());
36: }
37: if (previousToken != null) {
38: return getVariableContainer(previousToken);
39: }
40: if (previousTaskInstance != null) {
41: return previousTaskInstance;
42: }
43:
44: if (tokenId != 0) {
45: return getVariableContainer(jbpmContext.getToken(tokenId));
46: }
47: if (taskInstanceId != 0) {
48: return jbpmContext.getTaskInstance(taskInstanceId);
49: }
50: return null;
51: }
52:
53: protected VariableContainer getVariableContainer(Token token) {
54: return token.getProcessInstance().getContextInstance()
55: .getTokenVariableMap(token);
56: }
57:
58: public long getTaskInstanceId() {
59: return taskInstanceId;
60: }
61:
62: public void setTaskInstanceId(long taskInstanceId) {
63: this .taskInstanceId = taskInstanceId;
64: }
65:
66: public long getTokenId() {
67: return tokenId;
68: }
69:
70: public void setTokenId(long tokenId) {
71: this .tokenId = tokenId;
72: }
73:
74: public Map getVariables() {
75: return variables;
76: }
77:
78: public void setVariables(Map variables) {
79: this.variables = variables;
80: }
81: }
|