WfRequester接口是一个和工作流流程的执行及结果有直接关系的接口,它代表了对要做的工作的请求。
知识点:WfRequester接口的performer是WfProcess,一个WfRequester接口可以对应好几个WfProcess
代码示例:
protected Map performers = null;
this.performers = new HashMap(); //构造proces与requester的Map
performers.put(process, requester);// registerProcess( )为requester注册process
下面的方法与performer有关:
/**
*@see org.ofbiz.core.workflow.WfRequester#howManyPerformer()
*获取performer的size
*/
public int howManyPerformer() throws WfException {
return performers.size();
}
/**
* @see org.ofbiz.core.workflow.WfRequester#getIteratorPerformer()
*获取performer的Iterator
*/
public Iterator getIteratorPerformer() throws WfException {
return performers.keySet().iterator();
}
/**
* @see org.ofbiz.core.workflow.WfRequester#getSequencePerformer(int)
*获取List形式的performer
*/
public List getSequencePerformer(int maxNumber) throws WfException {
if (maxNumber > 0)
return new ArrayList(performers.keySet()).subList(0, (maxNumber - 1));
return new ArrayList(performers.keySet());
}
知识点:WfRequester接口常作为启动process的对象的接口
作为流程的启动者它通常做三件事情:
1) setting up the context
2) start the process
3) get the status and results
知识点:WfRequester接口和WfProcess的关联,一般有两种应用场合:
1) 工作流过程的演化 :在这种场合下,WfActivity被精化为WfRequester,这样,它有一个执行者WfProcess。WfProcess执行一个请求就是执行一个活动。
2) WfRequester将WfProcess连接到其它应用。
知识点:WfProcess一般用void receiveEvent(WfEventAudit event)方法来将工作流事件(event)通知给request
在发生活动的完成,中断,中止等事件时,流程必须通知requester
代码示例:
/**
*@see org.ofbiz.core.workflow.WfRequester#receiveEvent()
*/
public synchronized void receiveEvent(WfEventAudit event) throws WfException, InvalidPerformer {
// Should the source of the audit come from the process? if so use this.
WfProcess process = null;
try {
process = (WfProcess) event.source(); //事件来源于process
} catch (SourceNotAvailable sna) {
throw new InvalidPerformer("Could not get the performer", sna);
} catch (ClassCastException cce) {
throw new InvalidPerformer("Not a valid process object", cce);
}
//如果事件源不是与requester关联的process,则抛出异常
if (process == null)
throw new InvalidPerformer("No performer specified");
if (!performers.containsKey(process))
throw new InvalidPerformer("Performer not assigned to this requester");
GenericRequester req = null;
//如果事件源是与requester关联的process,则获取状态和结果
if (performers.containsKey(process))
req = (GenericRequester) performers.get(process);
if (req != null)
req.receiveResult(process.result());
}
本文地址:http://com.8s8s.com/it/it37143.htm