如鵬網(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 評(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ì) 閱讀(2555) 評(píng)論(0)  編輯  收藏 所屬分類: 技術(shù)類
          主站蜘蛛池模板: 敦煌市| 阿鲁科尔沁旗| 平舆县| 临江市| 深圳市| 溧水县| 方正县| 儋州市| 柏乡县| 大余县| 久治县| 兰溪市| 内黄县| 阿瓦提县| 凌海市| 平原县| 新乡市| 政和县| 鄄城县| 开原市| 玉屏| 阳原县| 喜德县| 桐庐县| 蓬莱市| 股票| 黑水县| 乌拉特中旗| 葫芦岛市| 白银市| 东源县| 临清市| 红河县| 容城县| 随州市| 彭州市| 新竹市| 勃利县| 聊城市| 灵璧县| 虞城县|