org.iscreen
Class ValidationFactory

java.lang.Object
  extended by org.iscreen.ValidationFactory
Direct Known Subclasses:
XmlServiceFactory

public class ValidationFactory
extends java.lang.Object

This class represents factories that can generate validation services from configuration files (or however the factory generates them). The static portion of this factory implementation is thread-safe.

Author:
Shellman, Dan

Field Summary
protected  java.lang.String configLocation
           
protected  java.util.Locale defaultLocale
           
static java.lang.String FACTORY_DEFAULT_XML
          Deprecated. This is no longer used for version 1.1 or later. For OGNL, use FACTORY_OGNL_XML. For MVEL, use FACTORY_MVEL_XML.
static java.lang.String FACTORY_MVEL_XML
           
static java.lang.String FACTORY_OGNL_XML
           
protected  java.util.Map serviceMap
           
 
Constructor Summary
protected ValidationFactory()
          Protected constructor.
 
Method Summary
static ValidationFactory buildFactory(java.lang.String factoryId, java.lang.String configLocation, java.util.Locale theDefaultLocale, java.util.Map services)
          Builds a registered factory.
static ValidationFactory buildFactory(java.lang.String factoryId, java.lang.String configLocation, java.util.Map services)
          Builds a registered factory.
protected  java.lang.String getConfigLocation()
          Retrieves the configuration file location for this validation factory.
protected  java.util.Locale getDefaultLocale()
          Retrieves the default locale for this factory.
protected  java.util.Map getServices()
          Retrieves the map of services available to this factory.
 ValidationService getValidationService(java.lang.String serviceName)
          Retrieves a validation service with the given service name.
 ValidationService getValidationService(java.lang.String metaPropertyName, java.lang.String metaValue)
          Retrieves a validation service with the given meta property and value.
protected  void loadConfig()
          This method is called to initialize the factory.
static void registerFactory(java.lang.Class factoryClass, java.lang.String factoryId)
          Registers a factory with a given factory id.
protected  void setConfigLocation(java.lang.String location)
          This is called right after the validation factory is instantiated and the services call (setServices()) has been called.
protected  void setDefaultLocale(java.util.Locale locale)
          Sets the default locale for this factory.
protected  void setServices(java.util.Map theServices)
          This is called right after the validation factory is instantiated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY_DEFAULT_XML

public static final java.lang.String FACTORY_DEFAULT_XML
Deprecated. This is no longer used for version 1.1 or later. For OGNL, use FACTORY_OGNL_XML. For MVEL, use FACTORY_MVEL_XML.
See Also:
Constant Field Values

FACTORY_OGNL_XML

public static final java.lang.String FACTORY_OGNL_XML
See Also:
Constant Field Values

FACTORY_MVEL_XML

public static final java.lang.String FACTORY_MVEL_XML
See Also:
Constant Field Values

serviceMap

protected java.util.Map serviceMap

configLocation

protected java.lang.String configLocation

defaultLocale

protected java.util.Locale defaultLocale
Constructor Detail

ValidationFactory

protected ValidationFactory()
Protected constructor. In general, validation factories shouldn't be constructed directly (hence the need to register them, etc.).

Method Detail

buildFactory

public static ValidationFactory buildFactory(java.lang.String factoryId,
                                             java.lang.String configLocation,
                                             java.util.Locale theDefaultLocale,
                                             java.util.Map services)
Builds a registered factory. The factory is tied to the configuration type (such as XML, etc.). Pre-defined factories (constants defined as FACTORY_xxx) are always available.

Parameters:
factoryId - The id of the factory to retrieve.
configLocation - Classpath location of the configuration
theDefaultLocale - The default locale
services - Services that are necessary for the factory
Returns:
Returns a ValidationFactory. If none exist with the given id, then a runtime exception is thrown.

buildFactory

public static ValidationFactory buildFactory(java.lang.String factoryId,
                                             java.lang.String configLocation,
                                             java.util.Map services)
Builds a registered factory. The factory is tied to the configuration type (such as XML, etc.). Pre-defined factories (constants defined as FACTORY_xxx) are always available.

Parameters:
factoryId - The id of the factory to retrieve.
configLocation - Classpath location of the configuration
services - Services that are necessary for the factory
Returns:
Returns a ValidationFactory. If none exist with the given id, then a runtime exception is thrown.

registerFactory

public static void registerFactory(java.lang.Class factoryClass,
                                   java.lang.String factoryId)
Registers a factory with a given factory id. Use this method to register a custom-built factory. If a factory of the given id already exists, it will be replaced.

Parameters:
factoryClass - The class of the factory to register
factoryId - The id of the factory (used to retrieve it later)

getValidationService

public ValidationService getValidationService(java.lang.String serviceName)
Retrieves a validation service with the given service name.

Parameters:
serviceName - The name of the validation service.
Returns:
Returns the validation service with the given name.

getValidationService

public ValidationService getValidationService(java.lang.String metaPropertyName,
                                              java.lang.String metaValue)
Retrieves a validation service with the given meta property and value. Note that, since the meta properties and values may be duplicated across validation sets, it's possible for multiple validation services to be returned. Therefore, the ValidationService implementation returned may represent multiple actual validation services (which will treat a call to validate() as if all validation services' validate() methods were called). Also, it's possible that no validation service will be returned if there are none associated with the meta property and value.

Parameters:
metaPropertyName - The meta name or id (i.e. className).
metaValue - The value of the meta data (i.e. com.something.someBean)
Returns:
Returns an implementation of the ValidationService interface.

setConfigLocation

protected void setConfigLocation(java.lang.String location)
This is called right after the validation factory is instantiated and the services call (setServices()) has been called. This method informs the factory of the config file that will be used. If it's not in the format that the factory expects, the factory should throw an unchecked exception.

Parameters:
location - The location of the configuration file for the factory. The location is classpath-based.

getConfigLocation

protected java.lang.String getConfigLocation()
Retrieves the configuration file location for this validation factory.

Returns:
Returns the location of the config file. This may be null.

setDefaultLocale

protected void setDefaultLocale(java.util.Locale locale)
Sets the default locale for this factory.

Parameters:
locale - The default locale for this factory.

getDefaultLocale

protected java.util.Locale getDefaultLocale()
Retrieves the default locale for this factory.

Returns:
Returns the default locale for this factory.

setServices

protected void setServices(java.util.Map theServices)
This is called right after the validation factory is instantiated. This map of services is meant to provide the factory with additional, external services that the factory can make available to validation services.

Parameters:
theServices - The services to provide to the factory.

getServices

protected java.util.Map getServices()
Retrieves the map of services available to this factory.

Returns:
Returns the map of services.

loadConfig

protected void loadConfig()
This method is called to initialize the factory. It is called after the services and configuration location have been set. After this call, the factory should be in a state that it can retrieve validation services.