/*
   * (non-Javadoc)
   *
   * @see com.webobjects.eocontrol.EOCustomObject#validateValueForKey(java.lang.Object,
   *      java.lang.String)
   */
  public Object validateValueForKey(Object value, String key) throws ValidationException {
    Object validatedValue = value;

    EOClassDescription classDescription = classDescription();

    if (classDescription instanceof ValidatingClassDescription) {
      ValidatingClassDescription vClassDescription = (ValidatingClassDescription) classDescription;

      validatedValue = vClassDescription.validateValueForKey(this, validatedValue, key);
    }

    validatedValue = super.validateValueForKey(validatedValue, key);

    return validatedValue;
  }
  /*
   * (non-Javadoc)
   *
   * @see com.webobjects.eocontrol.EOCustomObject#validateForSave()
   */
  public void validateForSave() throws ValidationException {
    NSMutableArray validationExceptions = new NSMutableArray();
    RuleContext validationContext = validatingEditingContext().validationContext();
    boolean didSetTask = false;

    if (validationContext.valueForKey(ValidatingRecord.TASK_KEY) == null) {
      didSetTask = true;

      validationContext.takeValueForKey(ValidatingRecord.SAVE_VALUE, ValidatingRecord.TASK_KEY);
    }

    validationContext.takeValueForKey(entityName(), ValidatingRecord.ENTITY_NAME_KEY);

    try {
      super.validateForSave();
    } catch (NSValidation.ValidationException ve) {
      validationExceptions.addObject(ve);
    }

    EOClassDescription classDescription = classDescription();

    if (classDescription instanceof ValidatingClassDescription) {
      try {
        ValidatingClassDescription vClassDescription =
            (ValidatingClassDescription) classDescription;

        vClassDescription.validateAdditionalKeys(this);
      } catch (NSValidation.ValidationException ve) {
        validationExceptions.addObject(ve);
      }
    }
    if (didSetTask) {
      validationContext.takeValueForKey(null, ValidatingRecord.TASK_KEY);
    }

    validationContext.takeValueForKey(null, ValidatingRecord.ENTITY_NAME_KEY);

    int vCount = validationExceptions.count();

    if (vCount == 1) {
      throw (NSValidation.ValidationException) validationExceptions.objectAtIndex(0);
    } else if (vCount > 1) {
      throw NSValidation.ValidationException.aggregateExceptionWithExceptions(validationExceptions);
    }
  }