public ActionDescriptor getAction(int id) {
    // check global actions
    for (Iterator iterator = globalActions.iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

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

    // check steps
    for (Iterator iterator = steps.iterator(); iterator.hasNext(); ) {
      StepDescriptor stepDescriptor = (StepDescriptor) iterator.next();
      ActionDescriptor actionDescriptor = stepDescriptor.getAction(id);

      if (actionDescriptor != null) {
        return actionDescriptor;
      }
    }

    // check initial actions, which we now must have unique id's
    for (Iterator iterator = initialActions.iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

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

    return null;
  }
  /**
   * Remove an action from this workflow completely.
   *
   * <p>This method will check global actions and all steps.
   *
   * @return true if the action was successfully removed, false if it was not found
   */
  public boolean removeAction(ActionDescriptor actionToRemove) {
    // global actions
    for (Iterator iterator = getGlobalActions().iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

      if (actionDescriptor.getId() == actionToRemove.getId()) {
        getGlobalActions().remove(actionDescriptor);

        return true;
      }
    }

    // steps
    for (Iterator iterator = getSteps().iterator(); iterator.hasNext(); ) {
      StepDescriptor stepDescriptor = (StepDescriptor) iterator.next();
      ActionDescriptor actionDescriptor = stepDescriptor.getAction(actionToRemove.getId());

      if (actionDescriptor != null) {
        stepDescriptor.getActions().remove(actionDescriptor);

        return true;
      }
    }

    return false;
  }
  // refactored this out from the three addAction methods above
  private void addAction(Object actionsCollectionOrMap, ActionDescriptor descriptor) {
    if (getAction(descriptor.getId()) != null) {
      throw new IllegalArgumentException(
          "action with id " + descriptor.getId() + " already exists for this step.");
    }

    if (actionsCollectionOrMap instanceof Map) {
      ((Map) actionsCollectionOrMap).put(new Integer(descriptor.getId()), descriptor);
    } else {
      ((Collection) actionsCollectionOrMap).add(descriptor);
    }
  }
  public ActionDescriptor getInitialAction(int id) {
    for (Iterator iterator = initialActions.iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

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

    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();
  }