好吧,alpha1里头通过Configuration来建立流程引擎的方法被废弃了,我们重新开始。
这回的入口类是org.activiti.test.ProcessDeployer。
先说点题外话,这次的重构尽管给我的blog撰写带来了麻烦,但是设计思想绝对是优秀的。首先看原来alpha1版本中example中的各项test类都是采用的多重继承的方式,而在alpha3中使用了 ProcessDeployer 对象,这符合"优先使用组合而非继承"的设计原则。所以,牛人的代码也不是一开始就优美的,也是经过了多次重构之后,才变得精巧起来的。
切换回正题,首先我们看到的是 ProcessDeployer中的 deployProcessString方法
/**
* convenience method for deploying a string literal (XML) as a process
* definition. It will be deployed with the name
* <code>xmlString.bpmn20.xml</code>
* 方便地将XML文件名加上 .bpmn20.xml后缀发布 为流程定义
*/
public void deployProcessString(String xmlString) {
String resourceName = "xmlString." + BpmnDeployer.BPMN_RESOURCE_SUFFIX;//加 后缀
createDeployment().name(resourceName).addString(resourceName, xmlString).deploy();
}
很明显,所有的业务处理都在 createDeployment().name(resourceName).addString(resourceName, xmlString).deploy();这一句中,那么,首先是 createDeployment(), 望文生义,这个应该是实现发布管理器,看源码:
/**
* create a {@link DeploymentBuilder} that is aware of the test context. All
* deployments built this way in a test case will be automatically removed
* from the engine when the test method finishes.
* 在测试上下文中创建发布管理器。用这种方式在测试用例中创建的发布管理器会在测试方法执行完毕后被流程引擎自动移除
*/
public DeploymentBuilder createDeployment() {
final DeploymentBuilder builder = getProcessService().createDeployment();
return getDeploymentBuilderProxy(builder);
}
呃。。。什么,这只是测试用的?又是新东西。。那正式使用的在哪儿呢?
本文探讨了Activiti流程引擎从Alpha1到Alpha3版本的重构过程,特别是针对流程定义部署方式的变化。从多重继承转向组合使用ProcessDeployer对象进行流程定义部署,遵循了优先使用组合而非继承的原则。

53万+

被折叠的 条评论
为什么被折叠?



