@Override
  public void validate(Definition definition) throws WorkflowException {
    State initialState = definition.getInitialState();

    if (initialState == null) {
      throw new WorkflowException("No initial state defined");
    }

    List<State> terminalStates = definition.getTerminalStates();

    if (terminalStates.isEmpty()) {
      throw new WorkflowException("No terminal states defined");
    }

    if (definition.getForksCount() != definition.getJoinsCount()) {
      throw new WorkflowException("There are unbalanced fork and join nodes");
    }

    Collection<Node> nodes = definition.getNodes();

    for (Node node : nodes) {
      NodeValidator<Node> nodeValidator =
          _nodeValidatorRegistry.getNodeValidator(node.getNodeType());

      nodeValidator.validate(definition, node);
    }
  }