com.uwyn.rife.site
Class MetaData<B extends ConstrainedBean,P extends ConstrainedProperty>

java.lang.Object
  extended by com.uwyn.rife.site.MetaData<B,P>
All Implemented Interfaces:
Constrained<B,P>, MetaDataBeanAware, MetaDataMerged, Validated, ValidatedConstrained<P>, Cloneable

public abstract class MetaData<B extends ConstrainedBean,P extends ConstrainedProperty>
extends Object
implements ValidatedConstrained<P>, Constrained<B,P>, MetaDataMerged, MetaDataBeanAware, Cloneable

This abstract base class can be conveniently used to added Constrained and ValidatedConstrained meta data 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 meta data isn't used.

Since:
1.4
Version:
$Revision: 3717 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)
See Also:
MetaDataMerged, MetaDataBeanAware

Constructor Summary
MetaData()
           
 
Method Summary
 void activateMetaData()
          This method is called at least once and maximum once when any meta-data introspection logic is executed.
 List<PropertyValidationRule> addConstrainedPropertyRules(P constrainedProperty)
          Adds the validation rules that are related to a particular ConstrainedProperty.
 void addConstraint(B constrainedBean)
          Add a new constrained bean.
 void addConstraint(P constrainedProperty)
          Add a new constrained property.
 ValidationGroup<P> addGroup(String name)
          Adds a new validation group.
 void addRule(ValidationRule rule)
          Adds a new validation rule.
 void addValidationError(ValidationError error)
          Add a new validation error explicitly to the collection of already existing errors.
 Object clone()
           
 int countValidationErrors()
          Counts the number of stored ValidationErrors.
 void focusGroup(String name)
          Focuses on one particular validation group, showing only the ValidationErrors that were generated by its ValidationRules.
 List<PropertyValidationRule> generateConstrainedPropertyRules(P constrainedProperty)
          Generates the validation rules that are related to a particular ConstrainedProperty.
 B getConstrainedBean()
          Retrieves the constrained bean that has been set for this Constrained instance.
 Collection<P> getConstrainedProperties()
          Returns a collection with all the constrained properties that have been registered.
 P getConstrainedProperty(String propertyName)
          Retrieve a registered ConstrainedProperty according to its name.
 ValidationGroup<P> getGroup(String name)
          Retrieve a particular validation group.
 Collection<ValidationGroup<P>> getGroups()
          Retrieves all validation groups.
 Collection<String> getLoadingErrors(String propertyName)
          Returns the collection of error messages that occurred during the loading of the content of a certain property.
 List<ValidationRule> getRules()
          Retrieves that validation rules that have been registered.
 List<String> getValidatedSubjects()
          Returns the list of subjects that this object is able to validate internally through the validate() method.
 Set<ValidationError> getValidationErrors()
          Returns a set with all the stored ValidationErrors.
 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 one ValidationError 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 provideValidatedBean(Validated bean)
          Provide the bean instance that will be validated.
 void replaceValidationErrors(Set<ValidationError> errors)
          Replaces the stored ValidationErrors with a new set of errors.
 void resetGroup(String name)
          Removed all the ValidationErrors of a particular validation group.
 void resetValidation()
          Resets the validation by removing all validation errors that are currently present.
 Validated retrieveValidatedBean()
          Retrieves the bean instance that will be validated.
 void setMetaDataBean(Object bean)
          This method will be called by RIFE when a new instance of the meta data class has been created.
 void unlimitSubjectErrors(String subject)
          Unlimits the number of errors for a particular subject so that any number of ValidationErrors 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 provided ValidationContext
 boolean validateGroup(String name)
          Validate the ValidationRules of a particular validation group.
 boolean validateGroup(String name, ValidationContext context)
          Validate the ValidationRules of a particular validation group and also validates the entire bean within the provided ValidationContext
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaData

public MetaData()
Method Detail

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 meta data setup here, you don't enforce a performance penalty at each object construction like when you do this in the default constructor.

Since:
1.4

setMetaDataBean

public final void setMetaDataBean(Object bean)
Description copied from interface: MetaDataBeanAware

This method will be called by RIFE when a new instance of the meta data class has been created.

Specified by:
setMetaDataBean in interface MetaDataBeanAware
Parameters:
bean - the bean instance that this particular meta data instance has been associated with

provideValidatedBean

public void provideValidatedBean(Validated bean)
Description copied from interface: Validated
Provide the bean instance that will be validated.

By default 'this' will be used.

Specified by:
provideValidatedBean in interface Validated
Parameters:
bean - the bean instance that will be validated

retrieveValidatedBean

public final Validated retrieveValidatedBean()
Description copied from interface: Validated
Retrieves the bean instance that will be validated.

Specified by:
retrieveValidatedBean in interface Validated

addConstraint

public void addConstraint(B constrainedBean)
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 interface Constrained<B extends ConstrainedBean,P extends ConstrainedProperty>
Parameters:
constrainedBean - the ConstrainedBean instance that has to be added
See Also:
ConstrainedBean

addConstraint

public void addConstraint(P constrainedProperty)
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 interface Constrained<B extends ConstrainedBean,P extends ConstrainedProperty>
Parameters:
constrainedProperty - the ConstrainedProperty instance that has to be added
See Also:
ConstrainedProperty

getConstrainedBean

public B getConstrainedBean()
Description copied from interface: Constrained
Retrieves the constrained bean that has been set for this Constrained instance.

Specified by:
getConstrainedBean in interface Constrained<B extends ConstrainedBean,P extends ConstrainedProperty>
Returns:
the requested ConstrainedBean; or

null if no ConstrainedBean is available.

See Also:
ConstrainedProperty

getConstrainedProperties

public Collection<P> getConstrainedProperties()
Description copied from interface: Constrained
Returns a collection with all the constrained properties that have been registered.

Specified by:
getConstrainedProperties in interface Constrained<B extends ConstrainedBean,P extends ConstrainedProperty>
Returns:
A Collection with all the ConstrainedProperty objects that are registered. If no constrained properties are available, an empty collection will be returned, not null.
See Also:
ConstrainedProperty

hasPropertyConstraint

public boolean hasPropertyConstraint(String name)
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 interface Constrained<B extends ConstrainedBean,P extends ConstrainedProperty>
Returns:
true if this constraint is present on at least one of the properties; or

false otherwise

See Also:
ConstrainedProperty

getConstrainedProperty

public P getConstrainedProperty(String propertyName)
Description copied from interface: Constrained
Retrieve a registered ConstrainedProperty according to its name.

Specified by:
getConstrainedProperty in interface Constrained<B extends ConstrainedBean,P extends ConstrainedProperty>
Parameters:
propertyName - the name of the ConstrainedProperty that has to be retrieved
Returns:
the requested ConstrainedProperty; or

null if no such ConstrainedProperty is available.

See Also:
ConstrainedProperty

validate

public boolean validate()
Description copied from interface: Validated
Validates the internal subjects.

This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

Specified by:
validate in interface Validated
Returns:
true if no validation errors are present after the validation; or

false if validation errors are available.

See Also:
Validated.validate(ValidationContext), Validated.resetValidation()

validate

public boolean validate(ValidationContext context)
Description copied from interface: Validated
Validates the internal subjects and also validates the bean within the provided ValidationContext

This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

Specified by:
validate in interface Validated
Parameters:
context - the ValidationContext in which this bean instance will be additionally validated
Returns:
true if no validation errors are present after the validation; or

false if validation errors are available.

See Also:
Validated.validate(), Validated.resetValidation()

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 interface Validated
See Also:
Validated.validate()

addValidationError

public void addValidationError(ValidationError error)
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 interface Validated
Parameters:
error - the ValidationError to add
See Also:
Validated.limitSubjectErrors(String), Validated.unlimitSubjectErrors(String)

getValidationErrors

public Set<ValidationError> getValidationErrors()
Description copied from interface: Validated
Returns a set with all the stored ValidationErrors.

Specified by:
getValidationErrors in interface Validated
Returns:
A Set instance with all the stored ValidationErrors. Note that when no errors are available an empty set is returned, not null.

countValidationErrors

public int countValidationErrors()
Description copied from interface: Validated
Counts the number of stored ValidationErrors.

Specified by:
countValidationErrors in interface Validated
Returns:
The number of stored ValidationErrors.

replaceValidationErrors

public void replaceValidationErrors(Set<ValidationError> errors)
Description copied from interface: Validated
Replaces the stored ValidationErrors with a new set of errors.

Specified by:
replaceValidationErrors in interface Validated
Parameters:
errors - the Set instance that contains all the ValidationErrors that have to be stored.

limitSubjectErrors

public void limitSubjectErrors(String subject)
Description copied from interface: Validated
Limits the number of errors for a particular subject so that maximum one ValidationError can be stored for it.

Specified by:
limitSubjectErrors in interface Validated
Parameters:
subject - the name of the subject that has to be limited.

unlimitSubjectErrors

public void unlimitSubjectErrors(String subject)
Description copied from interface: Validated
Unlimits the number of errors for a particular subject so that any number of ValidationErrors can be stored for it.

Specified by:
unlimitSubjectErrors in interface Validated
Parameters:
subject - the name of the subject that has to be unlimited.

getValidatedSubjects

public List<String> getValidatedSubjects()
Description copied from interface: Validated
Returns the list of subjects that this object is able to validate internally through the validate() method.

Specified by:
getValidatedSubjects in interface Validated
Returns:
a List instance with the names of the internally validated subjects

isSubjectValid

public boolean isSubjectValid(String subject)
Description copied from interface: Validated
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.

Specified by:
isSubjectValid in interface Validated
Parameters:
subject - the name of the subject that has to be checked.
Returns:
true when no errors could be found for the subject; or

false when errors are present for the subject.

See Also:
Validated.validate()

makeErrorValid

public void makeErrorValid(String identifier,
                           String subject)
Description copied from interface: Validated
Makes 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:
makeErrorValid in interface Validated
Parameters:
identifier - the name of the error identifier that has to be made
subject - the name of the subject that has to be made valid. valid.

makeSubjectValid

public void makeSubjectValid(String subject)
Description copied from interface: Validated
Makes a subject valid.

This is done by removing all ValidationErrors that are stored for it.

Specified by:
makeSubjectValid in interface Validated
Parameters:
subject - the name of the subject that has to be made valid.

addGroup

public ValidationGroup<P> addGroup(String name)
Description copied from interface: ValidatedConstrained
Adds a new validation group.

Specified by:
addGroup in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
name - the name of the validation group that needs to be created and added
Returns:
the newly created ValidationGroup

focusGroup

public void focusGroup(String name)
Description copied from interface: ValidatedConstrained
Focuses on one particular validation group, showing only the ValidationErrors that were generated by its ValidationRules.

Specified by:
focusGroup in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
name - the name of the validation group that will be focused

resetGroup

public void resetGroup(String name)
Description copied from interface: ValidatedConstrained
Removed all the ValidationErrors of a particular validation group.

Specified by:
resetGroup in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
name - the name of the validation group that will be focused

addRule

public void addRule(ValidationRule rule)
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.

Specified by:
addRule in interface Validated
Parameters:
rule - the rule that will be added
See Also:
Validated.validate(), Validated.getRules()

addConstrainedPropertyRules

public List<PropertyValidationRule> addConstrainedPropertyRules(P constrainedProperty)
Description copied from interface: ValidatedConstrained
Adds the validation rules that are related to a particular ConstrainedProperty.

If the rules of this property name have already been added before through another ConstrainedProperty instance, its existing ValidationRules will be erased and the previous constraints will be merged into the new ConstrainedProperty before adding its validation rules.

Specified by:
addConstrainedPropertyRules in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
constrainedProperty - the ConstrainedProperty that will be inspected
Returns:
the list of generated ValidationRules

generateConstrainedPropertyRules

public List<PropertyValidationRule> generateConstrainedPropertyRules(P constrainedProperty)
Description copied from interface: ValidatedConstrained
Generates the validation rules that are related to a particular ConstrainedProperty.

Specified by:
generateConstrainedPropertyRules in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
constrainedProperty - the ConstrainedProperty that will be inspected
Returns:
the list of generated ValidationRules

getRules

public List<ValidationRule> getRules()
Description copied from interface: Validated
Retrieves that validation rules that have been registered.

Specified by:
getRules in interface Validated
See Also:
Validated.validate(), Validated.addRule(com.uwyn.rife.site.ValidationRule)

getGroups

public Collection<ValidationGroup<P>> getGroups()
Description copied from interface: ValidatedConstrained
Retrieves all validation groups.

Specified by:
getGroups in interface ValidatedConstrained<P extends ConstrainedProperty>
Returns:
the collection of all registered validation groups

getGroup

public ValidationGroup<P> getGroup(String name)
Description copied from interface: ValidatedConstrained
Retrieve a particular validation group.

Specified by:
getGroup in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
name - the name of the validation group that will be retrieved
Returns:
the requested ValidationGroup; or

null if no such validation group exists


validateGroup

public boolean validateGroup(String name)
Description copied from interface: ValidatedConstrained
Validate the ValidationRules of a particular validation group.

Specified by:
validateGroup in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
name - the name of the validation group that will be retrieved
Returns:
true if no validation errors were generated; or

false otherwise


validateGroup

public boolean validateGroup(String name,
                             ValidationContext context)
Description copied from interface: ValidatedConstrained
Validate the ValidationRules of a particular validation group and also validates the entire bean within the provided ValidationContext

Specified by:
validateGroup in interface ValidatedConstrained<P extends ConstrainedProperty>
Parameters:
name - the name of the validation group
context - the ValidationContext in which this bean instance will be additionally validated
Returns:
true if no validation errors were generated; or

false otherwise


getLoadingErrors

public Collection<String> getLoadingErrors(String propertyName)
Description copied from interface: ValidatedConstrained
Returns the collection of error messages that occurred during the loading of the content of a certain property.

Specified by:
getLoadingErrors in interface ValidatedConstrained<P extends ConstrainedProperty>
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

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.