コード例 #1
0
  /*
   * (non-Javadoc)
   *
   * @see com.webobjects.eocontrol.EOCustomObject#validateForUpdate()
   */
  public void validateForUpdate() throws ValidationException {
    RuleContext validationContext = validatingEditingContext().validationContext();

    validationContext.takeValueForKey(ValidatingRecord.UPDATE_VALUE, ValidatingRecord.TASK_KEY);

    try {
      super.validateForUpdate();
    } finally {
      validationContext.takeValueForKey(null, ValidatingRecord.TASK_KEY);
    }
  }
コード例 #2
0
  /*
   * (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);
    }
  }