OsWorkFlow工作流简介

OsWorkFlow工作流简介:

Osworkflow是完全用java语言编写的开放源代码的工作流引擎,具有显著的灵活性及完全面向有技术背景的用户的特点。用户可以根据自身的需求利用这款开源软件设计简单或是复杂的工作流。通过使用,用户就可以把工作中心放在业务和规则的定义上,而不需通过硬编码的方式实现一个Petri网或是一个有穷自动机。用户可以以最小的代价把osworkflow整合到自己的程序中来。

OsWorkFlow工作流实例:

下载工作流相关jar包:osworkflow-2.8.0.jar

工作流配置文件:

osworkflow.xml

[html] view plain copy
  1. <osworkflow>  
  2.     <persistence  
  3.         class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore" />  
  4.     <factory  
  5.         class="com.opensymphony.workflow.loader.XMLWorkflowFactory">  
  6.         <property key="resource" value="workflows.xml" />  
  7.     </factory>  
  8. </osworkflow>  
workflows.xml
[html] view plain copy
  1. <workflows>  
  2.     <workflow name="mytest" type="resource" location="myworkflow.xml" />  
  3. </workflows>  
myworkflow.xml
[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE workflow PUBLIC   
  3.   "-//OpenSymphony Group//DTD OSWorkflow 2.7//EN"  
  4.   "http://www.opensymphony.com/osworkflow/workflow_2_7.dtd">  
  5. <workflow>  
  6.     <initial-actions>  
  7.         <action id="100" name="Start Workflow">  
  8.             <results>  
  9.                 <unconditional-result old-status="Finished"  
  10.                     status="Queued" step="1" />  
  11.             </results>  
  12.         </action>  
  13.     </initial-actions>  
  14.     <steps>  
  15.         <step id="1" name="First Draft">  
  16.             <actions>  
  17.                 <action id="1" name="Start First Draft">  
  18.                     <restrict-to>  
  19.                         <conditions>  
  20.                             <condition type="class">  
  21.                                 <arg name="class.name">  
  22.                                     com.opensymphony.workflow.util.StatusCondition  
  23.                                 </arg>  
  24.                                 <arg name="status">Queued</arg>  
  25.                             </condition>  
  26.                         </conditions>  
  27.                     </restrict-to>  
  28.                     <pre-functions>  
  29.                         <function type="class">  
  30.                             <arg name="class.name">  
  31.                                 com.opensymphony.workflow.util.Caller  
  32.                             </arg>  
  33.                         </function>  
  34.                     </pre-functions>  
  35.                     <results>  
  36.                         <unconditional-result old-status="Finished"  
  37.                             status="Underway" step="1" owner="${caller}" />  
  38.                     </results>  
  39.                 </action>  
  40.                 <action id="2" name="Finish First Draft">  
  41.                     <restrict-to>  
  42.                         <conditions type="AND">  
  43.                             <condition type="class">  
  44.                                 <arg name="class.name">  
  45.                                     com.opensymphony.workflow.util.StatusCondition  
  46.                                 </arg>  
  47.                                 <arg name="status">Underway</arg>  
  48.                             </condition>  
  49.                             <condition type="class">  
  50.                                 <arg name="class.name">  
  51.                                     com.opensymphony.workflow.util.AllowOwnerOnlyCondition  
  52.                                 </arg>  
  53.                             </condition>  
  54.                         </conditions>  
  55.                     </restrict-to>  
  56.                     <results>  
  57.                         <unconditional-result old-status="Finished"  
  58.                             status="Queued" step="2" />  
  59.                     </results>  
  60.                 </action>  
  61.             </actions>  
  62.         </step>  
  63.         <step id="2" name="finished" />  
  64.     </steps>  
  65. </workflow>  

测试类:
[java] view plain copy
  1. package test;  
  2.   
  3. import java.util.HashMap;  
  4.   
  5. import com.opensymphony.workflow.InvalidActionException;  
  6. import com.opensymphony.workflow.InvalidEntryStateException;  
  7. import com.opensymphony.workflow.InvalidInputException;  
  8. import com.opensymphony.workflow.InvalidRoleException;  
  9. import com.opensymphony.workflow.Workflow;  
  10. import com.opensymphony.workflow.WorkflowException;  
  11. import com.opensymphony.workflow.basic.BasicWorkflow;  
  12.   
  13. public class MyWorkflowTest {  
  14.   
  15.     @SuppressWarnings("unchecked")  
  16.     public static void main(String[] args) throws InvalidActionException, InvalidRoleException, InvalidInputException, InvalidEntryStateException, WorkflowException {  
  17.         String caller = "testUser";  
  18.         String params1 = "params1";  
  19.         String docTitle = "docTitle";  
  20.         long workflowId = 1;  
  21.         HashMap inputs = new HashMap();  
  22.   
  23.         Workflow wf = new BasicWorkflow(caller);  
  24.         inputs.put("params1", params1);  
  25.         inputs.put("docTitle", docTitle);  
  26.         workflowId = wf.initialize("mytest"100, inputs);  
  27.           
  28.         //执行第1步动作  
  29.         wf.doAction(workflowId, 1, inputs);  
  30.     }  
  31.       

你可能感兴趣的:(OsWorkFlow工作流)