kxbin
          成功留給有準備的人
          posts - 10,  comments - 35,  trackbacks - 0
          活動標簽
          -控制流程的活動
          -原子活動
           
          控制流程的活動
          Start   開始節點,一個(主)流程只能有一個開始節點
          End     結束節點,一個流程可以有多個結束節點
          Decision 條件判斷節點,當一個流程出現多個分支(情況),而分支排他時使用。
          Fork    分支節點,當一個流程出現多個分支,而分支并列執行時使用。
          Join    聚合/聯合節點,通常與fork節點一起使用。
          Sub-process 子流程(本人未曾使用過)
          State   狀態節點    一個暫停節點,當需要對流程的執行進行控制時使用。
          Task    任務節點,通常與form表單關聯,主要是在流程實例經過活動時為某一人或
          組指派任務
           
          原子活動
          Java、Script、Sql、Hql、Email
           
           
          下面介紹三個最常用的活動
          state
          一個強制流程暫停的節點,當需要對流程的執行進行控制時使用。該節點可能什么都
          不需要做,也可能執行一些的操作。比如,路過銀行,你拍怕褲兜,看看錢夠還是不
          夠。如果錢還可以花一段時間,你就不會去取錢。如果錢不多了,你就會去銀行取些
          現金?;蚴清X本來就夠花,但外面在下著雨,你想取避一避雨也不是不可以。State
          要做的相當于帶你路過銀行,至于你取不取錢,取多少,還是為了別的什么,不是它
          說了算,而是你自己的決定。
           
          第一種方式:無分支的State
          Xml代碼  
          <?xml version="1.0" encoding="UTF-8"?>  
            
          <process name="simpleState" xmlns="http://jbpm.org/4.3/jpdl">  
             <start name="start1" g="368,117,48,48">  
                <transition name="to state" to="state" g="-59,-17"/>  
             </start>  
             <end name="end" g="372,396,48,48"/>  
             <state name="state" g="348,250,92,52">  
                <transition name="to end" to="end" g="-47,-17"/>  
             </state>  
          </process>  
           
          測試代碼如下:
          Java代碼  
          ProcessInstance processInstance =   
                      executionService.startProcessInstanceByKey("simpleState");  
                  System.out.println("流程實例Id:"+  
                          processInstance.getId());  
                  System.out.println("流程定義Id:"+  
                          processInstance.getProcessDefinitionId());            
                  System.out.println("是否在 state節點:"+  
                          processInstance.isActive("state"));//true  
                  System.out.println("判斷流程是否結束:"+  
                          processInstance.isEnded());//false  
                    
                  processInstance =   
                      executionService.signalExecutionById(processInstance.getId()); 
           
                  System.out.println("是否在 state節點:"+  
                          processInstance.isActive("state"));//true  
                  System.out.println("判斷流程是否結束:"+  
                          processInstance.isEnded());//false  
           
          執行結果如下:
          Consult代碼  
          流程實例Id:simpleState.7  
          流程定義Id:simpleState-1  
          是否在 state節點:true  
          判斷流程是否結束:false  
          **************  
          是否在 state節點:false  
          判斷流程是否結束:true  
           
          第二種方式:有分支的state
          Xml代碼  
          <?xml version="1.0" encoding="UTF-8"?>  
            
          <process name="compState" xmlns="http://jbpm.org/4.3/jpdl">  
             <start name="start1" g="300,106,48,48">  
                <transition name="to proot" to="proot" g="-59,-17"/>  
             </start>  
             <end name="end" g="315,448,48,48"/>  
             <state name="proot" g="281,223,92,52">  
                <transition name="to boy" to="boy" g="-59,-17"/>  
                <transition name="to girl" to="girl" g="-59,-17"/>  
             </state>  
             <state name="boy" g="187,346,92,52">  
                <transition name="to end" to="end" g="-47,-17"/>  
             </state>  
             <state name="girl" g="383,342,92,52">  
                <transition name="to end" to="end" g="-47,-17"/>  
             </state>  
          </process>  
           
          測試代碼如下:
          Java代碼  
          ProcessInstance processInstance =   
                      executionService.startProcessInstanceByKey("compState");  
                    
                  System.out.println("是否在 proot節點:"+  
                          processInstance.isActive("proot"));//true  
                  System.out.println("是否在 boy節點:"+  
                          processInstance.isActive("boy"));//false  
                    
                  System.out.println("是否在 girl節點:"+  
                          processInstance.isActive("girl"));//false  
                    
                  System.out.println("判斷流程是否結束:"+  
                          processInstance.isEnded());//false  
                    
                  processInstance =   
                      executionService.signalExecutionById(processInstance.getId
          (),"to boy");//因為proot往下有多個分支,如果不指定流程轉向,流程不會繼續往
          下執行  
                  System.out.println("是否在 proot節點:"+  
                          processInstance.isActive("proot"));//false  
                  System.out.println("是否在 boy節點:"+  
                          processInstance.isActive("boy"));//true  
                  System.out.println("是否在 girl節點:"+  
                          processInstance.isActive("girl"));//false  
                  System.out.println("判斷流程是否結束:"+  
                          processInstance.isEnded());//false    
           
          executionService.signalExecutionById(processInstance.getId(),"to boy");
          這句如果改為:
          executionService.signalExecutionById(processInstance.getId());
          則流程不會往下執行,流程繼續停留在proot節點。
           
          decision  
          條件判斷節點,當一個流程出現多個中情況而各種情況都排他時使用,相當于switch 
          case.
          第一種方式:decision內置condition
           
          Xml代碼  
          <?xml version="1.0" encoding="UTF-8"?>  
          <process key="deci" name="deci" xmlns="http://jbpm.org/4.3/jpdl">  
             <start g="358,77,48,48" name="start1">  
                <transition g="-83,-17" name="to exclusive1" to="exclusive1"/>  
             </start>  
             <end g="374,510,48,48" name="end"/>  
             <decision g="358,219,48,48" name="exclusive1">  
                <transition g="-59,-17" name="to 200" to="200">  
                  <condition expr="#{errorcode == 200}"/>  
                </transition>  
                <transition g="-59,-17" name="to 404" to="404">  
                  <condition expr="#{errorcode == 404}"/>  
                </transition>  
                <transition g="-59,-17" name="to 500" to="500">        
                  <condition expr="#{errorcode == 500}"/>  
                </transition>  
             </decision>  
             <state g="194,351,92,52" name="200">  
                <transition g="-47,-17" name="to end" to="end"/>  
             </state>  
             <state g="340,349,92,52" name="404">  
                <transition g="-47,-17" name="to end" to="end"/>  
             </state>  
             <state g="476,349,92,52" name="500">  
                <transition g="-47,-17" name="to end" to="end"/>  
             </state>  
          </process>  
           
           
          測試代碼如下:
          Java代碼  
          Map<String, String> variables = new HashMap<String, String>();  
                  variables.put("errorcode", "200");  
                  ProcessInstance processInstance =   
                      executionService.startProcessInstanceByKey("deci", variables); 
           
                    
                  System.out.println("200 isActive:"+  
                          processInstance.isActive("200"));//進入state 200,暫停  
                  System.out.println("processInstance isEnd:"+  
                          processInstance.isEnded()); //流程未結束,返回false  
                  System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
                    
                  //該方法返回processInstance如果不接收,processInstance還是原來的對
          象  
                  //如果不接收返回值,也不重新查詢,則processInstance還是方法調前的
          狀態  
                  processInstance=  
                      executionService.signalExecutionById(processInstance.getId()); 
           
                    
                  System.out.println("processInstance isEnd:"+  
                          processInstance.isEnded()); //流程結束,返回true  
                  System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
           
          控制臺輸出結果如下:
          Consult代碼  
          200 isActive:true  
          processInstance isEnd:false  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
          ********  
          processInstance isEnd:true  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
           
          第二種方式:為decision活動設置expr
          Xml代碼  
          <?xml version="1.0" encoding="UTF-8"?>  
          <process name="deciBaseExpr" xmlns="http://jbpm.org/4.3/jpdl">  
             <start name="start1" g="407,65,48,48">  
                <transition name="to exclusive1" to="exclusive1" g="-83,-17"/>  
             </start>  
             <end name="end1" g="418,497,48,48"/>  
             <decision name="exclusive1" g="409,207,48,48" expr="#{whatcode}">  
                <transition name="to 200" to="200" g="-59,-17"/>  
                <transition name="to 404" to="404" g="-59,-17"/>  
                <transition name="to 500" to="500" g="-59,-17"/>  
             </decision>  
             <state name="200" g="251,344,92,52">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </state>  
             <state name="404" g="389,342,92,52">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </state>  
             <state name="500" g="516,341,92,52">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </state>  
          </process>  
           
          測試代碼如下:
          Java代碼  
          Map<String, String> variables = new HashMap<String, String>();  
                  variables.put("whatcode", "to 404");  
                  ProcessInstance processInstance =   
                      executionService.startProcessInstanceByKey("deciBaseExpr", 
          variables);  
                    
                  System.out.println("200 isActive:"+  
                          processInstance.isActive("200"));//返回false  
                  System.out.println("404 isActive:"+  
                          processInstance.isActive("404"));//返回true  
                  System.out.println("500 isActive:"+  
                          processInstance.isActive("500"));//返回false  
                  System.out.println("processInstance isEnd:"+  
                          processInstance.isEnded()); //流程未結束,返回false  
                  System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
                    
                  //該方法返回processInstance如果不接收,processInstance還是原來的對
          象  
                  //如果不接收返回值,也不重新查詢,則processInstance還是方法調前的
          狀態  
                  processInstance=  
                      executionService.signalExecutionById(processInstance.getId()); 
           
                    
                  System.out.println("processInstance isEnd:"+  
                          processInstance.isEnded()); //流程結束,返回true  
                  System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
           
          控制臺輸出結果如下:
          Consult代碼  
          200 isActive:false  
          404 isActive:true  
          500 isActive:false  
          processInstance isEnd:false  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
          ***************  
          processInstance isEnd:true  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
           
          第三種方式:為decision配置handler
          Xml代碼  
          <?xml version="1.0" encoding="UTF-8"?>  
          <process name="deciByHandler" key="deciByHandler" 
          xmlns="http://jbpm.org/4.3/jpdl">  
             <start name="start1" g="341,55,48,48">  
                <transition name="to exclusive1" to="exclusive1" g="-83,-17"/>  
             </start>  
             <end name="end1" g="346,435,48,48"/>  
             <decision name="exclusive1" g="340,164,48,48">  
                <handler class="com.lihua.HandlerDecision"></handler>  
                <transition name="to 200" to="200" g="-59,-17"/>  
                <transition name="to 404" to="404" g="-59,-17"/>  
                <transition name="to 500" to="500" g="-59,-17"/>  
             </decision>  
             <state name="200" g="178,315,92,52">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </state>  
             <state name="404" g="322,309,92,52">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </state>  
             <state name="500" g="461,309,92,52">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </state>  
          </process>  
           
          Handler類:
           
          Java代碼  
          package com.lihua;  
            
          import org.jbpm.api.jpdl.DecisionHandler;  
          import org.jbpm.api.model.OpenExecution;  
            
          public class HandlerDecision implements DecisionHandler {  
            
              private static final long serialVersionUID = -1639139174140348966L;  
            
              @Override  
              public String decide(OpenExecution execution) {  
                  return (String) execution.getVariable("towhere");      
              }  
            
          }  
           
          測試代碼如下:
          Java代碼  
          Map<String, String> variables =   
                      new HashMap<String, String>();  
                  variables.put("towhere", "to 500");  
                  ProcessInstance processInstance =   
                      executionService.  
                      startProcessInstanceByKey("deciByHandler", variables);  
                    
                  System.out.println("200 isActive:"+  
                          processInstance.isActive("200"));//返回 false  
                  System.out.println("404 isActive:"+  
                          processInstance.isActive("404"));//返回 false  
                  System.out.println("500 isActive:"+  
                          processInstance.isActive("500"));//返回 true  
                  System.out.println("processInstance isEnd:"+  
                          processInstance.isEnded()); //流程未結束,返回false  
                  System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
                    
                  //該方法返回processInstance如果不接收,processInstance還是原來的對
          象  
                  //如果不接收返回值,也不重新查詢,則processInstance還是方法調前的
          狀態  
                  processInstance=  
                      executionService.signalExecutionById(processInstance.getId()); 
           
                    
                  System.out.println("processInstance isEnd:"+  
                          processInstance.isEnded()); //流程結束,返回true  
                  System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
           
          控制臺輸出結果如下:
          Consult代碼  
          200 isActive:false  
          404 isActive:false  
          500 isActive:true  
          processInstance isEnd:false  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
          ************  
          processInstance isEnd:true  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
           
          以上三種方式差別都不是很大,第三中在程序中通過Handler進行復雜的處理。個人
          覺得,如果對于邏輯不是很復雜的操作,前兩種方式是比較可取的。但如果邏輯過于
          復雜,或者還有其他的操作比如同步數據庫中的其他信息等操作時,不妨選擇第三種
          方式。
          這些代碼代碼比較簡單,這里就不做過多的解釋。
           
          Task
          任務節點,通常與form表單關聯,主要是在流程實例經過活動時為某一人或組指派任
          務.
          Task的assignee屬性
           
          第一, assignee用來指示用戶,負責完成任務的人。分配人是一個任務中的字符串
          屬性,引用一個用戶。(直接指定一個字符串)
          第二,這個屬性默認會當做表達式來執行。(指定一個表達式,然后在代碼里為該表達
          式賦值) 如:在這里任務被分配給#{order.owner}。這意味著首先使用order這個名字
          查找一個對象。 其中一個查找對象的地方是這個任務對應的流程變量。 然后
          getOwner()方法會用來獲得用戶id, 引用的用戶負責完成這個任務。
           
          Xml代碼  
          <?xml version="1.0" encoding="UTF-8"?>  
            
          <process name="task" xmlns="http://jbpm.org/4.3/jpdl">  
             <start name="start1" g="390,97,48,48">  
                <transition name="to task" to="task" g="-53,-17"/>  
             </start>  
             <end name="end1" g="391,362,48,48"/>  
             <task name="task" g="368,239,92,52" assignee="${taskAssignee}">  
                <transition name="to end1" to="end1" g="-47,-17"/>  
             </task>  
          </process>  
           
           
          測試代碼如下:
          Java代碼  
          Map<String,String> map=  
                      new HashMap<String, String>();  
                  map.put("taskAssignee", "lihua");  
                  ProcessInstance processInstance=null;  
                  for (int i = 0; i < 2; i++) {  
                      processInstance=executionService.  
                      startProcessInstanceByKey("task",map);            
                      System.out.println("流程是否處于task節點:"+  
                              processInstance.isActive("task"));//true  
                      System.out.println("流程實例Id:"+  
                              processInstance.getId());  
                  }  
                  List<Task> list=taskService.findPersonalTasks("lihua");  
                  for (Task task : list) {  
                      System.out.println("任務活動名稱:"+  
                              task.getActivityName());  
                      System.out.println("流程實例Id:"+  
                              task.getExecutionId());  
                      System.out.println("任務活動Id:"+  
                              task.getId());  
                      System.out.println("任務活動創建時間:"+  
                              task.getCreateTime());  
                      System.out.println("任務活動進度:"+  
                              task.getProgress());  
                      System.out.println("任務活動分配給:"+  
                              task.getAssignee());  
                      System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
                  }  
           
          控制臺輸出結果如下:
          Consult代碼  
          流程是否處于task節點:true  
          流程實例Id:task.7  
          ************  
          流程是否處于task節點:true  
          流程實例Id:task.11  
          *****************  
          任務活動名稱:task  
          流程實例Id:task.11  
          任務活動Id:13  
          任務活動創建時間:2012-02-16 15:48:50.406  
          任務活動進度:null  
          任務活動分配給:lihua  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
          任務活動名稱:task  
          流程實例Id:task.7  
          任務活動Id:9  
          任務活動創建時間:2012-02-16 15:48:50.375  
          任務活動進度:null  
          任務活動分配給:lihua  
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
           
           
          Tips代碼  
          1、在流程設置時如果出現亂碼可在Eclipse.ini中添加如下配置:  
          -Dfile.encoding=UTF-8  
          2、在jbpm中表達式$(),#()均可以成功解析。  
          posted on 2012-05-18 00:09 kxbin 閱讀(1077) 評論(0)  編輯  收藏 所屬分類: 流程引擎
          你恨一個人是因為你愛他;你喜歡一個人,是因為他身上有你沒有的;你討厭一個人是因為他身上有你有的東西;你經常在別人面前批評某人,其實潛意識中是想接近他。

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(5)

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          J2EE

          java技術網站

          Linux

          平時常去的網站

          數據庫

          電影網站

          網站設計

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 安多县| 肥东县| 黄梅县| 留坝县| 望城县| 根河市| 柳江县| 绿春县| 嘉兴市| 津市市| 永靖县| 西青区| 马公市| 皮山县| 台北市| 通渭县| 盐亭县| 进贤县| 阳谷县| 凤阳县| 西城区| 泸水县| 广德县| 车险| 黄冈市| 奈曼旗| 恩平市| 滦南县| 陇川县| 高淳县| 从化市| 南木林县| 金溪县| 英德市| 博乐市| 和平区| 宁夏| 鄂州市| 恩施市| 唐河县| 漯河市|