org.qi4j.api.constraint
Class ConstraintViolationException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by java.lang.IllegalArgumentException
                  extended by 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.

This class is still under evolution. Beware that the methods, formatting, Locale spec may change. It will be stable before the 1.0 release.

See Also:
Serialized Form

Constructor Summary
ConstraintViolationException(Composite instance, Method method, Collection<ConstraintViolation> constraintViolations)
           
ConstraintViolationException(String instanceToString, String instanceTypeName, Method method, Collection<ConstraintViolation> violations)
           
ConstraintViolationException(String instanceToString, String instanceTypeName, String mixinTypeName, String methodName, Collection<ConstraintViolation> violations)
           
 
Method Summary
 Collection<ConstraintViolation> constraintViolations()
           
 String getLocalizedMessage()
           
 String[] getLocalizedMessages(ResourceBundle bundle)
          Creates localized messages of all the constraint violations that has occured.
 String getMessage()
           
 String localizedMessage()
           
 String methodName()
           
 String mixinTypeName()
           
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getStackTrace, 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,
                                    Method method,
                                    Collection<ConstraintViolation> constraintViolations)

ConstraintViolationException

public ConstraintViolationException(String instanceToString,
                                    String instanceTypeName,
                                    Method method,
                                    Collection<ConstraintViolation> violations)

ConstraintViolationException

public ConstraintViolationException(String instanceToString,
                                    String instanceTypeName,
                                    String mixinTypeName,
                                    String methodName,
                                    Collection<ConstraintViolation> violations)
Method Detail

constraintViolations

public Collection<ConstraintViolation> constraintViolations()

getLocalizedMessages

public String[] getLocalizedMessages(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 CompositePattern 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;
ArgValue
{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()