Interface Validated
- All Known Subinterfaces:
Credentials,RoleUserCredentials
- All Known Implementing Classes:
ContentInfo,ContentRepository,DatabaseContentInfo,MetaData,RoleUser,Task,TaskOption,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
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddConstrainedPropertyRules(ConstrainedProperty constrainedProperty) Adds the validation rules that are related to a particularConstrainedProperty.Adds a new validation group.voidaddRule(ValidationRule rule) Adds a new validation rule.voidAdd a new validation error explicitly to the collection of already existing errors.intCounts the number of storedValidationErrors.voidfocusGroup(String name) Focuses on one particular validation group, showing only theValidationErrors that were generated by itsValidationRules.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 storedValidationErrors.booleanisSubjectValid(String subject) Checks if a subject is valid.voidlimitSubjectErrors(String subject) Limits the number of errors for a particular subject so that maximum oneValidationErrorcan be stored for it.voidmakeErrorValid(String identifier, String subject) Makes errors for a particular subject and identifier valid.voidmakeSubjectValid(String subject) Makes a subject valid.voidProvide the bean instance that will be validated.voidreplaceValidationErrors(Set<ValidationError> errors) Replaces the storedValidationErrors with a new set of errors.voidresetGroup(String name) Removed all theValidationErrors of a particular validation group.voidResets the validation by removing all validation errors that are currently present.Retrieves the bean instance that will be validated.voidunlimitSubjectErrors(String subject) Unlimits the number of errors for a particular subject so that any number ofValidationErrors can be stored for it.booleanvalidate()Validates the internal subjects.booleanvalidate(ValidationContext context) Validates the internal subjects and also validates the bean within the providedValidationContextbooleanvalidateGroup(String name) Validate theValidationRules of a particular validation group.booleanvalidateGroup(String name, ValidationContext context) Validate theValidationRules 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:
trueif no validation errors are present after the validation; orfalseif validation errors are available.- Since:
- 1.0
- See Also:
-
validate
Validates the internal subjects and also validates the bean within the providedValidationContextThis 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- theValidationContextin which this bean instance will be additionally validated- Returns:
trueif no validation errors are present after the validation; orfalseif 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- theValidationErrorto add- Since:
- 1.0
- See Also:
-
getValidationErrors
Set<ValidationError> getValidationErrors()Returns a set with all the storedValidationErrors.- Returns:
- A
Setinstance with all the storedValidationErrors. Note that when no errors are available an empty set is returned, notnull. - Since:
- 1.0
-
countValidationErrors
int countValidationErrors()Counts the number of storedValidationErrors.- Returns:
- The number of stored
ValidationErrors. - Since:
- 1.0
-
replaceValidationErrors
Replaces the storedValidationErrors with a new set of errors.- Parameters:
errors- theSetinstance that contains all theValidationErrors that have to be stored.- Since:
- 1.0
-
limitSubjectErrors
Limits the number of errors for a particular subject so that maximum oneValidationErrorcan 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 ofValidationErrors 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
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:
truewhen no errors could be found for the subject; orfalsewhen 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
ValidationErrors 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
ValidationErrors 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 theValidationErrors that were generated by itsValidationRules.- Parameters:
name- the name of the validation group that will be focused- Since:
- 1.0
-
resetGroup
Removed all theValidationErrors 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; ornullif no such validation group exists - Since:
- 1.0
-
validateGroup
Validate theValidationRules of a particular validation group.- Parameters:
name- the name of the validation group that will be retrieved- Returns:
trueif no validation errors were generated; orfalseotherwise- Since:
- 1.0
-
validateGroup
Validate theValidationRules of a particular validation group and also validates the entire bean within the providedValidationContext- Parameters:
name- the name of the validation groupcontext- theValidationContextin which this bean instance will be additionally validated- Returns:
trueif no validation errors were generated; orfalseotherwise- 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
ConstrainedPropertyinstance, its existingValidationRules will be erased and the previous constraints will be merged into the newConstrainedPropertybefore adding its validation rules.- Parameters:
constrainedProperty- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRules - 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
ValidationRules - 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
-