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 ...
随机推荐
- Python获取会议部分的信息内容(不断完善中)
这是一个用于获取物理师会议报告的简单爬虫,数据库表结构正在不断完善中 爬虫信息: # -*- coding:utf-8 -*- import urllib.request import pymysql ...
- [Luogu 2265]路边的水沟
Description LYQ市有一个巨大的水沟网络,可以近似看成一个n*m的矩形网格,网格的每个格点都安装了闸门,我们将从水沟网络右下角的闸门到左上角的闸门的一条路径称为水流. 现给定水沟网的长和宽 ...
- [WC2006]水管局长数据加强版
Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公司找到一 ...
- UVALive - 3942:Remember the Word
发现字典里面的单词数目多且长度短,可以用字典树保存 f[i]表示s[i~L]的分割方式,则有f[i]=∑f[i+len(word[j])] 其中word[j]为s[i~L]的前缀 注意字典树又叫前 ...
- UVA11552:Fewest Flops
发现如果只有一块就是种类的数目,也就是同种放在一起, 再考虑多块,如果违背的上面的规律,可以发现不会更优, 于是问题就是求在满足同种类放在一起的前提下,尽量使得相邻块的两端一模一样 然后dp一下就可以 ...
- ●POJ 1228 Grandpas Estate
题链: http://poj.org/problem?id=1228 题解: 计算几何,凸包 题意:给出一些点,求出其凸包,问是否是一个稳定的凸包. 稳定凸包:不能通过新加点使得原来凸包上的点(包括原 ...
- ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net
●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...
- bzoj1043[HAOI2008]下落的圆盘 计算几何
1043: [HAOI2008]下落的圆盘 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1598 Solved: 676[Submit][Stat ...
- String.IndexOf 方法笔记
记录以备使用 作用:报告指定 Unicode 字符或字符串在此实例中的第一个匹配项的从零开始的索引. 如果未在此实例中找到该字符或字符串,则此方法返回 -1. 重载列表 名称 说明 IndexOf ...
- 用js来实现那些数据结构12(散列表)
上一篇写了如何实现简单的Map结构,因为东西太少了不让上首页.好吧... 这一篇文章说一下散列表hashMap的实现.那么为什么要使用hashMap?hashMap又有什么优势呢?hashMap是如何 ...