After you imported your model you can search for elements by their id or by the type of element.
StartEvent start = (StartEvent) modelInstance.getModelElementById("start");
// find all elements of the type task
ModelElementType taskType = modelInstance.getModel().getType(Task.class);
Collection<ModelElementInstance> taskInstances = modelInstance.getModelElementsByType(taskType);
You can also access the child elements of an element or references to other elements. For example, a sequence flowreferences a source and a target element while a flow node (like start event, tasks, etc.) has child elementsfor incoming and outgoing sequence flows.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions targetNamespace="http://camunda.org/examples" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
<process id="process-with-one-task">
<startEvent id="start">
</startEvent>
<userTask id="task1">
<incoming>start-task1</incoming>
<outgoing>task1-end</outgoing>
</userTask>
<endEvent id="end">
<incoming>task1-end</incoming>
</endEvent>
<sequenceFlow id="start-task1" sourceRef="start" targetRef="task1"/>
</process>
</definitions>
You can now use the BPMN model API to get the source and target flow node of the sequence flow with the ID start-task1.
public Collection<FlowNode> getFlowingFlowNodes(FlowNode node) {
Collection<FlowNode> followingFlowNodes = new ArrayList<FlowNode>();
for (SequenceFlow sequenceFlow : node.getOutgoing()) {
followingFlowNodes.add(sequenceFlow.getTarget());
}
return followingFlowNodes;
}