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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis 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.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.voidAdd a new validation error explicitly to the collection of already existing errors.clone()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.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.Has to return the bean instance that has been associated with this metadata class instance.final ValidatedRetrieves the bean instance that will be validated.final voidsetMetaDataBean(Object bean) This method will be called by RIFE2 when a new instance of the metadata class has been created.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
-
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:MetaDataBeanAwareThis method will be called by RIFE2 when a new instance of the metadata class has been created.
- Specified by:
setMetaDataBeanin interfaceMetaDataBeanAware- Parameters:
bean- the bean instance that this particular metadata instance has been associated with
-
retrieveMetaDataBean
Description copied from interface:MetaDataBeanAwareHas to return the bean instance that has been associated with this metadata class instance.- Specified by:
retrieveMetaDataBeanin interfaceMetaDataBeanAware- Returns:
- this metadata's bean instance
-
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
-
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:
-
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:
-
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:
-
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:
-
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.
-
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:
-
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:
error- theValidationErrorto add- 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.
-
countValidationErrors
public int countValidationErrors()Description copied from interface:ValidatedCounts the number of storedValidationErrors.- Specified by:
countValidationErrorsin interfaceValidated- Returns:
- The number of stored
ValidationErrors.
-
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.
-
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
-
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:
-
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.
-
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.
-
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.
-
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
-
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
-
getRules
Description copied from interface:ValidatedRetrieves that validation rules that have been registered. -
getGroups
Description copied from interface:ValidatedRetrieves all validation groups. -
getGroup
Description copied from interface:ValidatedRetrieve a particular validation group. -
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
-
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
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-