jbpm4源码深入分析罗创锋

jbpm4源码深入分析
JBPM4源码分析---Configuration hibernate主键生成策略--native(文档不满)
JBPM源码分析---EnvironmentJBPM 2010-04-26 11:30:05 阅读105 评论7 字号:大中小 订阅
Environment是jbpm运行期环境,他提供了jbpm的所有的服务(Service),我们通常会使用EnvironmentFactory的openEnvironment()方法来获取Environment,而jbpm的Environment用到了Threadlocal模式,他是这样定义的:

static ThreadLocal<Environment> currentEnvironment = new ThreadLocal<Environment>();

static ThreadLocal<Stack<Environment>> currentEnvironmentStack = new ThreadLocal<Stack<Environment>>();
其中currentEnvironment 是当前的运行期环境,而currentEnvironmentStack 则提供了一个栈,可以压入多个Environment。

public static Environment getCurrent() {
return currentEnvironment.get();

//用来获取当前的Environment 。
}

其中主要的方法是用来获取服务的:

public abstract Object get(String name);

public abstract <T> T get(Class<T> type);



上一次说到了Configuration,默认的构造实际上获取的是JbpmConfiguration,而这个JbpmConfiguration便实现了EnvironmentFactory接口,当JbpmConfiguration加载jbpm.default.cfg.xml配置文件的时候,他会将其中的<process-engine-context>和<transaction-context>初始化好,注入到environment中,就可以用来获取各种服务类了。



JBPM4源码分析---ConfigurationJBPM 2010-04-26 10:00:42 阅读172 评论0 字号:大中小 订阅
在jBPM内部是通过各种服务相互作用, 服务接口可以从ProcessEngine中获得, 所有线程和请求都可以使用同一个流程引擎对象,而ProcessEngine是由Configuration创建的.通常我们使用默认的构造进行创建:

ProcessEngine processEngine = new Configuration().buildProcessEngine(); /** default constructor */ public Configuration() { this((String)null); }这个默认构造中的this((String)null)实际上调用的是另一个带String type 参数的构造方法,方式如下:public Configuration(String type) { String implementationClassName = getImplementationClassName(type); if (implementationClassName==null) { throw new JbpmException("type is null"); } impl = instantiate(implementationClassName); }而在getImplementationClassName方法中,JBPM把Configuration实现类implementationClassName设置为一个Map,它实现了2种Configuration: implementationClassNames.put(null, "org.jbpm.pvm.internal.cfg.JbpmConfiguration"); implementationClassNames.put("spring-test", "org.jbpm.pvm.internal.cfg.SpringConfiguration"); 所以说我们通常使用的默认构造实际上是创建的org.jbpm.pvm.internal.cfg.JbpmConfiguration在JbpmConfiguration中,他继承了Configuration,实现了Context, ProcessEngine, EnvironmentFactory等接口,这个类中主要的方法就是buildProcessEngine和一些setX(),分别用来创建流程引擎和从InputStream中、 从xml字符串中、从InputSource中、 从URL中或者从文件(File)中指定配置


请问一下,jbpm中的流程定义xml文件是如何存储到数据库中的? 该问题已经关闭: 超过15天由系统自动关闭,悬赏平分给所有参与回答的会员
问题答案可能在这里 → 寻找更多解答

* 重新看待jbpm的流程定义
* jBPM工作流应用
* jBPM3.2.2源码分析---org.jbpm.db*
* jbpm读取流程定义文件异常
* 请问下有没有jbpm3.2高手在?请教几个问题

回答
总体过程:读取XML文件->从文件中提取所有Node,Task,Transition等并设置到对应的Domain Object中->持久化到数据库
详细过程(代码):
Java代码

1. ProcessDefinition解析流程定义文件相关方法
2. public static ProcessDefinition parseXmlString(String xml);
3. public static ProcessDefinition parseXmlInputStream(InputStream inputStream);
4. public static ProcessDefinition parseXmlReader(Reader reader);
5. ..........................................
6. ..........................................

ProcessDefinition解析流程定义文件相关方法
public static ProcessDefinition parseXmlString(String xml);
public static ProcessDefinition parseXmlInputStream(InputStream inputStream);
public static ProcessDefinition parseXmlReader(Reader reader);
..........................................
..........................................


以上所有方法其实最终都会转化为对JpdlXmlReader对象的readProcessDefinition方法的调用,
Java代码

1. readProcessDefinition()方法具体实现
2.
3. // 创建一个新的流程定义对象
4. processDefinition = ProcessDefinition.createNewProcessDefinition();
5.
6. // 初始化包含的各种列表
7. problems = new ArrayList();
8. unresolvedTransitionDestinations = new ArrayList();
9. unresolvedActionReferences = new ArrayList();
10.
11. try {
12. //把流程定义文档读到内存DOM树中
13. Document document = JpdlParser.parse(inputSource, this);
14. Element root = document.getRootElement();
15.
16. // 读取流程名称
17. parseProcessDefinitionAttributes(root);
18.
19. // 读取流程描述
20. String description = root.elementTextTrim("description");
21. if (description!=null) {
22. processDefinition.setDescription(description);
23. }
24.
25. // 一次加工:读取流程中各种信息
26. readSwimlanes(root);//读取所有泳道
27. readActions(root, null, null);//读取所有Action
28. readNodes(root, processDefinition);//读取所有node
29. readEvents(root, processDefinition);//读取所有event
30. readExceptionHandlers(root, processDefinition);//读取所有异常处理器
31. readTasks(root, null);//读取所有任务
32.
33. // 二次加工:处理各种Transition和Action的引用
34. resolveTransitionDestinations();
35. resolveActionReferences();
36. verifySwimlaneAssignments();//确认泳道的分配策略
37.
38. } catch (Exception e) {
39. log.error("couldn't parse process definition", e);
40. addProblem(new Problem(Problem.LEVEL_ERROR, "couldn't parse process definition", e));
41. }
42.
43. if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR)) {
44. throw new JpdlException(problems);
45. }
46.
47. if (problems!=null) {
48. Iterator iter = problems.iterator();
49. while (iter.hasNext()) {
50. Problem problem = (Problem) iter.next();
51. log.warn("process parse warning: "+problem.getDescription());
52. }
53. }
54.
55. return processDefinition;//返回processDefinition对象,已经完全把xml中定义的流程转化为java中的对象,xml中的各种tag都已经转换为JBPM中的相关图形对象POJO并包含在ProcessDefinition的所包含的各种列表中
56.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值