CSDN博客

img hongbo781202

ofbiz工作流源代码学习(1)---WfRequester接口

发表于2004/4/7 14:35:00  2977人阅读

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());

    }

 

 

 

 

 

0 0

相关博文

我的热门文章

img
取 消
img