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

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

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            363 隨筆 :: 2 文章 :: 808 評(píng)論 :: 0 Trackbacks
          定義一個(gè)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);
           }

          }


          定義一個(gè)流程文件:

          <?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ū)動(dòng)類:

          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三個(gè)包加入classpath就可以了。
          執(zhí)行結(jié)果:
          Going to the first state!
          About to finish!
          posted on 2007-11-16 13:51 CowNew開源團(tuán)隊(duì) 閱讀(2551) 評(píng)論(0)  編輯  收藏 所屬分類: 技術(shù)類
          主站蜘蛛池模板: 上饶县| 垦利县| 渝中区| 贞丰县| 伊春市| 桦川县| 思茅市| 赤峰市| 泰安市| 鄂托克前旗| 沙湾县| 灌云县| 镇雄县| 万全县| 龙泉市| 德格县| 商都县| 通榆县| 苍南县| 舟山市| 集安市| 肥东县| 乐安县| 讷河市| 邯郸县| 布尔津县| 天峻县| 县级市| 芦溪县| 开鲁县| 宝兴县| 葫芦岛市| 沈丘县| 阳泉市| 信阳市| 陵水| 应城市| 江孜县| 临西县| 罗定市| 什邡市|