activiti--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转化xml //将上面的对象转化为标准的xml代码如下所示: //bpmnModel 转换为标准的bpmn xml文件 BpmnXMLConverter bpmnXMLConverter=new BpmnXMLConverter(); byte[] convertToXML = bpmnXMLConverter.convertToXML(bpmnModel); String bytes=new String(convertToXML); System.out.println(bytes);
ProcessValidatorFactory processValidatorFactory=new ProcessValidatorFactory(); ProcessValidator defaultProcessValidator = processValidatorFactory.createDefaultProcessValidator(); //验证失败信息的封装ValidationError List<ValidationError> validate = defaultProcessValidator.validate(bpmnModel); System.out.println(validate.size()); //需要说明的是:ValidationError封装的是验证信息,如果size为0说明,bpmnmodel正确,大于0,说明自定义的bpmnmodel是错误的,不可以使用的。
标签:bpmnmodel,activiti,--,s2,s1,userTask,process,new,setId 来源: https://www.cnblogs.com/jentary/p/14005602.html