Class Validation
- All Implemented Interfaces:
Cloneable
,Constrained
,ConstrainedPropertyListener
,Validated
- Direct Known Subclasses:
ContentInfo
,ContentRepository
,TaskOption
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
This method is called at least once and maximum once when any method related to Validated rules, subjects and group or Constrained properties are used.addConstrainedPropertyRules
(ConstrainedProperty constrainedProperty) Adds the validation rules that are related to a particularConstrainedProperty
.void
addConstraint
(ConstrainedBean constrainedBean) Add a new constrained bean.void
addConstraint
(ConstrainedProperty constrainedProperty) Add a new constrained property.Adds a new validation group.void
addRule
(ValidationRule rule) Adds a new validation rule.void
addValidationError
(ValidationError newError) Add a new validation error explicitly to the collection of already existing errors.clone()
void
constraintSet
(ConstrainedProperty property, String name, Object constraintData) This method is called on a registered listener when a constraint has been set to a particular value.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
.Retrieves the constrained bean that has been set for thisConstrained
instance.Returns a collection with all the constrained properties that have been registered.getConstrainedProperty
(String propertyName) Retrieve a registeredConstrainedProperty
according to its name.static String
getErrorIndication
(Validated validated, String subject, String valid, String error) 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
hasPropertyConstraint
(String name) Indicates whether this constrained bean contains a particular constraint on at least one of its properties.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
-
Constructor Details
-
Validation
public Validation()
-
-
Method Details
-
activateValidation
protected void activateValidation()This method is called at least once and maximum once when any method related to Validated rules, subjects and group or Constrained properties are used.By overriding this method, you can thus isolate all the validation setup code and don't enforce a performance penalty at each object construction when doing it in the default constructor.
- Since:
- 1.0
-
provideValidatedBean
Description copied from interface:Validated
Provide the bean instance that will be validated.By default '
this
' will be used.- Specified by:
provideValidatedBean
in interfaceValidated
- Parameters:
bean
- the bean instance that will be validated
-
retrieveValidatedBean
Description copied from interface:Validated
Retrieves the bean instance that will be validated.- Specified by:
retrieveValidatedBean
in interfaceValidated
-
addGroup
Description copied from interface:Validated
Adds a new validation group. -
focusGroup
Description copied from interface:Validated
Focuses on one particular validation group, showing only theValidationError
s that were generated by itsValidationRule
s.- Specified by:
focusGroup
in interfaceValidated
- Parameters:
name
- the name of the validation group that will be focused
-
resetGroup
Description copied from interface:Validated
Removed all theValidationError
s of a particular validation group.- Specified by:
resetGroup
in interfaceValidated
- Parameters:
name
- the name of the validation group that will be focused
-
addRule
Description copied from interface:Validated
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.
-
generateConstrainedPropertyRules
public List<PropertyValidationRule> generateConstrainedPropertyRules(ConstrainedProperty constrainedProperty) Description copied from interface:Validated
Generates the validation rules that are related to a particularConstrainedProperty
.- Specified by:
generateConstrainedPropertyRules
in interfaceValidated
- Parameters:
constrainedProperty
- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRule
s
-
addConstrainedPropertyRules
public List<PropertyValidationRule> addConstrainedPropertyRules(ConstrainedProperty constrainedProperty) Description copied from interface:Validated
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.- Specified by:
addConstrainedPropertyRules
in interfaceValidated
- Parameters:
constrainedProperty
- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRule
s
-
addConstraint
Description copied from interface:Constrained
Add a new constrained property.When several of the same constrained properties are added, they are merged at constraint-level. This means for instance that a previous inList constraint will be replaced by the one of the new constrained bean, they will not be combined.
- Specified by:
addConstraint
in interfaceConstrained
- Parameters:
constrainedProperty
- theConstrainedProperty
instance that has to be added- See Also:
-
addConstraint
Description copied from interface:Constrained
Add a new constrained bean.When several constrained beans are added, they are merged at constraint-level. This means for instance that all previous unique constraints will be replaced by those of the new constrained bean, they will not be combined.
- Specified by:
addConstraint
in interfaceConstrained
- Parameters:
constrainedBean
- theConstrainedBean
instance that has to be added- See Also:
-
addValidationError
Description copied from interface:Validated
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.
- Specified by:
addValidationError
in interfaceValidated
- Parameters:
newError
- theValidationError
to add- See Also:
-
getRules
Description copied from interface:Validated
Retrieves that validation rules that have been registered. -
getConstrainedProperties
Description copied from interface:Constrained
Returns a collection with all the constrained properties that have been registered.- Specified by:
getConstrainedProperties
in interfaceConstrained
- Returns:
- A
Collection
with all theConstrainedProperty
objects that are registered. If no constrained properties are available, an empty collection will be returned, notnull
. - See Also:
-
hasPropertyConstraint
Description copied from interface:Constrained
Indicates whether this constrained bean contains a particular constraint on at least one of its properties.- Specified by:
hasPropertyConstraint
in interfaceConstrained
- Returns:
true
if this constraint is present on at least one of the properties; orfalse
otherwise- See Also:
-
getConstrainedProperty
Description copied from interface:Constrained
Retrieve a registeredConstrainedProperty
according to its name.- Specified by:
getConstrainedProperty
in interfaceConstrained
- Parameters:
propertyName
- the name of theConstrainedProperty
that has to be retrieved- Returns:
- the requested
ConstrainedProperty; or
null
if no suchConstrainedProperty
is available. - See Also:
-
getGroups
Description copied from interface:Validated
Retrieves all validation groups. -
getGroup
Description copied from interface:Validated
Retrieve a particular validation group. -
getConstrainedBean
Description copied from interface:Constrained
Retrieves the constrained bean that has been set for thisConstrained
instance.- Specified by:
getConstrainedBean
in interfaceConstrained
- Returns:
- the requested
ConstrainedBean; or
null
if noConstrainedBean
is available. - See Also:
-
validate
public boolean validate()Description copied from interface:Validated
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.
-
validate
Description copied from interface:Validated
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.
-
validateGroup
Description copied from interface:Validated
Validate theValidationRule
s of a particular validation group.- Specified by:
validateGroup
in interfaceValidated
- Parameters:
name
- the name of the validation group that will be retrieved- Returns:
true
if no validation errors were generated; orfalse
otherwise
-
validateGroup
Description copied from interface:Validated
Validate theValidationRule
s of a particular validation group and also validates the entire bean within the providedValidationContext
- Specified by:
validateGroup
in interfaceValidated
- 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
-
countValidationErrors
public int countValidationErrors()Description copied from interface:Validated
Counts the number of storedValidationError
s.- Specified by:
countValidationErrors
in interfaceValidated
- Returns:
- The number of stored
ValidationError
s.
-
resetValidation
public void resetValidation()Description copied from interface:Validated
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.
- Specified by:
resetValidation
in interfaceValidated
- See Also:
-
getValidationErrors
Description copied from interface:Validated
Returns a set with all the storedValidationError
s.- Specified by:
getValidationErrors
in interfaceValidated
- Returns:
- A
Set
instance with all the storedValidationError
s. Note that when no errors are available an empty set is returned, notnull
.
-
replaceValidationErrors
Description copied from interface:Validated
Replaces the storedValidationError
s with a new set of errors.- Specified by:
replaceValidationErrors
in interfaceValidated
- Parameters:
errors
- theSet
instance that contains all theValidationError
s that have to be stored.
-
limitSubjectErrors
Description copied from interface:Validated
Limits the number of errors for a particular subject so that maximum oneValidationError
can be stored for it.- Specified by:
limitSubjectErrors
in interfaceValidated
- Parameters:
subject
- the name of the subject that has to be limited.
-
unlimitSubjectErrors
Description copied from interface:Validated
Unlimits the number of errors for a particular subject so that any number ofValidationError
s can be stored for it.- Specified by:
unlimitSubjectErrors
in interfaceValidated
- Parameters:
subject
- the name of the subject that has to be unlimited.
-
isSubjectValid
Description copied from interface:Validated
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.- Specified by:
isSubjectValid
in interfaceValidated
- 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.- See Also:
-
makeSubjectValid
Description copied from interface:Validated
Makes a subject valid.This is done by removing all
ValidationError
s that are stored for it.- Specified by:
makeSubjectValid
in interfaceValidated
- Parameters:
subject
- the name of the subject that has to be made valid.
-
makeErrorValid
Description copied from interface:Validated
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.- Specified by:
makeErrorValid
in interfaceValidated
- 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.
-
getValidatedSubjects
Description copied from interface:Validated
Returns the list of subjects that this object is able to validate internally through thevalidate()
method.- Specified by:
getValidatedSubjects
in interfaceValidated
- Returns:
- a List instance with the names of the internally validated subjects
-
getErrorIndication
-
getLoadingErrors
Description copied from interface:Validated
Returns the collection of error messages that occurred during the loading of the content of a certain property.- Specified by:
getLoadingErrors
in interfaceValidated
- 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
-
constraintSet
Description copied from interface:ConstrainedPropertyListener
This method is called on a registered listener when a constraint has been set to a particular value.- Specified by:
constraintSet
in interfaceConstrainedPropertyListener
- Parameters:
property
- theConstrainedProperty
instance where the constraint has been setname
- the name of the constraintconstraintData
- the data that the constraint has been set to
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-