Bpmn和xml文件相互转化
package com.activit; import static org.junit.Assert.assertEquals; import java.io.InputStream; import javax.xml.stream.XMLInputFactory; import org.activiti.bpmn.converter.BpmnXMLConverter; public class BpmnTest { /** * 加载配置文件 */ @Before public void init() { processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml") .buildProcessEngine(); repositoryService = processEngine.getRepositoryService(); runtimeService = processEngine.getRuntimeService(); taskService = processEngine.getTaskService(); } @Test @Deployment(resources="resources/diagrams/VacationRequest.bpmn") public void testXmltoBpmn() throws XMLStreamException{ ProcessDefinition processDefinition =repositoryService.createProcessDefinitionQuery().processDefinitionKey("vacationRequest").singleResult(); //获取流程资源的名称 String sourceName = processDefinition.getResourceName(); //获取流程资源 InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getId(),sourceName); //创建转换对象 BpmnXMLConverter converter = new BpmnXMLConverter(); //读取xml文件 XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(inputStream); //将xml文件转换成BpmnModel BpmnModel bpmnModel = converter.convertToBpmnModel((XMLStreamReader) reader); //验证bpmnModel是否为空 assertNotNull(bpmnModel); org.activiti.bpmn.model.Process process = bpmnModel.getMainProcess(); //验证转换的流程id assertEquals("leave",process.getId()); } } 还有一种更加简便的方法xml 格式直接自动生成bpmn文件。 新建文件: bpmn20.xml文件结尾的 activiti模型。然后copy得到的xml文件,最后open with 用activiti专用的视图打开就可以了。(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |