Class Validation
- All Implemented Interfaces:
Cloneable,Constrained,ConstrainedPropertyListener,Validated
- Direct Known Subclasses:
ContentInfo,ContentRepository,TaskOption
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThis 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.voidaddConstraint(ConstrainedBean constrainedBean) Add a new constrained bean.voidaddConstraint(ConstrainedProperty constrainedProperty) Add a new constrained property.Adds a new validation group.voidaddRule(ValidationRule rule) Adds a new validation rule.voidaddValidationError(ValidationError newError) Add a new validation error explicitly to the collection of already existing errors.clone()voidconstraintSet(ConstrainedProperty property, String name, Object constraintData) This method is called on a registered listener when a constraint has been set to a particular value.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.Retrieves the constrained bean that has been set for thisConstrainedinstance.Returns a collection with all the constrained properties that have been registered.getConstrainedProperty(String propertyName) Retrieve a registeredConstrainedPropertyaccording to its name.static StringgetErrorIndication(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 storedValidationErrors.booleanhasPropertyConstraint(String name) Indicates whether this constrained bean contains a particular constraint on at least one of its properties.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
-
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:ValidatedProvide the bean instance that will be validated.By default '
this' will be used.- Specified by:
provideValidatedBeanin interfaceValidated- Parameters:
bean- the bean instance that will be validated
-
retrieveValidatedBean
Description copied from interface:ValidatedRetrieves the bean instance that will be validated.- Specified by:
retrieveValidatedBeanin interfaceValidated
-
addGroup
Description copied from interface:ValidatedAdds a new validation group. -
focusGroup
Description copied from interface:ValidatedFocuses on one particular validation group, showing only theValidationErrors that were generated by itsValidationRules.- Specified by:
focusGroupin interfaceValidated- Parameters:
name- the name of the validation group that will be focused
-
resetGroup
Description copied from interface:ValidatedRemoved all theValidationErrors of a particular validation group.- Specified by:
resetGroupin interfaceValidated- Parameters:
name- the name of the validation group that will be focused
-
addRule
Description copied from interface:ValidatedAdds 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:ValidatedGenerates the validation rules that are related to a particularConstrainedProperty.- Specified by:
generateConstrainedPropertyRulesin interfaceValidated- Parameters:
constrainedProperty- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRules
-
addConstrainedPropertyRules
public List<PropertyValidationRule> addConstrainedPropertyRules(ConstrainedProperty constrainedProperty) Description copied from interface:ValidatedAdds 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.- Specified by:
addConstrainedPropertyRulesin interfaceValidated- Parameters:
constrainedProperty- the ConstrainedProperty that will be inspected- Returns:
- the list of generated
ValidationRules
-
addConstraint
Description copied from interface:ConstrainedAdd 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:
addConstraintin interfaceConstrained- Parameters:
constrainedProperty- theConstrainedPropertyinstance that has to be added- See Also:
-
addConstraint
Description copied from interface:ConstrainedAdd 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:
addConstraintin interfaceConstrained- Parameters:
constrainedBean- theConstrainedBeaninstance that has to be added- See Also:
-
addValidationError
Description copied from interface:ValidatedAdd 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:
addValidationErrorin interfaceValidated- Parameters:
newError- theValidationErrorto add- See Also:
-
getRules
Description copied from interface:ValidatedRetrieves that validation rules that have been registered. -
getConstrainedProperties
Description copied from interface:ConstrainedReturns a collection with all the constrained properties that have been registered.- Specified by:
getConstrainedPropertiesin interfaceConstrained- Returns:
- A
Collectionwith all theConstrainedPropertyobjects that are registered. If no constrained properties are available, an empty collection will be returned, notnull. - See Also:
-
hasPropertyConstraint
Description copied from interface:ConstrainedIndicates whether this constrained bean contains a particular constraint on at least one of its properties.- Specified by:
hasPropertyConstraintin interfaceConstrained- Returns:
trueif this constraint is present on at least one of the properties; orfalseotherwise- See Also:
-
getConstrainedProperty
Description copied from interface:ConstrainedRetrieve a registeredConstrainedPropertyaccording to its name.- Specified by:
getConstrainedPropertyin interfaceConstrained- Parameters:
propertyName- the name of theConstrainedPropertythat has to be retrieved- Returns:
- the requested
ConstrainedProperty; ornullif no suchConstrainedPropertyis available. - See Also:
-
getGroups
Description copied from interface:ValidatedRetrieves all validation groups. -
getGroup
Description copied from interface:ValidatedRetrieve a particular validation group. -
getConstrainedBean
Description copied from interface:ConstrainedRetrieves the constrained bean that has been set for thisConstrainedinstance.- Specified by:
getConstrainedBeanin interfaceConstrained- Returns:
- the requested
ConstrainedBean; ornullif noConstrainedBeanis available. - See Also:
-
validate
public boolean validate()Description copied from interface:ValidatedValidates 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:ValidatedValidates 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.
-
validateGroup
Description copied from interface:ValidatedValidate theValidationRules of a particular validation group.- Specified by:
validateGroupin interfaceValidated- Parameters:
name- the name of the validation group that will be retrieved- Returns:
trueif no validation errors were generated; orfalseotherwise
-
validateGroup
Description copied from interface:ValidatedValidate theValidationRules of a particular validation group and also validates the entire bean within the providedValidationContext- Specified by:
validateGroupin interfaceValidated- 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
-
countValidationErrors
public int countValidationErrors()Description copied from interface:ValidatedCounts the number of storedValidationErrors.- Specified by:
countValidationErrorsin interfaceValidated- Returns:
- The number of stored
ValidationErrors.
-
resetValidation
public void resetValidation()Description copied from interface:ValidatedResets 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:
resetValidationin interfaceValidated- See Also:
-
getValidationErrors
Description copied from interface:ValidatedReturns a set with all the storedValidationErrors.- Specified by:
getValidationErrorsin interfaceValidated- Returns:
- A
Setinstance with all the storedValidationErrors. Note that when no errors are available an empty set is returned, notnull.
-
replaceValidationErrors
Description copied from interface:ValidatedReplaces the storedValidationErrors with a new set of errors.- Specified by:
replaceValidationErrorsin interfaceValidated- Parameters:
errors- theSetinstance that contains all theValidationErrors that have to be stored.
-
limitSubjectErrors
Description copied from interface:ValidatedLimits the number of errors for a particular subject so that maximum oneValidationErrorcan be stored for it.- Specified by:
limitSubjectErrorsin interfaceValidated- Parameters:
subject- the name of the subject that has to be limited.
-
unlimitSubjectErrors
Description copied from interface:ValidatedUnlimits the number of errors for a particular subject so that any number ofValidationErrors can be stored for it.- Specified by:
unlimitSubjectErrorsin interfaceValidated- Parameters:
subject- the name of the subject that has to be unlimited.
-
isSubjectValid
Description copied from interface:ValidatedChecks 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.- Specified by:
isSubjectValidin interfaceValidated- 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.- See Also:
-
makeSubjectValid
Description copied from interface:ValidatedMakes a subject valid.This is done by removing all
ValidationErrors that are stored for it.- Specified by:
makeSubjectValidin interfaceValidated- Parameters:
subject- the name of the subject that has to be made valid.
-
makeErrorValid
Description copied from interface:ValidatedMakes errors for a particular subject and identifier valid.This is done by removing all
ValidationErrors that are stored with this identifier and subject.- Specified by:
makeErrorValidin 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:ValidatedReturns the list of subjects that this object is able to validate internally through thevalidate()method.- Specified by:
getValidatedSubjectsin interfaceValidated- Returns:
- a List instance with the names of the internally validated subjects
-
getErrorIndication
-
getLoadingErrors
Description copied from interface:ValidatedReturns the collection of error messages that occurred during the loading of the content of a certain property.- Specified by:
getLoadingErrorsin 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:ConstrainedPropertyListenerThis method is called on a registered listener when a constraint has been set to a particular value.- Specified by:
constraintSetin interfaceConstrainedPropertyListener- Parameters:
property- theConstrainedPropertyinstance where the constraint has been setname- the name of the constraintconstraintData- the data that the constraint has been set to
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-