org.springmodules.validation.bean.conf.loader.xml
Class AbstractResourceBasedBeanValidationConfigurationLoader

java.lang.Object
  extended by org.springmodules.validation.bean.conf.loader.xml.AbstractResourceBasedBeanValidationConfigurationLoader
All Implemented Interfaces:
InitializingBean, BeanValidationConfigurationLoader
Direct Known Subclasses:
AbstractXmlBeanValidationConfigurationLoader

public abstract class AbstractResourceBasedBeanValidationConfigurationLoader
extends Object
implements BeanValidationConfigurationLoader, InitializingBean

A base class for all bean validation configuration loaders that are resource based (that is, load configuration from files, urls, etc...)

Author:
Uri Boness

Constructor Summary
AbstractResourceBasedBeanValidationConfigurationLoader()
          Constructs a new AbstractResourceBasedBeanValidationConfigurationLoader.
AbstractResourceBasedBeanValidationConfigurationLoader(Resource[] resources)
          Constructs a new AbstractResourceBasedBeanValidationConfigurationLoader with the given resources.
 
Method Summary
 void afterPropertiesSet()
           
protected  String createDefaultConfigurationFileName(Class clazz)
          Creates the default configuration file name for the given class.
 Resource getResource()
          If this loader is configured with only on resource, use this method to retreive it.
 Resource[] getResources()
          Returns the resouces this loader uses to load bean validation configurations.
 BeanValidationConfiguration loadConfiguration(Class clazz)
          Loads the bean validation configuration for the given class from the configured resources.
protected abstract  Map loadConfigurations(Resource resource)
          Loads all the bean validation configurations from the given resource and returns them as a map where the value is a BeanValidationConfiguration instance and the key is the associated class.
protected  BeanValidationConfiguration loadDefaultConfiguration(Class clazz)
          Loads the default validation configuration for the given class, caches it and returns it.
 void setResource(Resource resource)
          Sets a single resource this loader will use to load the bean validation configurations from.
 void setResources(Resource[] resources)
          Sets the resources this loader will use to load bean validation configurations.
 boolean supports(Class clazz)
          Determines whether the given class is supported by this loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractResourceBasedBeanValidationConfigurationLoader

public AbstractResourceBasedBeanValidationConfigurationLoader()
Constructs a new AbstractResourceBasedBeanValidationConfigurationLoader.


AbstractResourceBasedBeanValidationConfigurationLoader

public AbstractResourceBasedBeanValidationConfigurationLoader(Resource[] resources)
Constructs a new AbstractResourceBasedBeanValidationConfigurationLoader with the given resources.

Parameters:
resources - The resources from which this loader will load the bean validation configurations.
Method Detail

loadConfiguration

public final BeanValidationConfiguration loadConfiguration(Class clazz)
Loads the bean validation configuration for the given class from the configured resources.

Specified by:
loadConfiguration in interface BeanValidationConfigurationLoader
Parameters:
clazz - The class for which the validation configuration will be loaded.
Returns:
The bean validation configuration for the given class or null if no configuration could be found.
See Also:
BeanValidationConfigurationLoader.loadConfiguration(Class)

supports

public final boolean supports(Class clazz)
Determines whether the given class is supported by this loader.

Specified by:
supports in interface BeanValidationConfigurationLoader
Parameters:
clazz - The class to be checked.
Returns:
true if this loader can load a valication configuration for the given class, false otherwise.
See Also:
BeanValidationConfigurationLoader.supports(Class)

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

loadConfigurations

protected abstract Map loadConfigurations(Resource resource)
Loads all the bean validation configurations from the given resource and returns them as a map where the value is a BeanValidationConfiguration instance and the key is the associated class.

Parameters:
resource - The resource from which the configurations will be loaded.
Returns:
A map of bean validation configuration by the associated class.

getResources

public Resource[] getResources()
Returns the resouces this loader uses to load bean validation configurations.

Returns:
The resouces this loader uses to load bean validation configurations.

setResources

public void setResources(Resource[] resources)
Sets the resources this loader will use to load bean validation configurations.

Parameters:
resources - The resources this loader will use to load bean validation configurations.

getResource

public Resource getResource()
If this loader is configured with only on resource, use this method to retreive it.

Returns:
The single resource this loader uses to load bean validation configuration from. If the loader uses multiple resources, the first one is returned.

setResource

public void setResource(Resource resource)
Sets a single resource this loader will use to load the bean validation configurations from.

Parameters:
resource - The one resource this loader will use to load the bean validation configurations from.

loadDefaultConfiguration

protected BeanValidationConfiguration loadDefaultConfiguration(Class clazz)
Loads the default validation configuration for the given class, caches it and returns it. The configuration resource for the given class is resolved by the createDefaultConfigurationFileName(Class) method.

Parameters:
clazz - The class for which the default configuration should be loaded.
Returns:
The default validation configuration of the given class.

createDefaultConfigurationFileName

protected String createDefaultConfigurationFileName(Class clazz)
Creates the default configuration file name for the given class. This method will search in the classpath for a file that is located where the class itself is located, named after the class, and has the extention of ".vld.xml". For example, the default configuration file name for class Person will be Person.vld.xml.

Parameters:
clazz - The class for which the default configuration will be created.
Returns:
The default validatoin configuration resource for the given class.


Copyright © 2009. All Rights Reserved.