最简单的JBPM例子

定义一个ActionHandler:
package com.test;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
public class MyAction implements ActionHandler
{
 private static final long serialVersionUID = 1L;
 private String message;
 public String getMessage()
 {
  return message;
 }
 public void setMessage(String message)
 {
  this.message = message;
 }
 public void execute(ExecutionContext executionContext) throws Exception
 {
  System.out.println(message);
 }
}

定义一个流程文件:
<?xml version="1.0" encoding="UTF-8"?>
<process-definition
  xmlns="urn:jbpm.org:jpdl-3.1"
  name="simple">
   <start-state name="start">
      <transition name="to_state" to="first">
         <action name="action" class="com.test.MyAction">
            <message>Going to the first state!</message>
         </action>
      </transition>
   </start-state>
   <state name="first">
      <transition name="to_end" to="end">
         <action name="action" class="com.test.MyAction">
            <message>About to finish!</message>
         </action>
      </transition>
   </state>
   <end-state name="end"></end-state>
</process-definition>
定义流程驱动类:
package com.test;
import java.io.IOException;
import java.io.InputStream;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
public class Main
{
 public static void main(String[] args) throws IOException
 {
  InputStream stream = Main.class.getResourceAsStream("processdefinition.xml");
  ProcessDefinition processDefinition = ProcessDefinition
    .parseXmlInputStream(stream);
  stream.close();
  ProcessInstance instance = new ProcessInstance(processDefinition);
  while (!instance.hasEnded())
  {
   instance.signal();
  }
 }
}

将jbpm***.jar、commons-logging**.jar和dom4j.jar三个包加入classpath就可以了。
执行结果:
Going to the first state!
About to finish!

本文出自 “CowNew开源团队” 博客,转载请与作者联系!

你可能感兴趣的:(职场,例子,最简单,休闲)