Class MetaData
- All Implemented Interfaces:
Cloneable
,Constrained
,MetaDataBeanAware
,MetaDataMerged
,Validated
Constrained
and Validated
metadata to a POJO.
Besides implementing all the required interfaces for you, it also sets up the underlying data structures in a lazy fashion. This allows you to benefit from a rich API without the memory overhead when the metadata isn't used.
- Since:
- 1.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This method is called at least once and maximum once when any meta-data introspection logic is executed.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
Add a new validation error explicitly to the collection of already existing errors.clone()
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.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.Has to return the bean instance that has been associated with this metadata class instance.final Validated
Retrieves the bean instance that will be validated.final void
setMetaDataBean
(Object bean) This method will be called by RIFE2 when a new instance of the metadata class has been created.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
-
MetaData
public MetaData()
-
-
Method Details
-
activateMetaData
public void activateMetaData()This method is called at least once and maximum once when any meta-data introspection logic is executed.You need to implement this method since it will be called after the underlying validation context has been initialized. Incidentally, by doing all your metadata setup here, you don't enforce a performance penalty at each object construction like when you do this in the default constructor.
- Since:
- 1.0
-
setMetaDataBean
Description copied from interface:MetaDataBeanAware
This method will be called by RIFE2 when a new instance of the metadata class has been created.
- Specified by:
setMetaDataBean
in interfaceMetaDataBeanAware
- Parameters:
bean
- the bean instance that this particular metadata instance has been associated with
-
retrieveMetaDataBean
Description copied from interface:MetaDataBeanAware
Has to return the bean instance that has been associated with this metadata class instance.- Specified by:
retrieveMetaDataBean
in interfaceMetaDataBeanAware
- Returns:
- this metadata's bean instance
-
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
-
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:
-
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:
-
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:
-
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:
-
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.
-
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:
-
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:
error
- theValidationError
to add- 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
.
-
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.
-
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.
-
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
-
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:
-
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.
-
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.
-
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.
-
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
-
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
-
getRules
Description copied from interface:Validated
Retrieves that validation rules that have been registered. -
getGroups
Description copied from interface:Validated
Retrieves all validation groups. -
getGroup
Description copied from interface:Validated
Retrieve a particular validation group. -
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
-
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
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-