Bpmn 2.0 Parser

951 views
Skip to first unread message

Edgar Zamora-Gómez

unread,
Oct 7, 2014, 1:42:22 PM10/7/14
to camunda-...@googlegroups.com

Hello!! 

After search in google for a lot of time, I'm think that the best option is to ask to you :D
I'm trying to parse a bpmn 2.0 to extract the all extensions elements. But I didn't obtain any result.

Using this two lines of code, I had obtain the all bpmn2.0 xml in String format:

BpmnModelInstance modelInstance = Bpmn.readModelFromStream(fileStream)
String xmlBpmn = Bpmn.convertToString(modelInstance)

But, at this point I don't know how continue.  I'm trying:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance()
 
DocumentBuilder db = dbf.newDocumentBuilder()
 
ByteArrayInputStream bin = new ByteArrayInputStream(xmlBpmn.getBytes("utf-8")) 
InputSource ins = new InputSource(new StringReader(xmlBpmn))
 
Document doc = db.parse(ins)

And I think that using it, I can obtain the elements from document, but the document has null element root. After this test, I try to parser using the camunda parser:

import org.camunda.bpm.engine.impl.util.xml.Parser

From this parser I find the api documentation, but I don't know how it works. I think that it works the saxParser, but I didn't find any example.

So please, can you help me or give me an example that demonstrate how to implement this parser.

For example if you have this bpmn 2.0, how can obtain the camunda form data, using a parser. Or other element, it's only to see an example. 
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://activiti.org/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_Qr4CsJjdEeOi2_UbKTmDjw" exporter="camunda modeler" exporterVersion="2.6.0" targetNamespace="http://activiti.org/bpmn">
  <bpmn2:process id="SimpleProcess14" name="SimpleProcess14" isExecutable="true">
    <bpmn2:startEvent id="StartEvent_1" name="StartEvent">
      <bpmn2:extensionElements>
        <camunda:formData>
          <camunda:formField id="name" label="Name" type="string"/>
          <camunda:formField id="age" label="Age" type="long" defaultValue="30"/>
 <camunda:formField id="task" label="Task" type="string" defaultValue="hit toda"/>
        </camunda:formData>
      </bpmn2:extensionElements>
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="StartEvent_1" targetRef="UserTask_1"/>
    <bpmn2:endEvent id="EndEvent_1" name="EndEvent">
      <bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:userTask id="UserTask_1" name="user_task">
      <bpmn2:extensionElements>
        <camunda:formData>
          <camunda:formField id="age" type="long" defaultValue="30"/>
          <camunda:formField id="name" type="string" defaultValue="pepito"/>
          <camunda:formField id="marica" type="boolean" defaultValue="True"/>
        </camunda:formData>
      </bpmn2:extensionElements>
      <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
    </bpmn2:userTask>
    <bpmn2:sequenceFlow id="SequenceFlow_4" name="" sourceRef="UserTask_1" targetRef="EndEvent_1"/>
  </bpmn2:process>


Thx!!!

Sebastian Menski

unread,
Oct 7, 2014, 4:56:02 PM10/7/14
to camunda-...@googlegroups.com
Hi Edgar,

nice to hear that you think camunda is the best option. ;)

I just created a small example [1] in our examples repository on GitHub to demonstrate some features of the BPMN model API to parse
BPMN. So please have a look at source code of the unit test [2] and hopefully that helps you to get started.

Also please ask further question if something is not clear or regarding your own use case.

Cheers,
Sebastian

Reply all
Reply to author
Forward
0 new messages