@Test public void shouldVisitTypeHiearchyInOrder() { final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process") .startEvent("start-1") .userTask("user-1") .endEvent("end-1") .done(); final ModelWalker walker = new ModelWalker(modelInstance); final List<Class<?>> visitedUserTaskTypes = new ArrayList<>(); final TypeHierarchyVisitor visitor = new TypeHierarchyVisitor() { @Override protected void visit( final ModelElementType implementedType, final BpmnModelElementInstance instance) { if (instance instanceof UserTask) { visitedUserTaskTypes.add(implementedType.getInstanceType()); } } }; walker.walk(visitor); assertThat(visitedUserTaskTypes) .containsExactly( BaseElement.class, FlowElement.class, FlowNode.class, Activity.class, Task.class, UserTask.class); }
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);  }