com.uwyn.rife.site
Interface Validated

All Known Subinterfaces:
Credentials, RoleUserCredentials, ValidatedConstrained<P>
All Known Implementing Classes:
CmfValidation, ContentInfo, ContentRepository, DatabaseContentInfo, Email, MetaData, RoleUser, Task, Taskoption, Validation

public interface Validated

This interface defines methods for bean-centric data validation.

Validation is bound to subjects that have distinct names. Each subject corresponds to a different variable, for example a property of a bean. When a subject is found to be invalid, a corresponding instance of ValidationError has to be registered.

ValidationErrors indicate in detail why a Validated object doesn't contain valid data. They should be stored internally and can be manipulated by other classes that are able to work with Validated objects. This makes it possible to collect errors incrementally in one central place and to allow each component in a system to perform its own part of the validation.

A Validated object has a validate() method which should be used to perform mandatory validation on subjects and data that the object itself knows about. This validation has to perform all checks that guarantee a coherent internal state of the data. Note that this method should not reset the validation, but instead add new validation errors to an already existing collection.

Since it's possible that subjects generate multiple ValidationErrors, it's possible to limit their number and only store the first error that occurs for a particular subject.

Since:
1.0
Version:
$Revision: 3634 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)
See Also:
ValidationError, ValidationContext

Method Summary
 void addRule(ValidationRule rule)
          Adds a new validation rule.
 void addValidationError(ValidationError error)
          Add a new validation error explicitly to the collection of already existing errors.
 int countValidationErrors()
          Counts the number of stored ValidationErrors.
 List<ValidationRule> getRules()
          Retrieves that validation rules that have been registered.
 List<String> getValidatedSubjects()
          Returns the list of subjects that this object is able to validate internally through the validate() method.
 Set<ValidationError> getValidationErrors()
          Returns a set with all the stored ValidationErrors.
 boolean isSubjectValid(String subject)
          Checks if a subject is valid.
 void limitSubjectErrors(String subject)
          Limits the number of errors for a particular subject so that maximum one ValidationError can be stored for it.
 void makeErrorValid(String identifier, String subject)
          Makes errors for a particular subject and identifier valid.
 void makeSubjectValid(String subject)
          Makes a subject valid.
 void provideValidatedBean(Validated bean)
          Provide the bean instance that will be validated.
 void replaceValidationErrors(Set<ValidationError> errors)
          Replaces the stored ValidationErrors with a new set of errors.
 void resetValidation()
          Resets the validation by removing all validation errors that are currently present.
 Validated retrieveValidatedBean()
          Retrieves the bean instance that will be validated.
 void unlimitSubjectErrors(String subject)
          Unlimits the number of errors for a particular subject so that any number of ValidationErrors can be stored for it.
 boolean validate()
          Validates the internal subjects.
 boolean validate(ValidationContext context)
          Validates the internal subjects and also validates the bean within the provided ValidationContext
 

Method Detail

validate

boolean validate()
Validates the internal subjects.

This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

Returns:
true if no validation errors are present after the validation; or

false if validation errors are available.

Since:
1.0
See Also:
validate(ValidationContext), resetValidation()

validate

boolean validate(ValidationContext context)
Validates the internal subjects and also validates the bean within the provided ValidationContext

This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

Parameters:
context - the ValidationContext in which this bean instance will be additionally validated
Returns:
true if no validation errors are present after the validation; or

false if validation errors are available.

Since:
1.0
See Also:
validate(), resetValidation()

addRule

void addRule(ValidationRule rule)

Adds a new validation rule.

The collection of rules is what is supposed to perform the validation, though any other additional method could be used. At least those rules that have been registered will be evaluated.

Parameters:
rule - the rule that will be added
Since:
1.4
See Also:
validate(), getRules()

getRules

List<ValidationRule> getRules()
Retrieves that validation rules that have been registered.

Since:
1.0
See Also:
validate(), addRule(com.uwyn.rife.site.ValidationRule)

resetValidation

void resetValidation()

Resets the validation by removing all validation errors that are currently present.

This method is typically used to start a new validation from scratch or to re-validate until all errors have been solved.

Since:
1.0
See Also:
validate()

addValidationError

void addValidationError(ValidationError error)
Add a new validation error explicitly to the collection of already existing errors.

Note that this method should respect subjects with a limited error amount and only store the first error for these subjects.

Parameters:
error - the ValidationError to add
Since:
1.0
See Also:
limitSubjectErrors(String), unlimitSubjectErrors(String)

getValidationErrors

Set<ValidationError> getValidationErrors()
Returns a set with all the stored ValidationErrors.

Returns:
A Set instance with all the stored ValidationErrors. Note that when no errors are available an empty set is returned, not null.
Since:
1.0

countValidationErrors

int countValidationErrors()
Counts the number of stored ValidationErrors.

Returns:
The number of stored ValidationErrors.
Since:
1.0

replaceValidationErrors

void replaceValidationErrors(Set<ValidationError> errors)
Replaces the stored ValidationErrors with a new set of errors.

Parameters:
errors - the Set instance that contains all the ValidationErrors that have to be stored.
Since:
1.0

limitSubjectErrors

void limitSubjectErrors(String subject)
Limits the number of errors for a particular subject so that maximum one ValidationError can be stored for it.

Parameters:
subject - the name of the subject that has to be limited.
Since:
1.0

unlimitSubjectErrors

void unlimitSubjectErrors(String subject)
Unlimits the number of errors for a particular subject so that any number of ValidationErrors can be stored for it.

Parameters:
subject - the name of the subject that has to be unlimited.
Since:
1.0

getValidatedSubjects

List<String> getValidatedSubjects()
Returns the list of subjects that this object is able to validate internally through the validate() method.

Returns:
a List instance with the names of the internally validated subjects
Since:
1.0

isSubjectValid

boolean isSubjectValid(String subject)
Checks if a subject is valid.

This is determined by verifying if there are ValidationErrors present for it. This method will thus not execute a validation action.

Parameters:
subject - the name of the subject that has to be checked.
Returns:
true when no errors could be found for the subject; or

false when errors are present for the subject.

Since:
1.0
See Also:
validate()

makeErrorValid

void makeErrorValid(String identifier,
                    String subject)
Makes errors for a particular subject and identifier valid.

This is done by removing all ValidationErrors that are stored with this identifier and subject.

Parameters:
identifier - the name of the error identifier that has to be made
subject - the name of the subject that has to be made valid. valid.
Since:
1.0

makeSubjectValid

void makeSubjectValid(String subject)
Makes a subject valid.

This is done by removing all ValidationErrors that are stored for it.

Parameters:
subject - the name of the subject that has to be made valid.
Since:
1.0

provideValidatedBean

void provideValidatedBean(Validated bean)
Provide the bean instance that will be validated.

By default 'this' will be used.

Parameters:
bean - the bean instance that will be validated
Since:
1.4

retrieveValidatedBean

Validated retrieveValidatedBean()
Retrieves the bean instance that will be validated.

Since:
1.4


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.