Skip to content

Instantly share code, notes, and snippets.

@henryyan
Created January 5, 2015 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryyan/0c807e7809257fac6f84 to your computer and use it in GitHub Desktop.
Save henryyan/0c807e7809257fac6f84 to your computer and use it in GitHub Desktop.
遍历流程文件的元素
// 从classpath中获取
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("chapter6/dynamic-form/leave.bpmn");
// 创建转换对象
BpmnXMLConverter converter = new BpmnXMLConverter();
// 创建XMLStreamReader读取XML资源
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(inputStream);
// 把XML转换成BpmnModel对象
BpmnModel bpmnModel = converter.convertToBpmnModel(reader);
// 验证BpmnModel对象不为空
assertNotNull(bpmnModel);
Process process = bpmnModel.getMainProcess();
Collection<FlowElement> flowElements = process.getFlowElements();
for (FlowElement flowElement : flowElements) {
System.out.println(flowElement);
}
@henryyan
Copy link
Author

henryyan commented Jan 5, 2015

// 查询流程定义对象
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult();

// 获取BpmnModel对象
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());

// 创建转换对象
BpmnXMLConverter converter = new BpmnXMLConverter();

// 验证BpmnModel对象不为空
Process process = bpmnModel.getMainProcess();
Collection<FlowElement> flowElements = process.getFlowElements();
for (FlowElement flowElement : flowElements) {
    System.out.println(flowElement);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment