com.jgoodies.validation.util
Class PropertyValidationSupport

java.lang.Object
  extended by com.jgoodies.validation.util.PropertyValidationSupport

public class PropertyValidationSupport
extends Object

A utility class that minimizes the effort to create instances of PropertyValidationMessage in validation code. You can use an instance of this class as a member field of your validator implementation and delegate the message creation to it.

Version:
$Revision: 1.11 $
Author:
Karsten Lentzsch
See Also:
PropertyValidationMessage

Constructor Summary
PropertyValidationSupport(Object target, String role)
          Constructs a PropertyValidationSupport instance for the given validation target and its validation role.
PropertyValidationSupport(Severity defaultSeverity, Object target, String role)
          Constructs a PropertyValidationSupport instance for the given validation target and its validation role.
PropertyValidationSupport(ValidationResult defaultResult, Severity defaultSeverity, Object target, String role)
          Constructs a PropertyValidationSupport instance for the given default result, default severity, validation target and the given validation role.
 
Method Summary
 void add(Severity severity, String property, String text)
          Adds a PropertyValidationMessage to this object's default ValidationResult.
 void add(String property, String text)
          Adds a PropertyValidationMessage to this object's default ValidationResult.
 void add(ValidationResult result, Severity severity, String property, String text)
          Adds a PropertyValidationMessage to the specified ValidationResult.
 void add(ValidationResult result, String property, String text)
          Adds a PropertyValidationMessage to the specified ValidationResult.
 void addError(String property, String text)
          Adds an error PropertyValidationMessage to this object's default ValidationResult.
 void addError(ValidationResult result, String property, String text)
          Adds an error PropertyValidationMessage to the specified ValidationResult.
 void addWarning(String property, String text)
          Adds a warning PropertyValidationMessage to this object's default ValidationResult.
 void addWarning(ValidationResult result, String property, String text)
          Adds a warning PropertyValidationMessage to the specified ValidationResult.
 void clearResult()
          Sets an empty ValidationResult as default result.
 PropertyValidationMessage create(Severity severity, String property, String text)
          Creates and returns an error PropertyValidationMessage for the given property and message text using the specified severity.
 PropertyValidationMessage create(String property, String text)
          Creates and returns a PropertyValidationMessage for the given property and message text using the default severity.
 PropertyValidationMessage createError(String property, String text)
          Creates and returns an error PropertyValidationMessage for the given property and message text.
 PropertyValidationMessage createWarning(String property, String text)
          Creates and returns a warning PropertyValidationMessage for the given property and message text.
 ValidationResult getResult()
          Returns the default ValidationResult.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyValidationSupport

public PropertyValidationSupport(Object target,
                                 String role)
Constructs a PropertyValidationSupport instance for the given validation target and its validation role. The default severity is set to Severity.WARNING.

Parameters:
target - the object to be validated
role - the validation target's role in the outer context
Throws:
NullPointerException - if the target or role is null

PropertyValidationSupport

public PropertyValidationSupport(Severity defaultSeverity,
                                 Object target,
                                 String role)
Constructs a PropertyValidationSupport instance for the given validation target and its validation role.

Parameters:
defaultSeverity - the optional Severity used for message creation when no severity is specified
target - the object to be validated
role - the validation target's role in the outer context
Throws:
NullPointerException - if the target or role is null
IllegalArgumentException - if defaultSeverity is Severity.OK

PropertyValidationSupport

public PropertyValidationSupport(ValidationResult defaultResult,
                                 Severity defaultSeverity,
                                 Object target,
                                 String role)
Constructs a PropertyValidationSupport instance for the given default result, default severity, validation target and the given validation role.

Parameters:
defaultResult - the optional ValidationResult that is used to add ValidationMessages to
defaultSeverity - the optional Severity used for message creation when no severity is specified
target - the object to be validated
role - the validation target's role in the outer context
Throws:
NullPointerException - if the target or role is null
IllegalArgumentException - if defaultSeverity is OK
Method Detail

clearResult

public final void clearResult()
Sets an empty ValidationResult as default result. Useful at the begin of a validation sequence.


getResult

public final ValidationResult getResult()
Returns the default ValidationResult.

Returns:
the default validation result

createError

public final PropertyValidationMessage createError(String property,
                                                   String text)
Creates and returns an error PropertyValidationMessage for the given property and message text.

Parameters:
property - describes the validated property
text - the message text
Returns:
a PropertyValidationMessage with error severity for the given property and text

createWarning

public final PropertyValidationMessage createWarning(String property,
                                                     String text)
Creates and returns a warning PropertyValidationMessage for the given property and message text.

Parameters:
property - describes the validated property
text - the message text
Returns:
a PropertyValidationMessage with warning severity for the given property and text

create

public final PropertyValidationMessage create(String property,
                                              String text)
Creates and returns a PropertyValidationMessage for the given property and message text using the default severity.

Parameters:
property - describes the validated property
text - the message text
Returns:
a PropertyValidationMessage with default severity for the given property and text

create

public PropertyValidationMessage create(Severity severity,
                                        String property,
                                        String text)
Creates and returns an error PropertyValidationMessage for the given property and message text using the specified severity. Subclasses can override this method to return a custom subclass of PropertyValidationMessage.

Parameters:
severity - the Severity to be used
property - describes the validated property
text - the message text
Returns:
a PropertyValidationMessage with the specified severity for the given property and text
Throws:
IllegalArgumentException - if severity is OK

addError

public final void addError(String property,
                           String text)
Adds an error PropertyValidationMessage to this object's default ValidationResult. Uses the given property and message text.

Parameters:
property - describes the validated property
text - the message text

addWarning

public final void addWarning(String property,
                             String text)
Adds a warning PropertyValidationMessage to this object's default ValidationResult. Uses the given property and message text.

Parameters:
property - describes the validated property
text - the message text

add

public final void add(String property,
                      String text)
Adds a PropertyValidationMessage to this object's default ValidationResult. Uses the default severity and the given property and message text.

Parameters:
property - describes the validated property
text - the message text

add

public final void add(Severity severity,
                      String property,
                      String text)
Adds a PropertyValidationMessage to this object's default ValidationResult. Uses the specified Severity and given property and message text.

Parameters:
severity - the Severity to be used
property - describes the validated property
text - the message text

addError

public final void addError(ValidationResult result,
                           String property,
                           String text)
Adds an error PropertyValidationMessage to the specified ValidationResult. Uses the given property and message text.

Parameters:
result - the result the message will be added to
property - describes the validated property
text - the message text

addWarning

public final void addWarning(ValidationResult result,
                             String property,
                             String text)
Adds a warning PropertyValidationMessage to the specified ValidationResult. Uses the given property and message text.

Parameters:
result - the result the message will be added to
property - describes the validated property
text - the message text

add

public final void add(ValidationResult result,
                      String property,
                      String text)
Adds a PropertyValidationMessage to the specified ValidationResult. Uses this object's default severity and the given property and message text.

Parameters:
result - the result the message will be added to
property - describes the validated property
text - the message text

add

public final void add(ValidationResult result,
                      Severity severity,
                      String property,
                      String text)
Adds a PropertyValidationMessage to the specified ValidationResult. Uses the specified severity and the given property and message text.

Parameters:
result - the result the message will be added to
severity - the severity used for the created message
property - describes the validated property
text - the message text
Throws:
IllegalArgumentException - if severity is OK


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