activiti bpmnModel使用
bpmnModel对象,是activiti动态部署钟很重要的一个对象,如果bpmnModel对象不能深入的理解,那可能如果自己需要开发一套流程设计器,就显得力不从心,之前我们公司自己开发了一套activiti web设计器,如下图所示:
当activiti web设计器设计的时候,存储格式是自定义的json对象,那现在问题来了,我们怎么把我们自己的json格式转化为标准的bpmn需要的xml文件呢?这一点很重要?所以这也是本节课需要重点讲解的地方,大家实际开发可以举一反三。灵活的运用到项目中。
1.1.1. BpmnModel使用
因为平时我们在使用的时候,展示流程图没有使用是默认的流程生成的这种方式,所以这里坐标信息,暂时不演示,主要演示节点等的核心功能。
1.1.1.1. eclipse绘制流程
为了方便演示,这里我们先在eclipse中绘制一个简单的流程。具体的流程图如下:
流程图的xml文件如下:直接用文本打开bpmn文件即可:
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> <process id="process1" isExecutable="true"> <startEvent id="start1shareniu" name="start1shareniu"></startEvent> <sequenceFlow id="starttouserTask" name="starttouserTask" sourceRef="start1shareniu" targetRef="userTask1shareniu"></sequenceFlow> <userTask id="userTask1shareniu" name="userTask1shareniu"></userTask> <sequenceFlow id="userTasktoend" name="userTasktoend" sourceRef="userTask1shareniu" targetRef="endEventshareniu"></sequenceFlow> <endEvent id="endEventshareniu" name="endEventshareniu"></endEvent> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_process1"> <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1"> <bpmndi:BPMNShape bpmnElement="start1shareniu" id="BPMNShape_start1shareniu"> <omgdc:Bounds height="35.0" width="35.0" x="70.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="userTask1shareniu" id="BPMNShape_userTask1shareniu"> <omgdc:Bounds height="60.0" width="100.0" x="180.0" y="110.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endEventshareniu" id="BPMNShape_endEventshareniu"> <omgdc:Bounds height="35.0" width="35.0" x="380.0" y="76.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="starttouserTask" id="BPMNEdge_starttouserTask"> <omgdi:waypoint x="87.0" y="150.0"></omgdi:waypoint> <omgdi:waypoint x="100.0" y="139.0"></omgdi:waypoint> <omgdi:waypoint x="180.0" y="140.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="87.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="userTasktoend" id="BPMNEdge_userTasktoend"> <omgdi:waypoint x="280.0" y="140.0"></omgdi:waypoint> <omgdi:waypoint x="324.0" y="129.0"></omgdi:waypoint> <omgdi:waypoint x="324.0" y="93.0"></omgdi:waypoint> <omgdi:waypoint x="380.0" y="93.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="414.0" y="126.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
1.1.1.2. 自己生成
下面的代码,就是生成这个bpmnmodel 核心代码,代码如下所示:
//实例化BpmnModel对象 BpmnModel bpmnModel=new BpmnModel(); //开始节点的属性 StartEvent startEvent=new StartEvent(); startEvent.setId("start1shareniu"); startEvent.setName("start1shareniu"); //普通的UserTask节点 UserTask userTask=new UserTask(); userTask.setId("userTask1shareniu"); userTask.setName("userTask1shareniu"); //结束节点属性 EndEvent endEvent=new EndEvent(); endEvent.setId("endEventshareniu"); endEvent.setName("endEventshareniu"); //连线信息 List<SequenceFlow> sequenceFlows=new ArrayList<SequenceFlow>(); List<SequenceFlow> toEnd=new ArrayList<SequenceFlow>(); SequenceFlow s1=new SequenceFlow(); s1.setId("starttouserTask"); s1.setName("starttouserTask"); s1.setSourceRef("start1shareniu"); s1.setTargetRef("userTask1shareniu"); sequenceFlows.add(s1); SequenceFlow s2=new SequenceFlow(); s2.setId("userTasktoend"); s2.setName("userTasktoend"); s2.setSourceRef("userTask1shareniu"); s2.setTargetRef("endEventshareniu"); toEnd.add(s2); startEvent.setOutgoingFlows(sequenceFlows); userTask.setOutgoingFlows(toEnd); userTask.setIncomingFlows(sequenceFlows); endEvent.setIncomingFlows(toEnd); //Process对象 Process process=new Process(); process.setId("process1"); process.addFlowElement(startEvent); process.addFlowElement(s1); process.addFlowElement(userTask); process.addFlowElement(s2); process.addFlowElement(endEvent); bpmnModel.addProcess(process);
上面的代码,我们已经写好了bpmnmodel绘制的流程,那我们怎么知道对还是不对呢?下面就开始将我们的bpmnmodel对象转化为标准的xml文件看一下。
1.1.2. BpmnModel转化xml
将上面的对象转化为标准的xml代码如下所示:
//bpmnModel 转换为标准的bpmn xml文件
BpmnXMLConverter bpmnXMLConverter=new BpmnXMLConverter();
byte[] convertToXML = bpmnXMLConverter.convertToXML(bpmnModel);
String bytes=new String(convertToXML);
System.out.println(bytes);
运行程序,看一下程序的输出如下:
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> <process id="process1" isExecutable="true"> <startEvent id="start1shareniu" name="start1shareniu"></startEvent> <sequenceFlow id="starttouserTask" name="starttouserTask" sourceRef="start1shareniu" targetRef="userTask1shareniu"></sequenceFlow> <userTask id="userTask1shareniu" name="userTask1shareniu"></userTask> <sequenceFlow id="userTasktoend" name="userTasktoend" sourceRef="userTask1shareniu" targetRef="endEventshareniu"></sequenceFlow> <endEvent id="endEventshareniu" name="endEventshareniu"></endEvent> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_process1"> <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1"></bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
我们看到转化的xml文件,对比eclipse绘制流程的xml,除了坐标没有,其他的都是正确的。那我们怎么验证我们生成的xml是正确的呢?因为转化成功,也不一定可以使用的。接下来看一下bpmnmodel如何验证。
1.1.3. BpmnModel验证
验证的方法代码如下所示:
说明,bpmnmodel正确,大于0,说明自定义的bpmnmodel是错误的,不可以使用的。
验证还是很有必要使用的,因为流程部署的时候,我们最好验证一次,没有问题在部署。
分享牛,分享、我们是快乐的。
分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519)
activiti bpmnModel使用的更多相关文章
- 流程开发Activiti 与SpringMVC整合实例
流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...
- activiti当前任务高亮(解决乱码问题)
package com.xinwei; import java.io.File; import java.io.InputStream; import java.util.ArrayList; imp ...
- Spring Boot整合Activiti,查看流程图出现中文乱码问题
最近研究SpringBoot 整合Activiti时,实现流程图高亮追踪是出现中文乱码问题,找了很多方法,现在把我最后的解决方法提供给大家. Spring Boot是微服务快速开发框架,强调的是零配置 ...
- 解决ACTIVITI流程图设置字体不生效的问题
在ACTIVITI 5.15的版本中,有一个设置流程图的字体配置. 配置如下: <bean id="processEngineConfiguration" class=&qu ...
- activiti自定义流程之整合(四):整合自定义表单部署流程定义
综合前几篇博文内容,我想在整合这一部分中应该会有很多模块会跳过不讲,就如自定义表单的表单列表那一块,因为这些模块在整合的过程中都几乎没有什么改动,再多讲也是重复无用功. 正因为如此,在创建了流程模型之 ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(六):启动流程
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti搭建(四)八项服务介绍
转载请注明源地址:http://www.cnblogs.com/lighten/p/5927949.html 1.前言 之前学习的时候一直在其它文章看到activiti提供了七个接口来操作工作流,但在 ...
- modeler与activiti进行整合
整合Activiti Modeler到业务系统(或BPM平台) http://www.kafeitu.me/activiti/2013/03/10/integrate-activiti-modeler ...
随机推荐
- mybatis学习一
1:ORM概念 ORM(OBJECT-RELATIONSHIP MAPPING) 即对象关系映射,是一种思想,实质是将数据库中的数据用对象的形式表现出来 JPA(JAVA PERSISIT ...
- [NOIp 2009]靶形数独
Description 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向 Z 博士请教,Z 博士拿出了他 ...
- [NOIp 2014]联合权值
Description 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v ...
- [NOI2009]变换序列
Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50: 60%的数据中N ...
- ●BZOJ 3270 博物馆
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3270题解: 期望DP,高斯消元 本来是定义的关于概率的dp, 但是发现这样定义有很多解释不通 ...
- ●UOJ 21 缩进优化
题链: http://uoj.ac/problem/21 题解: ...技巧题吧 先看看题目让求什么: 令$F(x)=\sum_{i=1}^{n}(\lfloor a[i]/x \rfloor +a[ ...
- Luogu1613 跑路
题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零.可是小A偏偏又有赖床的坏毛病.于是为了保住自己的工资,小A买了一个十分牛B的空间跑路器,每秒钟 ...
- URAL 1297 最长回文子串(后缀数组)
1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...
- WiFi天线分集
0 概述 在调试一款古董级射频芯片时,发现它支持1发2收,由于在画板工程师将辅助天线也整出来.等板子贴出来后,就与同事一起折腾这个分集接收功能. 碰到过如下问题,先记录,以便后期有空再继续. 1)发现 ...
- redis启动失败
redis.conf 设置的daemonize yes后台运行,使用redis-server redis.conf之后没有任何反应,以为启动成功 使用 ps -ef|grep redis 查看redi ...