|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jgoodies.validation.message.AbstractValidationMessage
com.jgoodies.validation.message.PropertyValidationMessage
public final class PropertyValidationMessage
An implementation of 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 Summary | |
|---|---|
PropertyValidationMessage(Severity severity,
java.lang.String text,
java.lang.Object target,
java.lang.String role,
java.lang.String property)
Constructs a PropertyValidationMessage for the given text, subject, role description and property description. |
|
PropertyValidationMessage(java.lang.String text,
java.lang.Object target,
java.lang.String role,
java.lang.String property)
Constructs a PropertyValidationMessage of type warning for the given text, subject, role description and property description. |
|
| Method Summary | |
|---|---|
java.lang.String |
aspect()
Returns a description of the validated aspect, that is the target's role plus the validated property. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this validation message for equality. |
java.lang.String |
formattedText()
Returns a message description as formatted text. |
int |
hashCode()
Returns the hash code value for this validation message. |
java.lang.Object |
key()
Returns this message's aspect as association key. |
java.lang.String |
property()
Returns a description of the validated object property, for example "zip code". |
java.lang.String |
role()
Returns a description of the role of the validated object. |
java.lang.Object |
target()
Returns the validated object that holds the validated property, for example an address object. |
| Methods inherited from class com.jgoodies.validation.message.AbstractValidationMessage |
|---|
setKey, severity, text, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PropertyValidationMessage(java.lang.String text,
java.lang.Object target,
java.lang.String role,
java.lang.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 property
java.lang.NullPointerException - if the text, target, role, or property
is null
java.lang.IllegalArgumentException - if severity is Severity.OK
public PropertyValidationMessage(Severity severity,
java.lang.String text,
java.lang.Object target,
java.lang.String role,
java.lang.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 property
java.lang.NullPointerException - if the text, target, role, or property
is null
java.lang.IllegalArgumentException - if severity is Severity.OK| Method Detail |
|---|
public java.lang.Object target()
public java.lang.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 java.lang.String property()
public java.lang.String aspect()
Examples:
"Customer.last name" "Customer.age" "Address.zip code" "Shipping address.zip code" "Physical address.zip code"
public java.lang.String formattedText()
formattedText in interface ValidationMessageformattedText in class AbstractValidationMessagepublic java.lang.Object key()
key in interface ValidationMessagekey in class AbstractValidationMessageaspect()public boolean equals(java.lang.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 java.lang.Objecto - 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 java.lang.ObjectObject.hashCode()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||