本文整理汇总了Java中org.activiti.bpmn.converter.BpmnXMLConverter.convertToBpmnModel方法的典型用法代码示例。如果您正苦于以下问题:Java BpmnXMLConverter.convertToBpmnModel方法的具体用法?Java BpmnXMLConverter.convertToBpmnModel怎么用?Java BpmnXMLConverter.convertToBpmnModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.activiti.bpmn.converter.BpmnXMLConverter
的用法示例。
在下文中一共展示了BpmnXMLConverter.convertToBpmnModel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToModelTest
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
@Test
public void convertToModelTest() throws Exception {
BpmnModel bpmnModel = buildModel();
BpmnXMLConverter converter = new BpmnXMLConverter();
String xml = new String(converter.convertToXML(bpmnModel), "UTF-8");
byte[] bytes = xml.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(inputStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
bpmnModel = converter.convertToBpmnModel(xtr);
xml = new String(converter.convertToXML(bpmnModel), "UTF-8");
System.out.println(xml);
}
示例2: testXmlToBpmnModel
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 把XML转换成BpmnModel对象
* @throws Exception
*/
@Test
@Deployment(resources = "chapter6/dynamic-form/leave.bpmn")
public void testXmlToBpmnModel() throws Exception {
// 验证是否部署成功
long count = repositoryService.createProcessDefinitionQuery().count();
assertEquals(1, count);
// 根据流程定义获取XML资源文件流对象
/*ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult();
String resourceName = processDefinition.getResourceName();
InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);*/
// 从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();
assertEquals("leave", process.getId());
}
示例3: execute
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
public BpmnModel execute(CommandContext commandContext) {
if (processDefinitionId == null) {
throw new ActivitiIllegalArgumentException("processDefinitionId is null");
}
// Find the bpmn 2.0 xml resource name which is stored on the process definition
ProcessDefinitionEntity processDefinitionEntity = commandContext
.getProcessDefinitionEntityManager()
.findProcessDefinitionById(processDefinitionId);
if (processDefinitionEntity == null) {
throw new ActivitiObjectNotFoundException("Process definition does not exist: " + processDefinitionId, ProcessDefinitionEntity.class);
}
// Fetch the resource
String resourceName = processDefinitionEntity.getResourceName();
ResourceEntity resource = commandContext.getResourceEntityManager()
.findResourceByDeploymentIdAndResourceName(processDefinitionEntity.getDeploymentId(), resourceName);
if (resource == null) {
if (commandContext.getDeploymentEntityManager().findDeploymentById(processDefinitionEntity.getDeploymentId()) == null) {
throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: "
+ processDefinitionEntity.getDeploymentId(), Deployment.class);
} else {
throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName
+ "' in deployment '" + processDefinitionEntity.getDeploymentId() + "'", InputStream.class);
}
}
// Convert the bpmn 2.0 xml to a bpmn model
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
return bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false); // no need to validate schema, it was already validated on deploy
}
示例4: execute
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
public BpmnParse execute() {
try {
BpmnXMLConverter converter = new BpmnXMLConverter();
boolean enableSafeBpmnXml = false;
String encoding = null;
if (Context.getProcessEngineConfiguration() != null) {
enableSafeBpmnXml = Context.getProcessEngineConfiguration().isEnableSafeBpmnXml();
encoding = Context.getProcessEngineConfiguration().getXmlEncoding();
}
if (encoding != null) {
bpmnModel = converter.convertToBpmnModel(streamSource, true, enableSafeBpmnXml, encoding);
} else {
bpmnModel = converter.convertToBpmnModel(streamSource, true, enableSafeBpmnXml);
}
createImports();
createItemDefinitions();
createMessages();
createOperations();
transformProcessDefinitions();
} catch (Exception e) {
if (e instanceof ActivitiException) {
throw (ActivitiException) e;
} else {
throw new ActivitiException("Error parsing XML", e);
}
}
if (bpmnModel.getProblems().size() > 0) {
StringBuilder problemBuilder = new StringBuilder();
for (Problem error : bpmnModel.getProblems()) {
problemBuilder.append(error.toString());
problemBuilder.append("\n");
}
throw new ActivitiException("Errors while parsing:\n" + problemBuilder.toString());
}
return this;
}