如鵬網 大學生計算機學習社區

          CowNew開源團隊

          http://www.cownew.com 郵件請聯系 about521 at 163.com

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            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>

          定義流程驅動類:

          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開源團隊 閱讀(2555) 評論(0)  編輯  收藏 所屬分類: 技術類
          主站蜘蛛池模板: 普定县| 朝阳区| 尚志市| 小金县| 饶平县| 武强县| 资溪县| 阿拉善右旗| 宁河县| 浦江县| 胶南市| 紫阳县| 集安市| 温州市| 滦平县| 通榆县| 沙河市| 新疆| 民和| 闸北区| 公安县| 德安县| 镇江市| 武强县| 元阳县| 登封市| 吴江市| 城固县| 吉水县| 察隅县| 中牟县| 玛沁县| 奈曼旗| 石阡县| 长春市| 德清县| 平江县| 扶沟县| 瓮安县| 花莲县| 乌鲁木齐市|