com.holonplatform.core

## Class Validator.ValidationException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - com.holonplatform.core.Validator.ValidationException

- All Implemented Interfaces:
    Localizable, Serializable
  Enclosing interface:
    Validator<T>

      public static class Validator.ValidationException
      extends RuntimeException
      implements Localizable

  Exception used to notify validation errors using `Validator.validate(Object)`.

  This exception is `Localizable`, providing optional message code and arguments for validation message localization.

  ValidationException may act as a wrapper for multiple validation errors, accessible through `getCauses()` method.

  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.holonplatform.core.i18n.Localizable

      `Localizable.Builder<B extends Localizable.Builder<B>>, Localizable.LocalizableBuilder, Localizable.LocalizationException`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ValidationException(Localizable message)` Constructor with `Localizable` message
    `ValidationException(String message)` Constructor with message
    `ValidationException(String message, String messageCode, Object... messageArguments)` Constructor with localized message
    `ValidationException(Validator.ValidationException... causes)` Constructor with causes

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Validator.ValidationException[]` | `getCauses()` Get the `Validator.ValidationException`s that caused this exception.
    `List<String>` | `getLocalizedValidationMessages()` Get all the localized validation error messages carried by this validation exception.
    `Object[]` | `getMessageArguments()` Optional arguments to use for message localization.
    `String` | `getMessageCode()` Get the message code to use to obtain a localized message
    `List<Localizable>` | `getValidationMessages()` Get all the validation error messages carried by this validation exception.
    `void` | `setCauses(Validator.ValidationException[] causes)` Set the `Validator.ValidationException`s that caused this exception

    - ### Methods inherited from class java.lang.Throwable

      `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface com.holonplatform.core.i18n.Localizable

      `builder, getMessage`

- - ### Constructor Detail

    - #### ValidationException

          public ValidationException(String message)

      Constructor with message
      Parameters:
        `message` - Validation error message

    - #### ValidationException

          public ValidationException(String message,
                                     String messageCode,
                                     Object... messageArguments)

      Constructor with localized message
      Parameters:
        `message` - Default validation error message
        `messageCode` - Validation error message code
        `messageArguments` - Optional message localization arguments

    - #### ValidationException

          public ValidationException(Localizable message)

      Constructor with `Localizable` message
      Parameters:
        `message` - Validation error message (not null)

    - #### ValidationException

          public ValidationException(Validator.ValidationException... causes)

      Constructor with causes
      Parameters:
        `causes` - One or more `Validator.ValidationException`s that caused this exception

  - ### Method Detail

    - #### getMessageCode

          public String getMessageCode()

      Description copied from interface: `Localizable`
      Get the message code to use to obtain a localized message
      Specified by:
        `getMessageCode` in interface `Localizable`
      Returns:
        Message code

    - #### getMessageArguments

          public Object[] getMessageArguments()

      Description copied from interface: `Localizable`
      Optional arguments to use for message localization.

      By default this method returns `null`. Override it to provide message localization arguments.

      Arguments resolution process is dependend from concrete localization handler. For example, a predefined argument placeholder character may be used to define arguments substitution positions within the localized message.

      Specified by:
        `getMessageArguments` in interface `Localizable`
      Returns:
        Message localization arguments, or `null` if none

    - #### getCauses

          public Validator.ValidationException[] getCauses()

      Get the `Validator.ValidationException`s that caused this exception.
      Returns:
        Array of causes, `null` if none

    - #### setCauses

          public void setCauses(Validator.ValidationException[] causes)

      Set the `Validator.ValidationException`s that caused this exception
      Parameters:
        `causes` - the causes to set

    - #### getValidationMessages

          public List<Localizable> getValidationMessages()

      Get all the validation error messages carried by this validation exception.
      Returns:
        A list of validation error messages which correspond to inner validation exceptions, if any, or a list with only one element which corresponds to the validation exception itself.

    - #### getLocalizedValidationMessages

          public List<String> getLocalizedValidationMessages()

      Get all the localized validation error messages carried by this validation exception.

      For successfull localization, a `LocalizationContext` must be available as context resource using `LocalizationContext.getCurrent()` and must be localized.

      Returns:
        A list of validation error messages which correspond to inner validation exceptions, if any, or a list with only one element which corresponds to the validation exception itself.

Copyright © 2017 The Holon Platform. All rights reserved.