开始一个流程
我们通过XML完成的只是流程的定义,真正需要流程跑起来,我们还需要一个个流程的实例。
Workflow
接口
OSWorkflow最主要最常用的操作都是通过Workflow接口来完成的。OSWorkflow针对Ofbiz、EJB、XFireSOAP、OfbizSOAP都给出了自己的Workflow实现,我们可以根据场景选用。
BasicWorkflow
BasicWorkflow是我们在大多数场合下使用频率最高的Workflow实现。
initialize方法
通过initialize方法,我们可以创建属于我们自己的流程实例,完成一些初始化操作,并返回新创建的流程id。以下是initialize的方法签名:
/**
* Initializes a workflow so that it can begin processing. A workflow must be initialized before it can
* begin any sort of activity. It can only be initialized once.
*
* @param workflowName The workflow name to create and initialize an instance for
* @param initialAction The initial step to start the workflow
* @param inputs The inputs entered by the end-user
* @throws InvalidRoleException if the user can't start this function
* @throws InvalidInputException if a validator is specified and an input is invalid.
* @throws InvalidActionException if the specified initial action is invalid for the specified workflow.
*/
public long initialize(String workflowName, int initialAction, Map inputs) throws InvalidRoleException, InvalidInputException, WorkflowException, InvalidEntryStateException, InvalidActionException;
workflowName:我们在定义workflow是name属性的值,比如下例中的example,
<workflow name="example" type="resource" location="example.xml"/>
initialAction:我们在流程定义文件中定义的initialAction的id,比如下例中的100,
<initial-actions>
<action id="100" name="Start Workflow">
<pre-functions>
<function type="class">
<arg name="class.name">com.opensymphony.workflow.util.Caller</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished" status="Underway" step="1" owner="${caller}"/>
</results>
</action>
</initial-actions>
inputs:用来保存我们自己需要用到的一些key-value,他可以在action里的condition、function、validator中作为各自的方法参数传递,我们可以在相应的接口方法中轻易的读写。
以下是initialize方法的实例代码:
Workflow workflow = new BasicWorkflow("caller");
Configuration config = new DefaultConfiguration();
workflow.setConfiguration(config);
long workflowId = workflow.initialize("example", 100, null);
doAction方法
doAction方法用来执行一个动作行为,驱动着流程的运转。
/**
* Perform an action on the specified workflow instance.
* @param id The workflow instance id.
* @param actionId The action id to perform (action id's are listed in the workflow descriptor).
* @param inputs The inputs to the workflow instance.
* @throws InvalidInputException if a validator is specified and an input is invalid.
* @throws InvalidActionException if the action is invalid for the specified workflow
* instance's current state.
*/
public void doAction(long id, int actionId, Map inputs) throws InvalidInputException, WorkflowException;
参数:
id:workflow entity id 即实例id
actionId:action id
inputs:同initialize方法inputs参数。
getCurrentSteps方法
返回指定workflow实例的当前step对象的集合
/**
* Returns a Collection of Step objects that are the current steps of the specified workflow instance.
*
* @param id The workflow instance id.
* @return The steps that the workflow instance is currently in.
*/
public List getCurrentSteps(long id);
参数:
id:workflow entity id 即实例id
getHistorySteps方法
返回指定workflow实例的当前历史step对象的集合
/**
* Returns a list of all steps that are completed for the given workflow instance id.
*
* @param id The workflow instance id.
* @return a List of Steps
* @see com.opensymphony.workflow.spi.Step
*/
public List getHistorySteps(long id);
参数:
id:workflow entity id 即实例id
action到底做了些什么
不论是initialize方法还是doAction方法,最后都会通过AbstractWorkflow的transitionWorkflow方法来完成流程流转的,下图是transitionWorkflow方法的执行步骤。
VariableResolver
VariableResolver接口只有一个translateVariables方法,OSWorkflow给出了一个默认实现DefaultVariableResolver。他负责将我们在XML流程定制文件中使用的类似“${var}”这样的占位符给替换成其具体的值。他首先会去transientVars中去找key=var的值,如果没有找到则会到propertySet去找。如此一来,我们就可以在XML文件中使用类似“${var}”这样的占位符,只要我们在之前把它们保存到transientVars或者propertySet就可以啦。
让OSWorkflow运行在Spring事务中
要让OSWorkflow和我们的应用运行在同一个事务中,前提是我们需要保证我们有相同的connection(JDBC)或者sessionFactory(hibernate),然后我们可以给Workflow
接口创建一个事务代理,当Workflow
接口的方法被执行时,可以加入到当前线程开启的事务中去,通过IOC容器这一切都变得那么简单。请参考以下红色部分的字体。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="propertySetDelegate"
class="com.opensymphony.workflow.spi.hibernate3.DefaultHibernatePropertySetDelegate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="workflowStore"
class="com.opensymphony.workflow.spi.hibernate3.SpringHibernateWorkflowStore">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="propertySetDelegate">
<ref bean="propertySetDelegate" />
</property>
</bean>
<bean id="workflowFactory"
class="com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory"
init-method="init">
<property name="resource">
<value>workflows.xml</value>
</property>
<property name="reload">
<value>true</value>
</property>
</bean>
<bean id="osworkflowConfiguration" class="com.opensymphony.workflow.config.SpringConfiguration">
<property name="store">
<ref local="workflowStore" />
</property>
<property name="factory">
<ref local="workflowFactory" />
</property>
</bean>
<bean id="workflowTypeResolver" class="com.opensymphony.workflow.util.SpringTypeResolver">
</bean>
<bean id="basicWorkflow" class="com.opensymphony.workflow.basic.BasicWorkflow">
<constructor-arg>
<value></value>
</constructor-arg>
<property name="configuration">
<ref local="osworkflowConfiguration" />
</property>
<property name="resolver">
<ref local="workflowTypeResolver" />
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="workflow" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="singleton">
<value>false</value>
</property>
<property name="proxyInterfaces">
<value>com.opensymphony.workflow.Workflow</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<value>basicWorkflow</value>
</list>
</property>
</bean>
</beans>
通过之前篇幅的探讨,我们的Spring Application Context应该如以上清单所示。如果使用Spring更高的版本,我们甚至可以通过其高级的特性来完成事务相关的配置,这些就不在此讨论范围之内啦。
OSWorkflow还有很多特性被我略过了,如对SOAP和EJB的相关支持,等等。对于没有提到的部分,大家也都可以一起分享探讨。
- 大小: 105.7 KB
分享到:
相关推荐
NULL 博文链接:https://kt8668.iteye.com/blog/1148886
OSWORKFlow流程开发教程
花了两天时间写了个demo作用是通过flex解析osworkflow定义文件生成流程图,下载需要五个积分。辛苦费 还望谅解 不骗分 此附近效果图在http://huqingyun69.iteye.com/admin/blogs/1930123这个链接上有解说 大家可以先...
NULL 博文链接:https://qsx1982-126-com.iteye.com/blog/769059
OSWorkflow中文手册+开发指南,包括了OSWorkflow的官方例子。
OSWorkflow的开发指导与指南.pdf
OSWorkflow开发指南[汇编].pdf
NULL 博文链接:https://jeenry119.iteye.com/blog/1195769
他翻译的OSWorkflow官方文档中文版是为数不多的高质量中文OSWorkflow文档之一。而他在翻译之外,总结自己学习的经验和方法原创编写了《OSWorkflow开发指南》,更是毫无保留的奉献了自己多年的心得。
OSWorkflow 工作流 开发指南、中文手册
免分下载(我也在学) 我们的口号就是:是知识,就应该共享 发现spi.hibernate3.DefaultHibernatePropertySetDelegate.java是不存在的 spi.hibernate.DefaultHibernatePropertySetDelegate.java存在。...
osWorkFlow 开源工作流 开发指南
OSWorkflow
简单易用的数据流开发技术,绝对够味。 OSWorkflow是opensymphony阻止开发的一个工作流引擎,OSWorkflow是用纯java语言编写的,并且开发源代码。
OSWorkflow适用于任何Java平台,为开发者提供了灵活的业务逻辑流程,并且在企业ERP开发中得到广泛应用。作者陈刚继翻译《OSWorkflow中文手册》之后,根据多年积累经验又撰写了《OSWorkflow开发指南》一书,帮助...
里面有个osworkflow各个概念的关系图很不错。 可以先看看osworkflow 中文手册
由OpensymPhony组织开发的开源工作流引擎 OSWorkflow是一种非常灵活的工作 流引擎。它主要基于有限状态机理论,通过状态的迁移描述工作的流转。每一种状态(state) 被描述成为 step ID和 status。从一种状态(state)...
OSWorkFlow demo 资料 OSWorkFlow demo 资料
用OSWorkFlow和JBPM开发工作流异同点解析