/**
   * Add a step
   *
   * @param descriptor The step descriptor to add
   * @throws IllegalArgumentException if the descriptor's ID already exists in the workflow
   */
  public void addStep(StepDescriptor descriptor) {
    if (getStep(descriptor.getId()) != null) {
      throw new IllegalArgumentException("Step with id " + descriptor.getId() + " already exists");
    }

    steps.add(descriptor);
  }
  public StepDescriptor getStep(int id) {
    for (Iterator iterator = steps.iterator(); iterator.hasNext(); ) {
      StepDescriptor step = (StepDescriptor) iterator.next();

      if (step.getId() == id) {
        return step;
      }
    }

    return null;
  }
  public void validate() throws InvalidWorkflowDescriptorException {
    ValidationHelper.validate(this.getRegisters());
    ValidationHelper.validate(this.getTriggerFunctions().values());
    ValidationHelper.validate(this.getGlobalActions());
    ValidationHelper.validate(this.getInitialActions());
    ValidationHelper.validate(this.getCommonActions().values());
    ValidationHelper.validate(this.getSteps());
    ValidationHelper.validate(this.getSplits());
    ValidationHelper.validate(this.getJoins());

    Set actions = new HashSet();
    Iterator i = globalActions.iterator();

    while (i.hasNext()) {
      ActionDescriptor action = (ActionDescriptor) i.next();
      actions.add(new Integer(action.getId()));
    }

    i = getSteps().iterator();

    while (i.hasNext()) {
      StepDescriptor step = (StepDescriptor) i.next();
      Iterator j = step.getActions().iterator();

      while (j.hasNext()) {
        ActionDescriptor action = (ActionDescriptor) j.next();

        // check to see if it's a common action (dups are ok, since that's the point of common
        // actions!)
        if (!action.isCommon()) {
          if (!actions.add(new Integer(action.getId()))) {
            throw new InvalidWorkflowDescriptorException(
                "Duplicate occurance of action ID "
                    + action.getId()
                    + " found in step "
                    + step.getId());
          }
        }
      }
    }

    // now we have all our unique actions, let's check that no common action id's exist in them
    i = commonActions.keySet().iterator();

    while (i.hasNext()) {
      Integer action = (Integer) i.next();

      if (actions.contains(action)) {
        throw new InvalidWorkflowDescriptorException(
            "common-action ID " + action + " is duplicated in a step action");
      }
    }

    i = initialActions.iterator();

    while (i.hasNext()) {
      ActionDescriptor action = (ActionDescriptor) i.next();

      if (actions.contains(new Integer(action.getId()))) {
        throw new InvalidWorkflowDescriptorException(
            "initial-action ID " + action + " is duplicated in a step action");
      }
    }

    validateDTD();
  }