51Testing软件测试论坛

标题: 工作流内部部分代码 [打印本页]

作者: caianying    时间: 2007-1-3 21:22
标题: 工作流内部部分代码
Using the the InMemoryWorklist




Here is a small example on how to use the InMemoryWorklist :
package test;import openwfe.org.engine.workitem.WorkItem;import openwfe.org.engine.workitem.LaunchItem;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.workitem.AttributeUtils;import openwfe.org.embed.engine.Engine;import openwfe.org.embed.worklist.Worklist;import openwfe.org.embed.impl.engine.InMemoryEngine;import openwfe.org.embed.impl.engine.AbstractEmbeddedParticipant;import openwfe.org.embed.impl.worklist.InMemoryWorklist;public class TestWorklist{    public static void main (String[] args)        throws Exception    {        //        // prepare engine        Engine engine = new InMemoryEngine();        // prepare worklists        InMemoryWorklist wla = new InMemoryWorklist("a");        InMemoryWorklist wlb = new InMemoryWorklist("b");        // register participants        engine.registerParticipant(wla);        engine.registerParticipant(wlb);        //        // launch flow        LaunchItem li = new LaunchItem();        li.setWorkflowDefinitionUrl("field:__definition__");        String flowDef =             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+            "<process-definition name=\"test\" revision=\"0.0\">\n"+            "   <sequence>\n"+            "      <participant ref=\"a\" />\n"+            "      <participant ref=\"b\" />\n"+            "   </sequence>\n"+            "</process-definition>";        li.getAttributes().puts("__definition__", flowDef);        engine.launch(li, true);        //        // play with the flow        System.out.println("wla.countWorkItems() : "+wla.countWorkItems());        System.out.println("wlb.countWorkItems() : "+wlb.countWorkItems());        java.util.Iterator it = wla.iterator();        InFlowWorkItem wi = (InFlowWorkItem)it.next();        wla.forward(wi);        System.out.println("\n ~~ forwarded workitem\n");        System.out.println("wla.countWorkItems() : "+wla.countWorkItems());        System.out.println("wlb.countWorkItems() : "+wlb.countWorkItems());    }}As you can see, those embedded worklist are registrable in the engine as embedded participants may be.




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2