com.jgoodies.validation.message
Class AbstractValidationMessage

java.lang.Object
  extended by com.jgoodies.validation.message.AbstractValidationMessage
All Implemented Interfaces:
ValidationMessage, Serializable
Direct Known Subclasses:
PropertyValidationMessage, SimpleValidationMessage

public abstract class AbstractValidationMessage
extends Object
implements ValidationMessage, Serializable

An abstract class that minimizes the effort required to implement the ValidationMessage interface. Holds the severity, a text message, and the association key.

Subclasses should implement #equals and #hashCode to prevent unnecessary change notifications for the result property when a ValidationResultModel gets a new ValidationResult. See for example the implementation of method PropertyValidationMessage.equals(Object).

Version:
$Revision: 1.11 $
Author:
Karsten Lentzsch
See Also:
Serialized Form

Constructor Summary
protected AbstractValidationMessage(String text, Severity severity)
          Constructs an AbstractValidationMessage for the given text and Severity.
protected AbstractValidationMessage(String text, Severity severity, Object key)
          Constructs an AbstractValidationMessage for the given text, Severity, and association key.
 
Method Summary
 String formattedText()
          Returns a message description as formatted text.
 Object key()
          Returns this message's association key that can be used to model a loose coupling between validation messages and views that present the validated data.
protected  void setKey(Object associationKey)
          Sets the given object as new association key.
 Severity severity()
          Returns this message's severity, either error or warning.
protected  String text()
          Returns this validation message's text.
 String toString()
          Returns a string representation of this validation message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractValidationMessage

protected AbstractValidationMessage(String text,
                                    Severity severity)
Constructs an AbstractValidationMessage for the given text and Severity.

Parameters:
text - describes this message
severity - this message's severity, either error or warning
Throws:
IllegalArgumentException - if severity is OK

AbstractValidationMessage

protected AbstractValidationMessage(String text,
                                    Severity severity,
                                    Object key)
Constructs an AbstractValidationMessage for the given text, Severity, and association key.

Parameters:
text - describes this message
severity - this message's severity, either error or warning
key - used to determine whether this message belongs to a given view
Throws:
IllegalArgumentException - if severity is OK
Method Detail

severity

public final Severity severity()
Returns this message's severity, either error or warning.

Specified by:
severity in interface ValidationMessage
Returns:
message's severity, either error or warning

formattedText

public String formattedText()
Returns a message description as formatted text. This default implementation just returns the message text. Subclasses may override to add information about the type and other message related information.

Specified by:
formattedText in interface ValidationMessage
Returns:
a message description as formatted text

text

protected final String text()
Returns this validation message's text.

Returns:
the message text

key

public Object key()
Returns this message's association key that can be used to model a loose coupling between validation messages and views that present the validated data.

Subclasses may override this method to return keys that are built from other internal data. For example, the PropertyValidationMessage returns the aspect as key.

See the class comment for more information about this relation.

Specified by:
key in interface ValidationMessage
Returns:
this message's association key

setKey

protected final void setKey(Object associationKey)
Sets the given object as new association key.

Parameters:
associationKey - the key to be set

toString

public String toString()
Returns a string representation of this validation message. Prints the class name and the formatted text.

Overrides:
toString in class Object
Returns:
a string representation of this validation message
See Also:
Object.toString()


Copyright © 2003-2011 JGoodies Karsten Lentzsch. All Rights Reserved.