private void addStartState() {
   builder
       .createActivity("start")
       .initial()
       .behavior(behaviorFactory.startBehavior())
       .transition(genNextActivityId())
       .endActivity();
 }
 @Override
 public void addService(
     String name,
     String id,
     List<ServiceParam> parameters,
     List<Output> output,
     List<TaskErrorReasonType> errorsToIgnore) {
   addActivity(
       behaviorFactory.serviceBehaviorInstance(
           name, id, parameters, output, registry, errorsToIgnore));
 }
  @Override
  public void addParallel(List<ExecutionFlow> threads) {
    if (threads.size() >= 2) {
      String forkActivityId = popCurrentId();
      String joinActivityId = "join-" + popCurrentId();

      // split executions with fork
      String[] flowIds =
          splitExecution(
              forkActivityId, behaviorFactory.forkBehaviorInstance(), threads.size(), null);
      addFlows(flowIds, threads, joinActivityId);

      // add join
      builder
          .createActivity(joinActivityId)
          .behavior(behaviorFactory.joinBehaviorInstance())
          .transition(genNextActivityId())
          .endActivity();
    } else if (threads.size() == 1) {
      addFlow(threads.get(0));
    }
  }
  private void addFlows(String[] flowIds, List<ExecutionFlow> flows, String endingActivityId) {
    for (int i = 0; i < flowIds.length; i++) {
      nextActivityId = flowIds[i];
      addFlow(flows.get(i));

      // end the flow
      builder
          .createActivity(nextActivityId)
          .behavior(behaviorFactory.emptyBehaviorInstance())
          .transition(endingActivityId)
          .endActivity();
    }
  }
  @Override
  public void addConditional(
      String condition, ExecutionFlow onTrueFlow, ExecutionFlow onFalseFlow) {
    String conditionStartActivityId = popCurrentId();
    String endingActivityId = "condition-end-" + popCurrentId();

    List<ExecutionFlow> flows = Arrays.asList(onTrueFlow, onFalseFlow);
    String[] flowIds =
        splitExecution(
            conditionStartActivityId,
            behaviorFactory.decisionBehaviorInstance(condition),
            flows.size(),
            Arrays.asList("onTrue", "onFalse"));
    addFlows(flowIds, flows, endingActivityId);

    nextActivityId = endingActivityId;
  }
 private void addProcessEndState() {
   builder
       .createActivity(nextActivityId)
       .behavior(behaviorFactory.waitBehavior(null))
       .endActivity();
 }
 @Override
 public void addScript(String scriptBody) {
   addActivity(behaviorFactory.scriptBehavior(scriptBody));
 }
 @Override
 public void addWait(String expression) {
   addActivity(behaviorFactory.waitBehavior(expression));
 }