After you imported your model you can search for elements by their id or by the type of element.

    1. StartEvent start = (StartEvent) modelInstance.getModelElementById("start");
    2. // find all elements of the type task
    3. ModelElementType taskType = modelInstance.getModel().getType(Task.class);
    4. 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.

    1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    2. <definitions targetNamespace="http://camunda.org/examples" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
    3. <process id="process-with-one-task">
    4. <startEvent id="start">
    5. </startEvent>
    6. <userTask id="task1">
    7. <incoming>start-task1</incoming>
    8. <outgoing>task1-end</outgoing>
    9. </userTask>
    10. <endEvent id="end">
    11. <incoming>task1-end</incoming>
    12. </endEvent>
    13. <sequenceFlow id="start-task1" sourceRef="start" targetRef="task1"/>
    14. </process>
    15. </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.

    1. public Collection<FlowNode> getFlowingFlowNodes(FlowNode node) {
    2. Collection<FlowNode> followingFlowNodes = new ArrayList<FlowNode>();
    3. for (SequenceFlow sequenceFlow : node.getOutgoing()) {
    4. followingFlowNodes.add(sequenceFlow.getTarget());
    5. }
    6. return followingFlowNodes;
    7. }