使用jBpm支持高级用户交互模式
2010-01-21 00:00:00 来源:WEB开发网清单14 分配处理器示例
这里我们尝试得到一个包含了给定任务上报次数的流程变量。如果变量未定义,则就分配“admin”为任务拥有者,否则任务就被分配给“bob”。在这个处理器中可以使用任何其他的分配策略。
任务实例创建动作处理器(清单15),它保存流程实例上下文的任务实例id
package com.sample.action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.Node;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class TaskCreationActionHandler implements ActionHandler {
private static final long serialVersionUID = 1L;
@Override
public void execute(ExecutionContext context) throws Exception {
Node task = context.getToken().getNode();
TaskInstance current = context.getTaskInstance();
if((task == null) || (current == null))
return;
String tName = task.getName();
String iName = tName + "instance";
context.setVariable(iName, new Long(current.getId()));
}
}
清单15 任务实例创建处理器
任务节点计时器触发调用的超时处理器(清单16)。
package com.sample.action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.GraphElement;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class EscalationActionHandler implements ActionHandler {
private static final long serialVersionUID = 1L;
private String escalation;
@Override
public void execute(ExecutionContext context) throws Exception {
GraphElement task = context.getTimer().getGraphElement();
if(task == null)
return;
String tName = task.getName();
String vName = tName + "escLevel";
long escLevel = (long)context.getVariable(vName);
if(escLevel == null)
escLevel = new long(1);
else
escLevel += 1;
context.setVariable(vName, escLevel);
String iName = tName + "instance";
long taskInstanceId = (long)context.getVariable(iName);
TaskInstance current =
context.getJbpmContext().getTaskInstance(taskInstanceId);
if(current != null){
current.end(escalation);
}
}
}
更多精彩
赞助商链接