public class PropertyValidationMessage extends AbstractValidationMessage
ValidationMessage
that holds a text message,
the validated object (target), a descriptions of the validated property,
and a description of the role this object takes in the validation context.
The target can be used to identify the source of a validation message.
The role and property together build the aspect that is used
as association key; in other words, it can be used to determine whether
a view is associated with a given message or not.Example: We validate an invoice that has a shipping address and a physical address. We want to report that the zip code of the shipping address is missing. This can be described by:
String validationRole = "Shipping address"; Address validationTarget = invoice.getShippingAddress(); String validationText = "is mandatory"; String validationProperty= "zip code"; if (validationTarget.getZipCode() ...) { validationResult.addMessage( new PropertyValidationMessage( validationText, validationTarget, validationRole, validationProperty) ); }
Constructor and Description |
---|
PropertyValidationMessage(Severity severity,
String text,
Object target,
String role,
String property)
Constructs a PropertyValidationMessage for the given text,
subject, role description and property description.
|
PropertyValidationMessage(String text,
Object target,
String role,
String property)
Constructs a PropertyValidationMessage of type warning
for the given text, subject, role description and property description.
|
Modifier and Type | Method and Description |
---|---|
String |
aspect()
Returns a description of the validated aspect, that is the target's
role plus the validated property.
|
boolean |
equals(Object o)
Compares the specified object with this validation message for equality.
|
String |
formattedText()
Returns a message description as formatted text.
|
int |
hashCode()
Returns the hash code value for this validation message.
|
Object |
key()
Returns this message's aspect as association key.
|
String |
property()
Returns a description of the validated object property, for example
"zip code".
|
String |
role()
Returns a description of the role of the validated object.
|
Object |
target()
Returns the validated object that holds the validated property,
for example an address object.
|
setKey, severity, text, toString
public PropertyValidationMessage(String text, Object target, String role, String property)
Examples:
new PropertyValidationMessage( "is mandatory", aCustomer, "Customer", "last name"); new PropertyValidationMessage( "must be over 18", aCustomer, "Customer", "age"); new PropertyValidationMessage( "is mandatory", shippingAddress, "Shipping address", "zip code"); new PropertyValidationMessage( "is mandatory", shippingAddress, "Physical address", "zip code");
text
- describes the validation problemtarget
- the object that holds the validated propertyrole
- describes the target's role in the contextproperty
- describes the validated propertyNullPointerException
- if the text, target, role, or property
is null
IllegalArgumentException
- if severity
is OK
public PropertyValidationMessage(Severity severity, String text, Object target, String role, String property)
new PropertyValidationMessage( Severity.ERROR, "is mandatory", aCustomer, "Customer", "last name"); new PropertyValidationMessage( Severity.WARNING, "must be over 18", aCustomer, "Customer", "age"); new PropertyValidationMessage( Severity.ERROR, "is mandatory", shippingAddress, "Shipping address", "zip code"); new PropertyValidationMessage( Severity.ERROR, "is mandatory", physicalAddress, "Physical address", "zip code");
severity
- the message severity, either error or warningtext
- describes the validation problemtarget
- the object that holds the validated propertyrole
- describes the target's role in the contextproperty
- describes the validated propertyNullPointerException
- if the text, target, role, or property
is null
IllegalArgumentException
- if severity
is OK
public final Object target()
public final String role()
Example: An invoice object holds a single Order
instance,
and two instances of class Address
, one for the shipping
address and another for the physical address. You then may consider
using the following roles: Customer, Shipping address, and
Physical address.
public final String property()
public String aspect()
Examples:
"Customer.last name" "Customer.age" "Address.zip code" "Shipping address.zip code" "Physical address.zip code"
public String formattedText()
formattedText
in interface ValidationMessage
formattedText
in class AbstractValidationMessage
public Object key()
key
in interface ValidationMessage
key
in class AbstractValidationMessage
aspect()
public boolean equals(Object o)
true
if and only if the specified object is also
a property validation message, both messages have the same severity,
text, target, role, and property. In other words, two property validation
messages are defined to be equal if and only if they behave one like
the other.
This implementation first checks if the specified object is this
a property validation message. If so, it returns true
;
if not, it checks if the specified object is a property validation message.
If not, it returns false
; if so, it checks and returns
if the severities, texts, targets, roles, and properties of both messages
are equal.
equals
in class Object
o
- the object to be compared for equality with this validation message.true
if the specified object is equal
to this validation message.Object.equals(java.lang.Object)
public int hashCode()
If this class could be extended, we should check if the formatted text
is null
.
hashCode
in class Object
Object.hashCode()
Copyright © 2003-2011 JGoodies Karsten Lentzsch. All Rights Reserved.