<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="example_5">
<start-state name="开始">
<event type="node-leave">
<action name="action1"></action>
</event>
<transition name="tr1" to="工作中"></transition>
<transition name="tr2" to="求学中"></transition>
</start-state>
<state name="工作中">
<event type="node-enter">
<action name="工作" class="com.wide.example5.WorkAction"></action>
</event>
<transition name="" to="终成正果"></transition>
</state>
<state name="求学中">
<event type="node-enter">
<action name="学习" class="com.wide.example5.StudyAction"></action>
</event>
<transition name="" to="终成正果"></transition>
</state>
<end-state name="终成正果">
<event type="node-enter">
<action name="圆满" class="com.wide.example5.EndAction"></action>
</event>
</end-state>
</process-definition>
这是一个比较简单的jbpm流程模板,通过这几天的学习(基本上是看别人的事子)发现jbpm原来这么的复杂的,好多东西想记下来,特别是一个同行总结出的例子,非常简洁的描述了各个小功能点。以下也是一个很简单的jpdl模板,清楚的描述了note与state的区别。jbpm提供了好几种不同的节点。
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="example_7">
<start-state name="start">
<transition name="tr1" to="state"></transition>
<transition name="tr2" to="node"></transition>
</start-state>
<state name="state"> <!-- 只有签收signal才执行 -->
<transition name="" to="end"></transition>
</state>
<node name="node"> <!-- 直接执行,当流转到这节点时,就马上执行transition -->
<transition name="" to="end"></transition>
</node>
<end-state name="end"></end-state>
</process-definition>
测试代码也很简单,
package com.jbpm;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import java.io.*;
public class Execute {
static JbpmConfiguration cfg=JbpmConfiguration.getInstance();
/**
* 把流程部署到数据库
* @param file
*/
public void deploy(String file){
JbpmContext jc=null;
try{
FileInputStream fis = new FileInputStream("src/proc2.xml");
ProcessDefinition pd=ProcessDefinition.parseXmlInputStream(fis);
jc=cfg.createJbpmContext();
jc.deployProcessDefinition(pd);
}catch(Exception e){
e.printStackTrace();
}finally{
jc.close();
}
}
public static void main(String args[])throws Exception {
Execute e=new Execute();
//e.deploy("src/proc2");
JbpmContext jc=cfg.createJbpmContext();
GraphSession gs=jc.getGraphSession();
ProcessDefinition pd=gs.findLatestProcessDefinition("example_5");
ProcessInstance pi=new ProcessInstance(pd);
Token token=pi.getRootToken();
System.out.println("token-->"+token.getNode().getName());
token.signal("tr1");
System.out.println("tr1-->"+token.getNode().getName());
token.signal();
System.out.println("kk->"+token.getNode().getName());
System.out.println("是否已结束->"+pi.hasEnded());
jc.save(pi);
}
}
以上这个类对应第一个工作流模板,至于该模板里定义的接口,
<action name="工作" class="com.wide.example5.WorkAction"></action>
该class只需要实现ActionHandler接口就行了,具体有啥用我现也没搞懂:)我一直努力着。
posted on 2007-04-11 23:48
有猫相伴的日子 阅读(2410)
评论(0) 编辑 收藏 所属分类:
workflow