45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 电脑教程 > 阅读资讯:怎么样使用---WfRequester接口?

怎么样使用---WfRequester接口?

2016-08-26 15:35:17 来源:www.45fan.com 【

怎么样使用---WfRequester接口?

WfRequester接口与实现

WfRequester接口是一个和工作流流程的执行及结果有直接关系的接口,它代表了对要做的工作的请求。

知识点:WfRequester接口的performerWfProcess,一个WfRequester接口可以对应好几个WfProcess

代码示例:

protected Map performers = null;

this.performers = new HashMap(); //构造procesrequesterMap

performers.put(process, requester);// registerProcess( )requester注册process

下面的方法与performer有关:

/**

*@see org.ofbiz.core.workflow.WfRequester#howManyPerformer()

*获取performersize

*/

public int howManyPerformer() throws WfException {

return performers.size();

}

 

/**

* @see org.ofbiz.core.workflow.WfRequester#getIteratorPerformer()

*获取performerIterator

*/

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,这样,它有一个执行者WfProcessWfProcess执行一个请求就是执行一个活动。

2) WfRequesterWfProcess连接到其它应用。

知识点: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://www.45fan.com/dnjc/67920.html
Tags: 工作流 源代码 ofbiz
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部