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í)行流程的相關數(shù)據(jù)
;
在可執(zhí)行流程剛剛創(chuàng)建時
,
會把它所需的上下文信息
(
主要是名值對
)
以
xml
的格式保存到數(shù)據(jù)庫中
(RuntimeData);
這樣在運行時可以隨時從
RuntimeData
取出上下文信息
;
?
運行時的對象信息是保存在
WorkEffort
中
,
通過
WorkEffort
可以找到具體的
RuntimeData
數(shù)據(jù)
;
(3)
???
state
屬性
執(zhí)行對象狀態(tài)
(
和
WfProcess
的流程狀態(tài)沒有關系
)
的演變是它的核心部分
;
各個狀態(tài)之間可以用一個層次結構來表示
;
?????????????
?????
????????
?
狀態(tài)組成圖
??????
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
??
?
從上面這張圖可以很方便的推出各種實現(xiàn)
,
比如當
open
狀態(tài)時候
,
我們可以知道目前只可有兩種狀態(tài)需要我們繼續(xù)關注
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)轉變前必須調用上面的
validStates(),
判斷該遷移是否在允許的設定內
;