Interface Validated
- All Known Implementing Classes:
MetaData
,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.
ValidationError
s 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
ValidationError
s, it's possible to limit their number and only
store the first error that occurs for a particular subject.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddConstrainedPropertyRules
(ConstrainedProperty constrainedProperty) Adds the validation rules that are related to a particularConstrainedProperty
.Adds a new validation group.void
addRule
(ValidationRule rule) Adds a new validation rule.void
Add a new validation error explicitly to the collection of already existing errors.int
Counts the number of storedValidationError
s.void
focusGroup
(String name) Focuses on one particular validation group, showing only theValidationError
s that were generated by itsValidationRule
s.generateConstrainedPropertyRules
(ConstrainedProperty constrainedProperty) Generates the validation rules that are related to a particularConstrainedProperty
.Retrieve a particular validation group.Retrieves all validation groups.getLoadingErrors
(String propertyName) Returns the collection of error messages that occurred during the loading of the content of a certain property.getRules()
Retrieves that validation rules that have been registered.Returns the list of subjects that this object is able to validate internally through thevalidate()
method.Returns a set with all the storedValidationError
s.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 oneValidationError
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
Provide the bean instance that will be validated.void
replaceValidationErrors
(Set<ValidationError> errors) Replaces the storedValidationError
s with a new set of errors.void
resetGroup
(String name) Removed all theValidationError
s of a particular validation group.void
Resets the validation by removing all validation errors that are currently present.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 ofValidationError
s 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 providedValidationContext
boolean
validateGroup
(String name) Validate theValidationRule
s of a particular validation group.boolean
validateGroup
(String name, ValidationContext context) Validate theValidationRule
s of a particular validation group and also validates the entire bean within the providedValidationContext
-
Method Details
-
validate
boolean validate()Validates the internal subjects.This method is not supposed 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; orfalse
if validation errors are available.- Since:
- 1.0
- See Also:
-
validate
Validates the internal subjects and also validates the bean within the providedValidationContext
This method is not supposed 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
- theValidationContext
in which this bean instance will be additionally validated- Returns:
true
if no validation errors are present after the validation; orfalse
if validation errors are available.- Since:
- 1.0
- See Also:
-
addRule
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.0
- See Also:
-
getRules
List<ValidationRule> getRules()Retrieves that validation rules that have been registered.- Since:
- 1.0
- See Also:
-
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:
-
addValidationError
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
- theValidationError
to add- Since:
- 1.0
- See Also:
-
getValidationErrors
Set<ValidationError> getValidationErrors()Returns a set with all the storedValidationError
s.- Returns:
- A
Set
instance with all the storedValidationError
s. Note that when no errors are available an empty set is returned, notnull
. - Since:
- 1.0
-
countValidationErrors
int countValidationErrors()Counts the number of storedValidationError
s.- Returns:
- The number of stored
ValidationError
s. - Since:
- 1.0
-
replaceValidationErrors
Replaces the storedValidationError
s with a new set of errors.- Parameters:
errors
- theSet
instance that contains all theValidationError
s that have to be stored.- Since:
- 1.0
-
limitSubjectErrors
Limits the number of errors for a particular subject so that maximum oneValidationError
can be stored for it.- Parameters:
subject
- the name of the subject that has to be limited.- Since:
- 1.0
-
unlimitSubjectErrors
Unlimits the number of errors for a particular subject so that any number ofValidationError
s can be stored for it.- Parameters:
subject
- the name of the subject that has to be unlimited.- Since:
- 1.0
-
getValidatedSubjects
Returns the list of subjects that this object is able to validate internally through thevalidate()
method.- Returns:
- a List instance with the names of the internally validated subjects
- Since:
- 1.0
-
isSubjectValid
Checks if a subject is valid.This is determined by verifying if there are
ValidationError
s 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; orfalse
when errors are present for the subject.- Since:
- 1.0
- See Also:
-
makeErrorValid
Makes errors for a particular subject and identifier valid.This is done by removing all
ValidationError
s that are stored with this identifier and subject.- Parameters:
identifier
- the name of the error identifier that has to be madesubject
- the name of the subject that has to be made valid. valid.- Since:
- 1.0
-
makeSubjectValid
Makes a subject valid.This is done by removing all
ValidationError
s that are stored for it.- Parameters:
subject
- the name of the subject that has to be made valid.- Since:
- 1.0
-
provideValidatedBean
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.0
-
retrieveValidatedBean
Validated retrieveValidatedBean()Retrieves the bean instance that will be validated.- Since:
- 1.0
-
addGroup
Adds a new validation group.- Parameters:
name
- the name of the validation group that needs to be created and added- Returns:
- the newly created
ValidationGroup
- Since:
- 1.0
-
focusGroup
Focuses on one particular validation group, showing only theValidationError
s that were generated by itsValidationRule
s.- Parameters:
name
- the name of the validation group that will be focused- Since:
- 1.0
-
resetGroup
Removed all theValidationError
s of a particular validation group.- Parameters:
name
- the name of the validation group that will be focused- Since:
- 1.0
-
getGroups
Collection<ValidationGroup> getGroups()Retrieves all validation groups.- Returns:
- the collection of all registered validation groups
- Since:
- 1.0
-
getGroup
Retrieve a particular validation group.- Parameters:
name
- the name of the validation group that will be retrieved- Returns:
- the requested
ValidationGroup
; ornull
if no such validation group exists - Since:
- 1.0
-
validateGroup
Validate theValidationRule
s of a particular validation group.- Parameters:
name
- the name of the validation group that will be retrieved- Returns:
true
if no validation errors were generated; orfalse
otherwise- Since:
- 1.0
-
validateGroup
Validate theValidationRule
s of a particular validation group and also validates the entire bean within the providedValidationContext
- Parameters:
name
- the name of the validation groupcontext
- theValidationContext
in which this bean instance will be additionally validated- Returns:
true
if no validation errors were generated; orfalse
otherwise- Since:
- 1.0
-
addConstrainedPropertyRules
Adds the validation rules that are related to a particularConstrainedProperty
.If the rules of this property name have already been added before through another
ConstrainedProperty
instance, its existingValidationRule
s will be erased and the previous constraints will be merged into the newConstrainedProperty
before adding its validation rules.- Parameters:
constrainedProperty
- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRule
s - Since:
- 1.0
-
generateConstrainedPropertyRules
List<PropertyValidationRule> generateConstrainedPropertyRules(ConstrainedProperty constrainedProperty) Generates the validation rules that are related to a particularConstrainedProperty
.- Parameters:
constrainedProperty
- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRule
s - Since:
- 1.0
-
getLoadingErrors
Returns the collection of error messages that occurred during the loading of the content of a certain property.- Parameters:
propertyName
- the name of the property whose loading errors should be obtained- Returns:
- null if no errors occurred during the loading of the content of
the provided property or if the property doesn't exist; or
the requested collection of error messages
- Since:
- 1.0
-