Junky's IT Notebook

          導航

          <2006年5月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          隨筆分類(224)

          文章分類(5)

          隨筆檔案(228)

          文章檔案(7)

          統(tǒng)計

          留言簿(8)

          積分與排名

          WebSphere Studio

          閱讀排行榜

          評論排行榜

          Work Flow 學習筆記(二)

          WfExecutionObject

          WfExecutionObject 是一個抽象類 , 它定義了一些的共有的屬性和方法 ; 該類的兩個主要派生類為 WfProcess WfActivity; 它的執(zhí)行步驟在介紹 WfProcess WfActivity 時我在對其進行詳細說明 , 這里主要介紹一下它的主要屬性和方法 ( 參考 ofbiz 實現(xiàn) ):

          (1) ??? key() 方法

          該方法返回當前可執(zhí)行對象的唯一標識 , 這里主要是 WfProcess WfActivity id;

          public String key() throws WfException {

          ??????? if (activityId != null)

          ??????????? return activityId;

          ??????? else

          ??????????? return processId;

          }

          (2) ??? processContext()

          該方法用于獲取當前執(zhí)行流程的相關(guān)數(shù)據(jù) ; 在可執(zhí)行流程剛剛創(chuàng)建時 , 會把它所需的上下文信息 ( 主要是名值對 ) xml 的格式保存到數(shù)據(jù)庫中 (RuntimeData); 這樣在運行時可以隨時從 RuntimeData 取出上下文信息 ;

          ? 運行時的對象信息是保存在 WorkEffort , 通過 WorkEffort 可以找到具體的 RuntimeData 數(shù)據(jù) ;

          (3) ??? state 屬性

          執(zhí)行對象狀態(tài) ( WfProcess 的流程狀態(tài)沒有關(guān)系 ) 的演變是它的核心部分 ; 各個狀態(tài)之間可以用一個層次結(jié)構(gòu)來表示 ;

          ????????????? ????? ???????? ? 狀態(tài)組成圖

          ??????

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ??

          ? 從上面這張圖可以很方便的推出各種實現(xiàn) , 比如當 open 狀態(tài)時候 , 我們可以知道目前只可有兩種狀態(tài)需要我們繼續(xù)關(guān)注 not_running running, 實現(xiàn)代碼如下

          ??? public List whileOpenType() throws WfException {

          ??????? String[] list = {"running", "not_running"};

          ?

          ??????? return Arrays.asList(list);

          }

          另外一個重點就是狀態(tài)的演變 , 很顯然狀態(tài)的演變有一定的約束 ; 比如它只能從 open->closed, 而不能反過來 ; 另外 open 狀態(tài)下的子狀態(tài)又可以互相進行演變 ; 狀態(tài)遷移圖如下

          ????????????????????? ? 狀態(tài)遷移圖

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          ?

          從上圖我們可以根據(jù)當前執(zhí)行對象的狀態(tài)推出可以演變的子狀態(tài)集合 ; 比如如當前狀態(tài)為 open.running, 那么它可以遷移的子狀態(tài)有 open.not_running.suspended 以及 closed 下的三個子狀態(tài) closed.completed,closed.terminated,closed.aborted, 而不能遷移到 open.not_running.not_started 狀態(tài) ;

          需要說明的一點是 , 按照 WF 規(guī)范遷移到 closed 狀態(tài) , 是指可以演變到 closed 下面三個子狀態(tài)的任何其中一個去 , 但不同的實現(xiàn)卻可以根據(jù)具體情況來進行設定 ; 比如 ofbiz 的實現(xiàn)中 ,not_started suspended 狀態(tài)只能遷移到 closed 下的 aborted, 而不能遷移到 completed teminated 狀態(tài)下 ;

          根據(jù)當前狀態(tài)獲取可以下一步的子狀態(tài)集合功能就是 validStates() 方法的實現(xiàn)了 ;

          (4)validStates()

          根據(jù)當前狀態(tài)獲取可以下一步的子狀態(tài)集合 , 從上面的遷移圖我們可以很容易實現(xiàn)該方法 ; 如下為 ofbiz 的參考實現(xiàn)

          public List validStates() throws WfException {

          ??????? String statesArr[] = {"open.running", "open.not_running.not_started", "open.not_running.suspended",

          ??????????????? "closed.completed", "closed.terminated", "closed.aborted"};

          ??????? ArrayList possibleStates = new ArrayList(Arrays.asList(statesArr));

          ??????? String currentState = state();

          ?

          ??????? if (currentState.startsWith("closed"))

          ??????????? return new ArrayList();

          ??????? if (!currentState.startsWith("open"))

          ??????????? throw new WfException("Currently in an unknown state.");

          ??????? if (currentState.equals("open.running")) {

          ??????????? possibleStates.remove("open.running");

          ??????????? possibleStates.remove("open.not_running.not_started");

          ??????????? return possibleStates;

          ??????? }

          ??????? if (currentState.equals("open.not_running.not_started")) {

          ??????????? possibleStates.remove("open.not_running.not_started");

          ??????????? possibleStates.remove("open.not_running.suspended");

          ??????????? possibleStates.remove("closed.completed");

          ??????????? possibleStates.remove("closed.terminated");???????????

          ??????????? return possibleStates;

          ??????? }

          ??????? if (currentState.equals("open.not_running.suspended")) {

          ??????????? possibleStates.remove("open.not_running.suspended");

          ??????????? possibleStates.remove("open.not_running.not_started");

          ??????????? possibleStates.remove("closed.complete");

          ??????????? possibleStates.remove("closed.terminated");???????????

          ??????????? return possibleStates;

          ??????? }

          ??????? return new ArrayList();

          }

          (5)changeState(String state)

          該方法的功能比較簡單 , 就是根據(jù)指定的狀態(tài)進行狀態(tài)的遷移 ; 需要注意的是在狀態(tài)轉(zhuǎn)變前必須調(diào)用上面的 validStates(), 判斷該遷移是否在允許的設定內(nèi) ;

          posted on 2006-05-25 20:25 junky 閱讀(352) 評論(1)  編輯  收藏 所屬分類: Work Flow

          評論

          # re: Work Flow 學習筆記(二) 2006-08-08 17:06 afdgfd

          gfsdgsdfg  回復  更多評論   


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 平定县| 台东市| 揭阳市| 唐山市| 荆门市| 香格里拉县| 钟山县| 大连市| 罗城| 东阿县| 腾冲县| 东乌珠穆沁旗| 健康| 信宜市| 大宁县| 鸡东县| 通化市| 依安县| 乌鲁木齐县| 双辽市| 拜城县| 南丹县| 沛县| 基隆市| 南漳县| 安远县| 淳化县| 确山县| 北安市| 香格里拉县| 聊城市| 陵水| 安吉县| 绥德县| 扶余县| 资溪县| 威信县| 甘谷县| 北京市| 汝州市| 玉林市|