???????????????
???? Work Flow
學習筆記
1.???
WfRequester
WfRequester
is the interface that has a direct concern with the execution and results
of a workflow process - it represents the request for some work to be done. Its
performer, a WfProcess, is expected to handle its request and communicate significant
status changes; in particular to inform the requester when it has completed performing
the requested work. A single requester can have many processes associated with it.
?
??

?
?
說明:
WfRequester
接口是一個和工作流流程的執行及結果有直接關系的接口;它代表了對一些工作執行的請求;它的一個主要功能是把
WfProcess
鏈接到一個其它應用;其中
WfRequester
會關聯到多個
WfProcee,
當
WfProcess
發生
complete
、
terminate
、
abort
事件時會通過回調
receiveEvent()
方法來通知
WfRequest
;在
receiveEvent(event)
方法中,參數
event
是一個
WfEventAudit
對象,其中
WfEventAudit
中有一個方法
source(),
通過這個方法我們可以得知是哪個
WfExecutionObject
對象觸發了事件源;得到了
WfExcutionObject
即
WfProcess
我們也進而
得到了和這個
WfProcess
相關聯的其它應用;
主要步驟
:
(1)???
自定義一個自己的類或接口,如
GenericRequester,
這個
GenericRequester
類代表用戶自定義的一個請求者;
(2)???
在啟動
WfProcess
是,把這個請求者和
WfProcess
進行綁定注冊到
WfRequester
中;
?
在
WfReuester
的
registerProcess()
就是做這個功能,主要代碼如下
protected Map performers = null;
public void registerProcess(WfProcess process, Map context, GenericRequester requester){
??????????????
performers.put(process, requester);
?
}
(3)???
當工作流程在執行的過程中發生
complete
、
terminate
、
abort
事件時會回調
WfRequest
中的
receiveEvent()
方法:
???
?
requester.receiveEvent(audit);
(4)
??
在
receiveEvent()
中首先根據
WfEventAudit
的
source()
獲取觸發事件的
WfProcess
對象;
receiveEvent(WfEventAudit event){
??????? //
獲取事件源
process
對象
WfProcess? process = (WfProcess) event.source();
//
根據
prcocess
對象獲取在注冊時綁定的自定義請求者
GenericRequester
GenericRequester ?req = (GenericRequester) performers.get(process);
//
執行自定義請求者的方法
req.receiveResult(process.result());
}
其它:在這里
GenericRequester
也可是一個
WfProcess
或
WfActivity
對象,這樣可以在
WfProcess
完成操作后又啟動另一個子流程或某個活動;
???