1. <?xml version="1.0" encoding="UTF-8"?> 
  2.  
  3. <process-definition 
  4.   xmlns="urn:jbpm.org:jpdl-3.2"  name="testcountersign"> 
  5.    <start-state name="start"> 
  6.       <transition to="会签任务节点"></transition> 
  7.    </start-state> 
  8.    <task-node name="会签任务节点"> 
  9.       <task name="会签任务"> </task> 
  10.        
  11.         <event type="node-enter"> 
  12.            <action class="com.bf.CountersignAction"></action> 
  13.         </event> 
  14.       
  15.       <transition name="" to="end1"></transition> 
  16.    </task-node> 
  17.    <end-state name="end1"></end-state> 
  18. </process-definition> 
  19.  
  20. package com.bf; 
  21.  
  22. import java.util.List; 
  23.  
  24. import org.jbpm.graph.def.ActionHandler; 
  25. import org.jbpm.graph.exe.ExecutionContext; 
  26. import org.jbpm.graph.exe.Token; 
  27. import org.jbpm.graph.node.TaskNode; 
  28. import org.jbpm.taskmgmt.def.Task; 
  29. import org.jbpm.taskmgmt.exe.TaskInstance; 
  30. import org.jbpm.taskmgmt.exe.TaskMgmtInstance; 
  31.  
  32.  
  33. //设置参与者 
  34. public class CountersignAction implements ActionHandler { 
  35.     public void execute(ExecutionContext executeContext) throws Exception { 
  36.         System.out.println("aaaaa"); 
  37.         Token token =  executeContext.getToken(); 
  38.         TaskMgmtInstance tmi = executeContext.getTaskMgmtInstance(); 
  39.         TaskNode taskNode = (TaskNode)executeContext.getNode(); 
  40.         Task task = taskNode.getTask("会签任务"); 
  41.         //从流程上下文里获取会签人列表 
  42.         List<String> ls = (List<String>)executeContext.getVariable("actorList"); 
  43.         for(String actorId : ls) { 
  44.             TaskInstance ti = tmi.createTaskInstance(task, token);   
  45.             ti.setActorId(actorId); 
  46.         } 
  47.     } 
  48.  
  49. <?xml version="1.0" encoding="UTF-8"?> 
  50.  
  51. <process-definition 
  52.   xmlns="urn:jbpm.org:jpdl-3.2"  name="ordercountersign"> 
  53.    <start-state name="start"> 
  54.       <transition name="" to="传阅节点"></transition> 
  55.    </start-state> 
  56.    <task-node name="传阅节点" signal="never"> 
  57.  
  58.       <task name="传阅任务"> 
  59.  
  60.         <assignment class="com.bf.OrderCountersignAssignment"></assignment> 
  61.  
  62.       </task> 
  63.       <transition name="" to="end1"></transition> 
  64.    </task-node> 
  65.    <end-state name="end1"></end-state> 
  66. </process-definition> 
  67.  
  68.  
  69.  
  70. package com.test; 
  71.  
  72. import java.util.ArrayList; 
  73. import java.util.LinkedList; 
  74. import java.util.List; 
  75. import java.util.Map; 
  76.  
  77. import javax.transaction.Transaction; 
  78.  
  79. import org.apache.commons.collections.map.HashedMap; 
  80. import org.jbpm.JbpmConfiguration; 
  81. import org.jbpm.JbpmContext; 
  82. import org.jbpm.context.exe.ContextInstance; 
  83. import org.jbpm.db.GraphSession; 
  84. import org.jbpm.graph.def.ProcessDefinition; 
  85. import org.jbpm.graph.def.Transition; 
  86. import org.jbpm.graph.exe.ProcessInstance; 
  87. import org.jbpm.graph.exe.Token; 
  88. import org.jbpm.taskmgmt.exe.TaskInstance; 
  89.  
  90. public class Test01 { 
  91.  
  92.     public static void main(String[] args)throws Exception  { 
  93.         //newProcessInstance(); 
  94.         endTask("李四"); 
  95.     } 
  96.  
  97.     // 创建流程实例 
  98.     public static void newProcessInstance() throws Exception { 
  99.         JbpmConfiguration config = JbpmConfiguration.getInstance(); 
  100.         JbpmContext context = config.createJbpmContext(); 
  101.         GraphSession gs = context.getGraphSession(); 
  102.         ProcessDefinition pd = gs 
  103.                 .findLatestProcessDefinition("ordercountersign"); 
  104.         ProcessInstance pi = new ProcessInstance(pd); 
  105.         // 创建放传阅人信息列表 
  106.         List ls = new LinkedList(); 
  107.         Map map1 = new HashedMap(); 
  108.         // 传阅人ID 
  109.         map1.put("actorId", "张三"); 
  110.         // 是否创建了任务实例 
  111.         map1.put("taskCreate", "0"); 
  112.         ls.add(map1); 
  113.  
  114.         Map map2 = new HashedMap(); 
  115.         // 传阅人ID 
  116.         map2.put("actorId", "李四"); 
  117.         // 是否创建了任务实例 
  118.         map2.put("taskCreate", "0"); 
  119.         ls.add(map2); 
  120.  
  121.         Map map3 = new HashedMap(); 
  122.         // 传阅人ID 
  123.         map3.put("actorId", "王五"); 
  124.         // 是否创建了任务实例 
  125.         map3.put("taskCreate", "0"); 
  126.         ls.add(map3); 
  127.  
  128.         pi.getContextInstance().setVariable("list", ls); 
  129.         Token token = pi.getRootToken(); 
  130.         token.signal(); 
  131.         context.close(); 
  132.     } 
  133.  
  134.     // 结束工作 
  135.     public static void endTask(String actorId) throws Exception { 
  136.         JbpmConfiguration config = JbpmConfiguration.getInstance(); 
  137.         JbpmContext context = config.createJbpmContext(); 
  138.         TaskInstance ti = (TaskInstance) context.getTaskList(actorId).get(0); 
  139.         ti.end(); 
  140.         // 从流程上下文中获取传阅人 
  141.         List ls = (List) ti.getContextInstance().getVariable("list"); 
  142.         for (int i = 0; i < ls.size(); i++) { 
  143.             Map map = (Map) ls.get(i); 
  144.             // 修改当前传阅人额度创建标识为1 
  145.             if (map.get("actorId").toString().equals(actorId)) { 
  146.                 map.put("taskCreate", "1"); 
  147.                 break; 
  148.          
  149.             } 
  150.         } 
  151.         //创建下一个传阅人的任务实例 
  152.         boolean flag = true
  153.          
  154.         for(int i=0;i<ls.size();i++) { 
  155.             Map map = (Map)ls.get(i); 
  156.             String taskCreate = map.get("taskCreate").toString(); 
  157.             if(taskCreate.equals("0")) { 
  158.                 String actor = map.get("actorId").toString(); 
  159.                 TaskInstance newTaskInstance = ti.getTaskMgmtInstance().createTaskInstance(ti.getTask(),ti.getToken()); 
  160.                 newTaskInstance.setActorId(actor); 
  161.                 flag = false
  162.                 break; 
  163.             } 
  164.         } 
  165.         ti.getContextInstance().setVariable("list", ls); 
  166.         //如果没有任务实例,表示传阅完成 进入下一个节点。 
  167.         if(flag) { 
  168.             ti.getToken().signal(); 
  169.         } 
  170.         context.close(); 
  171.     } 
  172.      
  173.