Posted on 2005-12-16 16:55
虾米老 阅读(577)
评论(0) 编辑 收藏 所属分类:
flow学习
(二)Decision
package kellerdu.jbpm.delegation;
import org.jbpm.delegation.*;
import kellerdu.jbpm.LogsFactory;
import org.apache.commons.logging.Log;
import kellerdu.jbpm.Constants;
public class ChiefDecision implements DecisionHandler {
public ChiefDecision() {
}
/**
* 判断是否需要主管批准,决定下一个要进行的transition
*
* @param executionContext ExecutionContext
* @return String
* @todo Implement this org.jbpm.delegation.DecisionHandler method
*/
public String decide(ExecutionContext executionContext) {
Log log=LogsFactory.getLogInstance(this.getClass());
String ac=(String)executionContext.getVariable(Constants.USER_NAME);
if(ac!=null&&(ac.equals("dali")||ac.equals("wang"))){
log.info(ac+"需要老板批准!");
return "BossApprove";
}else{
log.info(ac+"需要先经主管批准");
return "ChiefApprove";
}
}
}
=======================
(三)fork
package kellerdu.jbpm.delegation;
import org.jbpm.*;
import org.jbpm.delegation.*;
import org.jbpm.model.execution.*;
import java.util.*;
public class DecidedJoin implements JoinHandler {
public DecidedJoin() {
}
/**
* fork,只要一个分支到达,即可进行下一步操作,同时取消其它同时进行的分支。
* 这里就是用户如果取消,请假就取消。如果用户请假批准,则用户不能取消。
*
* @param forkContext ForkContext
* @throws ExecutionException
* @todo Implement this org.jbpm.delegation.ForkHandler method
*/
public void join(JoinContext joinContext) throws ExecutionException {
Iterator it=joinContext.getConcurrentTokens().values().iterator();
Token arrivingToken = joinContext.getToken();
while(it.hasNext()){
Token to=(Token)it.next();
if(to.getId().equals(arrivingToken.getId())){
//取消其它执行的Token
joinContext.getExecutionService().cancelToken(to.getId());
}
}
// reactivate the parent token.
joinContext.reactivateToken( arrivingToken.getParent() );
}
}