如鵬網(wǎng) 大學(xué)生計(jì)算機(jī)學(xué)習(xí)社區(qū)

          CowNew開源團(tuán)隊(duì)

          http://www.cownew.com 郵件請聯(lián)系 about521 at 163.com

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            363 隨筆 :: 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>

          定義流程驅(qū)動類:

          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就可以了。
          執(zhí)行結(jié)果:
          Going to the first state!
          About to finish!
          posted on 2007-11-16 13:51 CowNew開源團(tuán)隊(duì) 閱讀(2552) 評論(0)  編輯  收藏 所屬分類: 技術(shù)類
          主站蜘蛛池模板: 盐池县| 大名县| 宁远县| 郎溪县| 永城市| 犍为县| 乌兰察布市| 南部县| 九台市| 台山市| 乃东县| 荆门市| 谢通门县| 涞源县| 金山区| 景泰县| 增城市| 丽江市| 谢通门县| 社会| 万荣县| 张北县| 微博| 萨嘎县| 遂平县| 和平县| 泰顺县| 肃宁县| 大理市| 禹城市| 广平县| 儋州市| 延吉市| 沧源| 江门市| 新乐市| 庐江县| 周至县| 临猗县| 通榆县| 广饶县|