org.iscreen.impl.xml
Class XmlServiceFactory

java.lang.Object
  extended by org.iscreen.ValidationFactory
      extended by org.iscreen.impl.xml.XmlServiceFactory
Direct Known Subclasses:
MvelXmlServiceFactory, OgnlXmlServiceFactory

public abstract class XmlServiceFactory
extends ValidationFactory

This is a base class used by the parser for registering configuration events with a ValidationFactory. It's meant to be subclassed by a service factory that understands the XML configuration file and can construct the internal configuration of it.

Author:
Shellman, Dan

Field Summary
static java.lang.String DEFAULT_META
           
protected  java.util.Map metaMap
           
protected  int parseCount
           
protected  java.util.Set parsedDocuments
           
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, FACTORY_MVEL_XML, FACTORY_OGNL_XML, serviceMap
 
Constructor Summary
XmlServiceFactory()
          Default constructor.
 
Method Summary
 void addMetaToValidationSet(java.lang.String setId, java.lang.String propertyName, java.lang.String metaValue)
          Adds meta information about a validation set.
abstract  void addValidationSetToSet(java.lang.String setId, java.lang.String setRefId, boolean failFastFlag, java.lang.String name, java.lang.String ifExp, java.lang.String iterateExp, java.lang.String mapExp)
          Adds a validation set reference call to a validation set.
abstract  void addValidatorToSet(java.lang.String setId, java.lang.String globalDefaultResource, java.lang.String defaultResource, java.lang.String validatorRef, boolean failFastFlag, java.lang.String validatorName, java.lang.String ifExp, XmlConfigLabel label, XmlConfigDoc doc, java.util.Set mappings, java.util.Set constraints, java.util.Set failures)
          Adds a 'use-validator' to a Validation Set.
 void endParse()
          Decrements the parse count
 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.
 ValidationService getValidationService(java.lang.String metaPropertyName, java.lang.String metaValue)
          Retrieves a validation service with the given meta property and value.
protected  DefaultValidationService getValidationSet(java.lang.String refId)
          Retrieves a DefaultValidationService 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.
abstract  void registerValidationSet(java.lang.String id)
          Registers a Validation Set.
abstract  void registerValidator(java.lang.String globalDefaultResource, java.lang.String id, java.lang.String ref, java.lang.String className, java.lang.String defaultResource, XmlConfigLabel label, XmlConfigDoc doc, java.util.Set mappings, java.util.Set constraints, java.util.Set failures)
          Registers an individual Validator configuration.
 void startParse()
          Increments the parse count
 
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

DEFAULT_META

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

resourceMap

protected java.util.Map resourceMap

validatorMap

protected java.util.Map validatorMap

setMap

protected java.util.Map setMap

metaMap

protected java.util.Map metaMap

parsedDocuments

protected java.util.Set parsedDocuments

parseCount

protected int parseCount
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.

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.

Overrides:
getValidationService in class ValidationFactory
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.

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.

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.

registerValidator

public abstract void registerValidator(java.lang.String globalDefaultResource,
                                       java.lang.String id,
                                       java.lang.String ref,
                                       java.lang.String className,
                                       java.lang.String defaultResource,
                                       XmlConfigLabel label,
                                       XmlConfigDoc doc,
                                       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.
doc - The documentation 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 abstract void registerValidationSet(java.lang.String id)
Registers a Validation Set.

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

addMetaToValidationSet

public void addMetaToValidationSet(java.lang.String setId,
                                   java.lang.String propertyName,
                                   java.lang.String metaValue)
Adds meta information about a validation set.

Parameters:
setId - The validation set id.
propertyName - The name or id of the meta tag.
metaValue - The value of the meta information.

addValidatorToSet

public abstract void addValidatorToSet(java.lang.String setId,
                                       java.lang.String globalDefaultResource,
                                       java.lang.String defaultResource,
                                       java.lang.String validatorRef,
                                       boolean failFastFlag,
                                       java.lang.String validatorName,
                                       java.lang.String ifExp,
                                       XmlConfigLabel label,
                                       XmlConfigDoc doc,
                                       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.
validatorName - The name of the validator.
ifExp - The 'if' expression on whether to execute this validator or not.
label - The label for this validator.
doc - The documentation for this validator.
mappings - The mappings for this validator.
constraints - The constraints for this validator.
failures - The failures for this validator.

addValidationSetToSet

public abstract void addValidationSetToSet(java.lang.String setId,
                                           java.lang.String setRefId,
                                           boolean failFastFlag,
                                           java.lang.String name,
                                           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.

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

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.

loadConfig

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

Overrides:
loadConfig in class ValidationFactory

startParse

public void startParse()
Increments the parse count


endParse

public void endParse()
Decrements the parse count


getValidationSet

protected DefaultValidationService getValidationSet(java.lang.String refId)
Retrieves a DefaultValidationService with the given id. If one has not been previously registered, then create a blank one.

Parameters:
id - The Validation Set id.
Returns:
Returns a DefaultValidationService with the given id.