org.qi4j.api.constraint

## Class ConstraintViolationException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - java.lang.IllegalArgumentException
        - - org.qi4j.api.constraint.ConstraintViolationException

- All Implemented Interfaces:
    Serializable

      public class ConstraintViolationException
      extends IllegalArgumentException

  This Exception is thrown when there is one or more Constraint Violations in a method call.

  The Constraint Violations are aggregated per method, and this exception will contain those violations, together with the Composite instance it happened on as well as the Method that was invoked. The Exception also has support for localized messages of these violations.

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstraintViolationException(Composite instance, Member method, Collection<ConstraintViolation> constraintViolations)`
    `ConstraintViolationException(String instanceToString, Iterable<Class<?>> instanceTypes, Member method, Collection<ConstraintViolation> violations)`
    `ConstraintViolationException(String instanceToString, Iterable<Class<?>> instanceTypes, String mixinTypeName, String methodName, Collection<ConstraintViolation> violations)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<ConstraintViolation>` | `constraintViolations()`
    `String` | `getLocalizedMessage()`
    `String` | `getMessage()`
    `String` | `localizedMessage()`
    `String[]` | `localizedMessagesFrom(ResourceBundle bundle)` Creates localized messages of all the constraint violations that has occured.
    `String` | `methodName()`
    `String` | `mixinTypeName()`

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

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

- - ### Constructor Detail

    - #### ConstraintViolationException

          public ConstraintViolationException(Composite instance,
                                      Member method,
                                      Collection<ConstraintViolation> constraintViolations)

    - #### ConstraintViolationException

          public ConstraintViolationException(String instanceToString,
                                      Iterable<Class<?>> instanceTypes,
                                      Member method,
                                      Collection<ConstraintViolation> violations)

    - #### ConstraintViolationException

          public ConstraintViolationException(String instanceToString,
                                      Iterable<Class<?>> instanceTypes,
                                      String mixinTypeName,
                                      String methodName,
                                      Collection<ConstraintViolation> violations)

  - ### Method Detail

    - #### constraintViolations

          public Collection<ConstraintViolation> constraintViolations()

    - #### localizedMessagesFrom

          public String[] localizedMessagesFrom(ResourceBundle bundle)

      Creates localized messages of all the constraint violations that has occured.

      The key "`Qi4j_ConstraintViolation_CompositeType`" will be used to lookup the text formatting pattern from the ResourceBundle, where `CompositeType` is the class name of the Composite where the constraint was violated. If such key does not exist, then the key "`Qi4j_ConstraintViolation`" will be used, and if that one also doesn't exist, or the resourceBundle argument is null, then the default patterns will be used;

      Type of Composite | Pattern used
      --- | ---
      Composite | `Constraint Violation in {2}.{3} with constraint {4}, in composite \n{0} of type {1}`
      EntityComposite | `Constraint Violation in {2}.{3} with constraint {4}, in entity {1}[id={0}]`
      ServiceComposite | `Constraint Violation in {2}.{3} with constraint {4}, in service {0}`

      Then format each ConstraintViolation according to such pattern, where the following argument are passed;

      Arg | Value
      --- | ---
      {0} | Composite instance toString()
      {1} | CompositeType class name
      {2} | MixinType class name
      {3} | MixinType method name
      {4} | Annotation toString()
      {5} | toString() of value passed as the argument, or "null" text if argument was null.

      NOTE!!! This class is still under construction and will be modified further.

      Parameters:
        `bundle` - The ResourceBundle for Localization, or null if default formatting and locale to be used.
      Returns:
        An array of localized messages of the violations incurred.

    - #### localizedMessage

          public String localizedMessage()

    - #### getLocalizedMessage

          public String getLocalizedMessage()

      Overrides:
        `getLocalizedMessage` in class `Throwable`

    - #### getMessage

          public String getMessage()

      Overrides:
        `getMessage` in class `Throwable`

    - #### methodName

          public String methodName()

    - #### mixinTypeName

          public String mixinTypeName()