private static List<SequenceFlow> findOutgoingFlows(ProcessDefinition pd, String from) { List<SequenceFlow> result = new ArrayList<>(); for (AbstractElement e : pd.getChildren()) { if (e instanceof SequenceFlow) { SequenceFlow f = (SequenceFlow) e; if (from.equals(f.getFrom())) { result.add(f); } } } return result; }
public ProcessDefinition(ProcessDefinition source, Map<String, String> attributes) { this(source.getId(), source.getChildren(), attributes); }
private static void indexOutgoingFlows0(ProcessDefinition pd, Map<String, List<SequenceFlow>> accumulator) { for (AbstractElement e : pd.getChildren()) { String id = e.getId(); List<SequenceFlow> l = findOutgoingFlows(pd, id); accumulator.put(id, ImmutableList.copyOf(l)); if (e instanceof ProcessDefinition) { indexOutgoingFlows0((ProcessDefinition) e, accumulator); } } }
private static ProcessDefinition findElementProcess0(ProcessDefinition pd, String id) { if (pd.hasChild(id)) { return pd; } for (AbstractElement e : pd.getChildren()) { if (e instanceof ProcessDefinition) { ProcessDefinition sub = findElementProcess0((ProcessDefinition) e, id); if (sub != null) { return sub; } } } return null; }
/** * Finds a (first) start event of the process. * * @param pd * @throws ExecutionException if process has no start events. */ public static StartEvent findStartEvent(ProcessDefinition pd) throws ExecutionException { for (AbstractElement e : pd.getChildren()) { if (e instanceof StartEvent) { return (StartEvent) e; } } throw new ExecutionException("Invalid process definition '%s': no start event defined", pd.getId()); }
private static void indexBoundaryEvents0(ProcessDefinition pd, Map<String, List<BoundaryEvent>> accumulator) { for (AbstractElement e : pd.getChildren()) { if (e instanceof ProcessDefinition) { indexBoundaryEvents0((ProcessDefinition) e, accumulator); } if (!(e instanceof BoundaryEvent)) { continue; } BoundaryEvent ev = (BoundaryEvent) e; if (ev.getAttachedToRef() == null) { continue; } List<BoundaryEvent> l = accumulator.computeIfAbsent(ev.getAttachedToRef(), k -> new ArrayList<>()); l.add(ev); } } }
/** * Finds all incoming flows for the specified element. * * @param pd * @param to * @throws ExecutionException if the element has no incoming flows.. */ public static List<SequenceFlow> findIncomingFlows(ProcessDefinition pd, String to) throws ExecutionException { List<SequenceFlow> result = new ArrayList<>(); ProcessDefinition sub = findElementProcess(pd, to); for (AbstractElement e : sub.getChildren()) { if (e instanceof SequenceFlow) { SequenceFlow f = (SequenceFlow) e; if (to.equals(f.getTo())) { result.add(f); } } } if (result.isEmpty()) { throw new ExecutionException("Invalid process definition '%s': no flows to '%s'", pd.getId(), to); } return result; }
private static void dump(StringBuilder b, ProcessDefinition pd, Map<String, SourceMap> sourceMaps, int level) { for (AbstractElement e : pd.getChildren()) { pad(b, level).append(e.getClass().getSimpleName()).append(" [").append(e.getId()).append("]");
private static void print(AbstractElement e, int level) { if (e instanceof SequenceFlow) { SequenceFlow f = (SequenceFlow) e; System.out.println(ident(level) + e.getClass() + ": id=" + e.getId() + " // " + f.getFrom() + " -> " + f.getTo() + " // " + f.getExpression()); } else { System.out.println(ident(level) + e.getClass() + ": id=" + e.getId()); } if (e instanceof ProcessDefinition) { ProcessDefinition pd = (ProcessDefinition) e; for (AbstractElement c : pd.getChildren()) { print(c, level + 1); } } }
public IndexedProcessDefinition(ProcessDefinition pd) { super(pd.getId(), pd.getChildren(), pd.getAttributes() != null ? pd.getAttributes() : Collections.emptyMap()); setName(pd.getName()); this.outgoingFlows = indexOutgoingFlows(); this.boundaryEvents = indexBoundaryEvents(); }