net.sourceforge.stripes.validation
Class DefaultValidationMetadataProvider

java.lang.Object
  extended by net.sourceforge.stripes.validation.DefaultValidationMetadataProvider
All Implemented Interfaces:
ConfigurableComponent, ValidationMetadataProvider

public class DefaultValidationMetadataProvider
extends Object
implements ValidationMetadataProvider

An implementation of ValidationMetadataProvider that scans classes and their superclasses for properties annotated with Validate and/or ValidateNestedProperties and exposes the validation metadata specified by those annotations. When searching for annotations, this implementation looks first at the property's read method (getter), then its write method (setter), and finally at the field itself.

Since:
Stripes 1.5
Author:
Ben Gunter

Constructor Summary
DefaultValidationMetadataProvider()
           
 
Method Summary
 Configuration getConfiguration()
          Get the Configuration object that was passed into init(Configuration).
 Map<String,ValidationMetadata> getValidationMetadata(Class<?> beanType)
          Get a map of property names to ValidationMetadata for the given ActionBean class.
 ValidationMetadata getValidationMetadata(Class<?> beanType, ParameterName field)
          Get the validation metadata associated with the named property of the given ActionBean class.
 void init(Configuration configuration)
          Currently does nothing except store a reference to configuration.
protected  Map<String,ValidationMetadata> loadForClass(Class<?> beanType)
          Get validation information for all the properties and nested properties of the given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultValidationMetadataProvider

public DefaultValidationMetadataProvider()
Method Detail

init

public void init(Configuration configuration)
          throws Exception
Currently does nothing except store a reference to configuration.

Specified by:
init in interface ConfigurableComponent
Parameters:
configuration - the Configuration object being used by Stripes
Throws:
Exception - should be thrown if the component cannot be configured well enough to use.

getConfiguration

public Configuration getConfiguration()
Get the Configuration object that was passed into init(Configuration).


getValidationMetadata

public Map<String,ValidationMetadata> getValidationMetadata(Class<?> beanType)
Description copied from interface: ValidationMetadataProvider
Get a map of property names to ValidationMetadata for the given ActionBean class.

Specified by:
getValidationMetadata in interface ValidationMetadataProvider
Parameters:
beanType - any class
Returns:
A map of property names to ValidationMetadata. If no validation information is present for the given class, then an empty map will be returned.

getValidationMetadata

public ValidationMetadata getValidationMetadata(Class<?> beanType,
                                                ParameterName field)
Description copied from interface: ValidationMetadataProvider
Get the validation metadata associated with the named property of the given ActionBean class.

Specified by:
getValidationMetadata in interface ValidationMetadataProvider
Parameters:
beanType - any class
field - a (possibly nested) property of beanType
Returns:
A ValidationMetadata object, if there is one associated with the property. If the property is not to be validated, then null.

loadForClass

protected Map<String,ValidationMetadata> loadForClass(Class<?> beanType)
Get validation information for all the properties and nested properties of the given class. The Validate and/or ValidateNestedProperties annotations may be applied to the property's read method, write method, or field declaration. If a property has a ValidateNestedProperties annotation, then the nested properties named in its Validate annotations will be included as well.

Parameters:
beanType - a class
Returns:
A map of (possibly nested) property names to ValidationMetadata for the property.
Throws:
StripesRuntimeException - if conflicts are found in the validation annotations


? Copyright 2005-2006, Stripes Development Team.