如鹏网 大学生计算机学习社区

CowNew开源团队

http://www.cownew.com 邮件请联系 about521 at 163.com

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  290 随笔 :: 2 文章 :: 808 评论 :: 0 Trackbacks
定义一个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!
posted on 2007-11-16 13:51 CowNew开源团队 阅读(2437) 评论(0)  编辑  收藏 所属分类: 技术类

只有注册用户登录后才能发表评论。


网站导航: