少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
          osworkflow.xml
          <osworkflow>
           <persistence class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore" />
           <factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
            <property key="resource" value="workflows.xml" />
           </factory>
          </osworkflow>


          workflows.xml
          <workflows>
            <workflow name="docworkflow" type="resource" location="myworkflow.xml"/>
          </workflows>


          myworkflow.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE workflow PUBLIC "-//OpenSymphony Group//DTD OSWorkflow 2.6//EN" "<workflow>
           <registers>
            <register type="class" variable-name="log">
             <arg name="class.name">com.opensymphony.workflow.util.LogRegister</arg>
             <arg name="addInstanceId">true</arg>
            </register>
           </registers>

           <initial-actions>
            <action id="100" name="Start Ordinary Workflow">
             <results>
              <unconditional-result old-status="Finished"
               status="Queued" step="1" />
             </results>
            </action>
            <action id="200" name="Start Emergent Workflow">
             <results>
              <unconditional-result old-status="Finished"
               status="Queued" step="5" />
             </results>
            </action>
           </initial-actions>

           <steps>

            <step id="1" name="Initiate Doc">
             <actions>
              <action id="1" name="Initial Work">
               <restrict-to>
                <conditions>
                 <condition type="class">
                  <arg name="class.name">
                   com.opensymphony.workflow.util.StatusCondition
                  </arg>
                  <arg name="status">Queued</arg>
                 </condition>
                </conditions>
               </restrict-to>
               <validators>
                <validator type="class">
                 <arg name="class.name">
                  org.abin.lee.validator.TitleValidator
                 </arg>
                </validator>
               </validators>
               <pre-functions>
                <function type="class">
                 <arg name="class.name">
                  com.opensymphony.workflow.util.Caller
                 </arg>
                 <arg name="stepId">1</arg>
                </function>
                <function type="beanshell">
                 <arg name="script">
                  transientVars.get("log").info("Initiate Work");
                 </arg>
                </function>
               </pre-functions>
               <results>
                <unconditional-result old-status="Finished"
                 status="Prepared" step="1" owner="${caller}" />
               </results>
               <post-functions>
                <function type="beanshell">
                 <arg name="script">
                  propertySet.setString("title",
                  (String)transientVars.get("title"));
                 </arg>
                </function>
               </post-functions>
              </action>
              <action id="2" name="Deliver Work">
               <restrict-to>
                <conditions type="AND">
                 <condition type="class">
                  <arg name="class.name">
                   com.opensymphony.workflow.util.StatusCondition
                  </arg>
                  <arg name="status">Prepared</arg>
                  <arg name="stepId">1</arg>
                 </condition>
                 <condition type="class">
                  <arg name="class.name">
                   com.opensymphony.workflow.util.AllowOwnerOnlyCondition
                  </arg>
                 </condition>
                </conditions>
               </restrict-to>
               <pre-functions>
                <function type="beanshell">
                 <arg name="script">
                  transientVars.get("log").info("Deliver Doc to Boss A and B");
                 </arg>
                </function>
               </pre-functions>
               <results>
                <unconditional-result old-status="Finished"
                 status="Prepared" split="1" />
               </results>
              </action>
             </actions>
            </step>

            <step id="2" name="Review Doc In Boss A">
             <external-permissions>
              <permission name="permA">
               <restrict-to>
                <conditions type="AND">
                 <condition name="check.status" type="class">
                  <arg name="class.name">com.opensymphony.workflow.util.StatusCondition</arg>
                  <arg name="status">Prepared</arg>
                 </condition>
                 <condition name="allow.owner.only" type="class">
                  <arg name="class.name">com.opensymphony.workflow.util.AllowOwnerOnlyCondition</arg>
                 </condition>
                </conditions>
               </restrict-to>
              </permission>
             </external-permissions>
             <actions>
              <action id="3" name="Review Work By A">
               <pre-functions>
                <function type="beanshell">
                 <arg name="script">
                  transientVars.get("log").info("Doc Reviewed By Boss A")
                 </arg>
                </function>
               </pre-functions>
               <results>
                <unconditional-result old-status="Finished"
                 status="Underway" join="1" />
               </results>
              </action>
             </actions>
            </step>

            <step id="3" name="Review Doc In Boss B">
             <external-permissions>
              <permission name="permA">
               <restrict-to>
                <conditions type="AND">
                 <condition name="check.status" type="class">
                  <arg name="class.name">com.opensymphony.workflow.util.StatusCondition</arg>
                  <arg name="status">Prepared</arg>
                 </condition>
                 <condition name="allow.owner.only" type="class">
                  <arg name="class.name">com.opensymphony.workflow.util.AllowOwnerOnlyCondition</arg>
                 </condition>
                </conditions>
               </restrict-to>
              </permission>
             </external-permissions>
             <actions>
              <action id="4" name="Review Work By B">
               <pre-functions>
                <function type="beanshell">
                 <arg name="script">
                  transientVars.get("log").info("Doc Reviewed By Boss B")
                 </arg>
                </function>
               </pre-functions>
               <results>
                <unconditional-result old-status="Finished"
                 status="Underway" join="1" />
               </results>
              </action>
             </actions>
            </step>

            <step id="4" name="Finish Ordinary Work">
             <pre-functions>
              <function type="beanshell">
               <arg name="script">
                System.out.println("Finish Doc Review. \nTitle:"+propertySet.getString("title")+".");
               </arg>
              </function>
             </pre-functions>
            </step>

            <step id="5" name="Finish Emergent Work">
             <pre-functions>
              <function type="beanshell">
               <arg name="script">
                System.out.println("Emergency Handler");
               </arg>
              </function>
             </pre-functions>
            </step>

           </steps>

           <splits>
            <split id="1">
             <unconditional-result old-status="Finished"
              status="Prepared" step="2" />
             <unconditional-result old-status="Finished"
              status="Prepared" step="3" />
            </split>
           </splits>

           <joins>
            <join id="1">
             <conditions type="AND">
              <condition type="beanshell">
               <arg name="script"><![CDATA[ "Finished".equals(jn.getStep(2).getStatus()) && "Finished".equals(jn.getStep(3).getStatus()) ]]></arg>
              </condition>
             </conditions>
             <unconditional-result old-status="Finished"
              status="Reviewed" step="4" />
            </join>
           </joins>

          </workflow>




          TitleValidator.java

          package org.abin.lee.validator;

          import java.util.Map;
          import com.opensymphony.module.propertyset.PropertySet;
          import com.opensymphony.workflow.InvalidInputException;
          import com.opensymphony.workflow.Validator;
          import com.opensymphony.workflow.WorkflowException;

          public class TitleValidator implements Validator {
           public void validate(Map transientVars, Map args, PropertySet ps)
             throws InvalidInputException, WorkflowException {
            System.out.println("TitleValidator is running");
            String title = (String) transientVars.get("title");
            if (title == null)
             throw new InvalidInputException("Missing title");
            if (title.length() > 30)
             throw new InvalidInputException("Title too long");
           }
          }



          SimpleSample.java

          package org.abin.lee.workflow;

          import java.util.HashMap;

          import com.opensymphony.workflow.InvalidActionException;
          import com.opensymphony.workflow.InvalidEntryStateException;
          import com.opensymphony.workflow.InvalidInputException;
          import com.opensymphony.workflow.InvalidRoleException;
          import com.opensymphony.workflow.Workflow;
          import com.opensymphony.workflow.WorkflowException;
          import com.opensymphony.workflow.basic.BasicWorkflow;
          import com.opensymphony.workflow.config.DefaultConfiguration;

          public class SimpleSample {
           public static void main(String[] args) {
            try {
             Workflow workflow = new BasicWorkflow("abin");

             DefaultConfiguration config = new DefaultConfiguration();
             workflow.setConfiguration(config);

             long workflowId = workflow.initialize("docworkflow", 100, null);
             HashMap inputs = new HashMap();
             inputs.put("title", "openopen");

             workflow.doAction(workflowId, 1, inputs);

             workflow.doAction(workflowId, 2, null);

             workflow.doAction(workflowId, 3, null);

             workflow.doAction(workflowId, 4, null);
             
            } catch (InvalidActionException e) {
             System.out.println(e.getMessage());
            } catch (InvalidRoleException e) {
             System.out.println(e.getMessage());
            } catch (InvalidInputException e) {
             System.out.println(e.getMessage());
            } catch (InvalidEntryStateException e) {
             System.out.println(e.getMessage());
            } catch (WorkflowException e) {
             System.out.println(e.getMessage());
            }
           }
          }




          log4j.properties

          log4j.rootCategory=info,log,console

          log4j.logger.org.apache.axis2.enterprise=FATAL
          log4j.logger.de.hunsicker.jalopy.io=FATAL
          log4j.logger.httpclient.wire.header=FATAL
          log4j.logger.org.apache.commons.httpclient=FATAL

          log4j.appender.console=org.apache.log4j.ConsoleAppender
          log4j.appender.console.layout=org.apache.log4j.PatternLayout
          log4j.appender.console.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
           
          log4j.appender.log=org.apache.log4j.DailyRollingFileAppender
          log4j.appender.log.File=logs/osworkflow.log
          log4j.appender.log.layout=org.apache.log4j.PatternLayout
          log4j.appender.log.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n




          http://blog.sina.com.cn/s/blog_544a96ce0100nvjy.html

          http://blog.csdn.net/tanruitian/article/details/498167

          http://www.cnblogs.com/jacky73/archive/2008/12/17/1357134.html

          posted on 2012-06-03 22:39 abin 閱讀(1552) 評論(2)  編輯  收藏 所屬分類: workflow

          Feedback

          # re: Osworkflow2.8 入門級例子 2012-11-05 17:42 Taiwaner
          Osworkflow 已經不再開發了,不是嗎?

            回復  更多評論
            

          # re: Osworkflow2.8 入門級例子 2013-01-16 23:47 abin
          @Taiwaner
          是滴,osworkflow貌似不提供更新了,都是使用以前的老東西,現在好多人都在用Jbpm。  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 日土县| 岚皋县| 南京市| 安宁市| 富源县| 张家港市| 如东县| 清涧县| 普兰店市| 灵宝市| 拜泉县| 鹤山市| 防城港市| 长顺县| 北川| 三河市| 宁晋县| 喀喇沁旗| 凤城市| 五原县| 遂溪县| 高安市| 库伦旗| 洛浦县| 武鸣县| 陵川县| 萨嘎县| 新建县| 黔西县| 喀喇沁旗| 弥渡县| 南宫市| 竹溪县| 嵩明县| 门源| 怀宁县| 上思县| 喜德县| 达日县| 隆子县| 甘泉县|