@Test public void shouldInvokeTypedVisitors() { final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process") .startEvent("start-1") .userTask("user-1") .endEvent("end-1") .done(); final List<FlowNode> flowNodes = new ArrayList<>(); final List<UserTask> userTasks = new ArrayList<>(); final TypeHierarchyVisitor compositeVisitor = new TypeHierarchyVisitor() { @Override protected void visit( final ModelElementType implementedType, final BpmnModelElementInstance instance) { if (implementedType.getInstanceType() == UserTask.class) { userTasks.add((UserTask) instance); } if (implementedType.getInstanceType() == FlowNode.class) { flowNodes.add((FlowNode) instance); } } }; final ModelWalker walker = new ModelWalker(modelInstance); walker.walk(compositeVisitor); assertThat(flowNodes).extracting(f -> f.getId()).containsOnly("start-1", "user-1", "end-1"); assertThat(userTasks).extracting(f -> f.getId()).containsOnly("user-1"); }
public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } ModelWalker(final BpmnModelInstance modelInstance); }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } ModelWalker(final BpmnModelInstance modelInstance); void walk(final ModelElementVisitor visitor); }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } ModelWalker(final BpmnModelInstance modelInstance); void walk(final ModelElementVisitor visitor);  }