org.iscreen.impl.xml
Class XmlServiceFactory

java.lang.Object
  extended by org.iscreen.ValidationFactory
      extended by org.iscreen.impl.xml.XmlServiceFactory

public class XmlServiceFactory
extends ValidationFactory

This factory constructs a ValidationService based upon an XML configuration (via file or String, etc.). This is the main ValidationFactory implementation (since the XML configuration option is the default configuration type).

Author:
Shellman, Dan

Field Summary
protected  java.util.Map resourceMap
           
protected  java.util.Map setMap
           
protected  java.util.Map validatorMap
           
 
Fields inherited from class org.iscreen.ValidationFactory
configLocation, defaultLocale, FACTORY_DEFAULT_XML, serviceMap
 
Constructor Summary
XmlServiceFactory()
          Default constructor.
 
Method Summary
 void addValidationSetToSet(java.lang.String setId, java.lang.String setRefId, boolean failFastFlag, java.lang.String ifExp, java.lang.String iterateExp, java.lang.String mapExp)
          Adds a validation set reference call to a validation set.
 void addValidatorToSet(java.lang.String setId, java.lang.String globalDefaultResource, java.lang.String defaultResource, java.lang.String validatorRef, boolean failFastFlag, XmlConfigLabel label, java.util.Set mappings, java.util.Set constraints, java.util.Set failures)
          Adds a 'use-validator' to a Validation Set.
protected  void configureValidator(ConfiguredValidator validator, java.lang.String globalDefaultResource, java.lang.String defaultResource, XmlConfigLabel label, java.util.Set mappings, java.util.Set constraints, java.util.Set failures)
          Handles the actual configuration of a Validator, whether via registration or by adding one to a Validation Set.
 ConfiguredResource getResource(java.lang.String id)
          Retrieves a ConfiguredResource for the given id.
 ConfiguredResource getResource(java.lang.String id1, java.lang.String id2, java.lang.String id3)
          Retrieves a resource based upon a set of id's.
 ValidationService getValidationService(java.lang.String serviceName)
          Retrieves a validation service with the given service name.
 ConfiguredValidator getValidator(java.lang.String id)
          Retrieves a ConfiguredValidator with the given id.
protected  void loadConfig()
          Called to initialize the configuration (loads the XML config file).
 void registerInclude(java.lang.String location)
          Registers an included file (for parsing).
 void registerResource(java.lang.String id, java.lang.String ref, java.util.Set messages, java.util.Set resourceFiles)
          Registers a resource with its id (and parent ref, if there is one), hard-coded messages, and resource bundle locations.
 void registerService(java.lang.String serviceId, java.lang.Object service)
          Registers a service with the factory.
 void registerValidationSet(java.lang.String id)
          Registers a Validation Set.
 void registerValidator(java.lang.String globalDefaultResource, java.lang.String id, java.lang.String ref, java.lang.String className, java.lang.String defaultResource, XmlConfigLabel label, java.util.Set mappings, java.util.Set constraints, java.util.Set failures)
          Registers an individual Validator configuration.
 
Methods inherited from class org.iscreen.ValidationFactory
buildFactory, buildFactory, getConfigLocation, getDefaultLocale, getServices, registerFactory, setConfigLocation, setDefaultLocale, setServices
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resourceMap

protected java.util.Map resourceMap

validatorMap

protected java.util.Map validatorMap

setMap

protected java.util.Map setMap
Constructor Detail

XmlServiceFactory

public XmlServiceFactory()
Default constructor.

Method Detail

getValidationService

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

Overrides:
getValidationService in class ValidationFactory
Parameters:
serviceName - The name of the validation service.
Returns:
Returns the validation service with the given name.

registerInclude

public void registerInclude(java.lang.String location)
Registers an included file (for parsing). The location defines a classpath-based location of the XML file.

Parameters:
location - The location of the XML file.

registerResource

public void registerResource(java.lang.String id,
                             java.lang.String ref,
                             java.util.Set messages,
                             java.util.Set resourceFiles)
Registers a resource with its id (and parent ref, if there is one), hard-coded messages, and resource bundle locations. Note that the Set of messages and resource files MUST NOT be null (if there are none, just pass in an empty Set).

Parameters:
id - The unique id of the resource.
ref - The unique id of the parent resource this resource is referencing.
messages - Set of XmlConfigMessage objects (can't be null)
resourceFiles - Set of Strings representing resource bundle locations.

registerValidator

public void registerValidator(java.lang.String globalDefaultResource,
                              java.lang.String id,
                              java.lang.String ref,
                              java.lang.String className,
                              java.lang.String defaultResource,
                              XmlConfigLabel label,
                              java.util.Set mappings,
                              java.util.Set constraints,
                              java.util.Set failures)
Registers an individual Validator configuration. This will create a configured Validator that can be referenced by other Validators or by adding a Validator to a Validation Set.

Parameters:
globalDefaultResource - The resource id, when all else fails.
id - The unique id of the Validator
ref - The unique id of the Validator this Validator references. This can be null and is optional.
className - The class name of the Validator (optional, but if there MUST be a valid ref).
defaultResource - The resource id if no id is defined locally.
label - The Label for the Validator. This is optional.
mappings - The Set of mappings (can't be null, but can be empty).
constraints - The Set of constraints (can't be null, but can be empty).
failures - The Set of failures (can't be null, but can be empty).

registerValidationSet

public void registerValidationSet(java.lang.String id)
Registers a Validation Set.

Parameters:
id - The validation set's unique id.

addValidatorToSet

public void addValidatorToSet(java.lang.String setId,
                              java.lang.String globalDefaultResource,
                              java.lang.String defaultResource,
                              java.lang.String validatorRef,
                              boolean failFastFlag,
                              XmlConfigLabel label,
                              java.util.Set mappings,
                              java.util.Set constraints,
                              java.util.Set failures)
Adds a 'use-validator' to a Validation Set. The 'use-validator' must reference a Validator.

Parameters:
setId - The Validation Set id.
globalDefaultResource - The configuration file's default resource (can be null/empty).
defaultResource - The Validation Set's default resource (optional).
validatorRef - The reference to a Validator (required).
failFastFlag - Whether to stop validations if this validator fails.
label - The label for this validator.
mappings - The mappings for this validator.
constraints - The constraints for this validator.
failures - The failures for this validator.

addValidationSetToSet

public void addValidationSetToSet(java.lang.String setId,
                                  java.lang.String setRefId,
                                  boolean failFastFlag,
                                  java.lang.String ifExp,
                                  java.lang.String iterateExp,
                                  java.lang.String mapExp)
Adds a validation set reference call to a validation set.

Parameters:
setId - The id of the containing Validation Set.
setRefId - The id of the Validation Set being referenced.
failFastFlag - Whether to continue validations if the set reports a failure.
ifExp - Whether to execute the validations in the referenced set.
iterateExp - Whether to iterate over the objects being mapped and validate each one.
mapExp - The mapping expression.

getValidator

public ConfiguredValidator getValidator(java.lang.String id)
Retrieves a ConfiguredValidator with the given id. If one has not been previously registered, then create a blank one.

Parameters:
id - The Validator's id.
Returns:
Returns a Validator with the given id.

getResource

public ConfiguredResource getResource(java.lang.String id)
Retrieves a ConfiguredResource for the given id. If no resource exists with that id, then a blank one is created and returned.

Parameters:
id - The id of the resource
Returns:
Returns a ConfiguredResource for the given id.

getResource

public ConfiguredResource getResource(java.lang.String id1,
                                      java.lang.String id2,
                                      java.lang.String id3)
Retrieves a resource based upon a set of id's. If the 'id1' is a valid resource id, then return that one. If not, and 'id2' is a valid resource id, then return that one. If not, and 'id3' is a valid resource id, then return that one. If none of the id's are valid, then throw an exception.

Parameters:
id1 - The first resource id to look for.
id2 - The second resource id to look for.
id3 - The third resource id to look for.
Returns:
Returns the ConfiguredResource of the first valid resource id.

registerService

public void registerService(java.lang.String serviceId,
                            java.lang.Object service)
Registers a service with the factory. This service can then be referenced by validators via configuration.

Parameters:
serviceId - The service id
service - The service

loadConfig

protected void loadConfig()
Called to initialize the configuration (loads the XML config file).

Overrides:
loadConfig in class ValidationFactory

configureValidator

protected void configureValidator(ConfiguredValidator validator,
                                  java.lang.String globalDefaultResource,
                                  java.lang.String defaultResource,
                                  XmlConfigLabel label,
                                  java.util.Set mappings,
                                  java.util.Set constraints,
                                  java.util.Set failures)
Handles the actual configuration of a Validator, whether via registration or by adding one to a Validation Set.