public class ConstraintViolationException extends IllegalArgumentException
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.
Constructor and Description |
---|
ConstraintViolationException(Collection<ValueConstraintViolation> violations) |
Modifier and Type | Method and Description |
---|---|
Collection<ValueConstraintViolation> |
constraintViolations() |
String |
getMessage() |
String |
localizedMessageFrom(ResourceBundle bundle)
Creates localized message of all the constraint violations that has occured.
|
void |
setCompositeDescriptor(CompositeDescriptor descriptor) |
void |
setIdentity(Identity identity) |
void |
setInstanceString(String instanceString) |
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public ConstraintViolationException(Collection<ValueConstraintViolation> violations)
public Collection<ValueConstraintViolation> constraintViolations()
public String localizedMessageFrom(ResourceBundle bundle)
Each ConstraintViolationException concerns one Composite instance, but may have many violations on that instance. For the composite instance related message following entries in the ResourceBundle will be searched for a pattern in the following order;
polygene.constraint.CompositeType
polygene.constraint.composite
where CompositeType
is the
class name of the Composite instance. If such key does not exist, or if the resourceBundle argument is null,
then the default patterns will be used;
Type of Composite | Pattern used |
---|---|
Composite | \tConstraint Violation(s) in {0} with types {3}\n |
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} | Primary Type of Composite |
{1} | Composite instance toString() |
{2} | Identity if composite implements HasIdentity |
{3} | Comma-separeated list of types implemented by Composite |
Once the message at the composite type level has been established, the message will contain each of the found violations. For each such violation, the resource bundle will be searched in the following order;
polygene.constraint.MixinType.member
polygene.constraint.MixinType
polygene.constraint.mixin
MixinType
refers to the mixin type of the member (method, field or
constructor) and the member
is the name of such Member.
Type of Composite | Pattern used |
---|---|
Mixin | \t\t@{2} {0}.{1} does not allow value [{4}] |
Arg | Value |
---|---|
{0} | Mixin Type Name |
{1} | Mixin Member Name |
{2} | Annotation type |
{3} | Annotation toString |
{4} | Name of the Member, see Name |
{5} | Value attempted |
bundle
- The ResourceBundle for Localization, or null if default formatting and locale to be used.public String getMessage()
getMessage
in class Throwable
public void setCompositeDescriptor(CompositeDescriptor descriptor)
public void setIdentity(Identity identity)
public void setInstanceString(String instanceString)