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(Collection<Validator.ValidationException> causes)` Constructor with causes.
    `ValidationException(Localizable message)` Constructor with `Localizable` message
    `ValidationException(Localizable message, Collection<Validator.ValidationException> causes)` Constructor with message and causes.
    `ValidationException(Localizable message, Validator.ValidationException... causes)` Constructor with message and causes.
    `ValidationException(String message)` Constructor with message
    `ValidationException(String message, Collection<Validator.ValidationException> causes)` Constructor with message and causes.
    `ValidationException(String message, String messageCode, Object... messageArguments)` Constructor with localized message
    `ValidationException(String message, Validator.ValidationException... causes)` Constructor with message and causes.
    `ValidationException(Validator.ValidationException... causes)` Constructor with causes.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<Validator.ValidationException>` | `getCauses()` Get the `Validator.ValidationException`s that caused this exception.
    `List<Localizable>` | `getCausesMessages()` Get all the validation error messages of the validation causes, if any.
    `Optional<Localizable>` | `getLocalizableMessage()` Get the exception localizable message, if available.
    `List<String>` | `getLocalizedCausesMessages()` Get all the localized validation error messages of the validation causes, if any.
    `String` | `getLocalizedMessage()`
    `String` | `getMessage()` Get the default message to use if a `Localizable.getMessageCode()` is not available or a localized message which corresponds to the message code cannot be found or no localization handler is available for message translation.
    `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.

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

      `addSuppressed, fillInStackTrace, getCause, 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, of, of`

- - ### 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

    - #### ValidationException

          public ValidationException(Validator.ValidationException... causes)

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

    - #### ValidationException

          public ValidationException(Collection<Validator.ValidationException> causes)

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

    - #### ValidationException

          public ValidationException(String message,
                                     Validator.ValidationException... causes)

      Constructor with message and causes.
      Parameters:
        `message` - The validation error message
        `causes` - One or more `Validator.ValidationException`s that caused this exception

    - #### ValidationException

          public ValidationException(String message,
                                     Collection<Validator.ValidationException> causes)

      Constructor with message and causes.
      Parameters:
        `message` - The validation error message
        `causes` - One or more `Validator.ValidationException`s that caused this exception

    - #### ValidationException

          public ValidationException(Localizable message,
                                     Validator.ValidationException... causes)

      Constructor with message and causes.
      Parameters:
        `message` - The validation error message
        `causes` - One or more `Validator.ValidationException`s that caused this exception

    - #### ValidationException

          public ValidationException(Localizable message,
                                     Collection<Validator.ValidationException> causes)

      Constructor with message and causes.
      Parameters:
        `message` - The validation error message
        `causes` - One or more `Validator.ValidationException`s that caused this exception

  - ### Method Detail

    - #### getLocalizableMessage

          public Optional<Localizable> getLocalizableMessage()

      Get the exception localizable message, if available.
      Returns:
        Optional exception localizable message

    - #### getMessage

          public String getMessage()

      Description copied from interface: `Localizable`
      Get the default message to use if a `Localizable.getMessageCode()` is not available or a localized message which corresponds to the message code cannot be found or no localization handler is available for message translation.
      Specified by:
        `getMessage` in interface `Localizable`
      Overrides:
        `getMessage` in class `Throwable`
      Returns:
        Default message

    - #### 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 Collection<Validator.ValidationException> getCauses()

      Get the `Validator.ValidationException`s that caused this exception.
      Returns:
        A collection of causes, empty if none

    - #### 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.

    - #### getCausesMessages

          public List<Localizable> getCausesMessages()

      Get all the validation error messages of the validation causes, if any.
      Returns:
        A list of validation error messages which correspond to inner validation exceptions, if any

    - #### getLocalizedCausesMessages

          public List<String> getLocalizedCausesMessages()

      Get all the localized validation error messages of the validation causes, if any.

      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

    - #### getLocalizedMessage

          public String getLocalizedMessage()

      Overrides:
        `getLocalizedMessage` in class `Throwable`

Copyright © 2019 The Holon Platform. All rights reserved.