JBPM知识点------node

node节点类型适用于当你想要在节点中编写自己的代码的情形。通过设置action来帮定我们自己的商业逻辑。

<start-state name="start">
      <transition name="tr1" to="node1"></transition>
   </start-state>
   <node name="node1">
      <action class="com.jeffentest.JeffenActionHandler">
  <msg>HELLO</msg>
   </action>
      <transition name="tr2" to="end1"></transition>
   </node>
   <end-state name="end1"></end-state>

------------------------------------

 package com.jeffentest;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

public class JeffenActionHandler implements ActionHandler {
  private static final long serialVersionUID = 1L;
  private String msg;
  public void execute(ExecutionContext executionContext) {
   System.out.println(msg+"jeffen");
   //可以指定流程的运行
   //executionContext.leaveNode(transitionName);
    }
 }

----------------------------------------

private static void run(){
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
  try {
   long processInstanceId =1;
   processInstance = jbpmContext.loadProcessInstance(processInstanceId);
   Token token = processInstance.getRootToken();
   System.out.println(token.getNode());
   token.signal();
   System.out.println(token.getNode());
   token.signal();
   System.out.println(token.getNode());
   jbpmContext.save(processInstance);
   }finally {
     jbpmContext.close();
   }
 } 

---------------------------------------

StartState(start)
HELLOjeffen
Node(node1)
EndState(end1)

自动节点实现:

在上面的node的介绍中,我们可以看到action和node的合作,这里做一点扩展,看下面的代码就很容易明白。

public class AmountUpdate implements ActionHandler {
 public void execute(ExecutionContext ctx) throws Exception {
    //从数据库中得到相应的信息,进行一定的商务计算,根据不同的值选择不同的变迁,流程自动运行下去
    if (result > 5000) {
      ctx.leaveNode(ctx, "big amounts");
    } else {
      ctx.leaveNode(ctx, "small amounts");
    }
 }
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值