Project Wonder 2.0

er.extensions
Class ERXValidationFactory

java.lang.Object
  extended byer.extensions.ERXValidationFactory

public class ERXValidationFactory
extends Object

The validation factory controls creating validation exceptions, both from model thrown exceptions and custom validation exceptions. The factory is responsible for resolving validation remplates for validation exceptions and generating validation messages.


Nested Class Summary
static interface ERXValidationFactory.ExceptionDelegateInterface
          Exception delegates can be used to provide hooks to customize how messages are generated for validation exceptions and how tempates are looked up.
static interface ERXValidationFactory.FactoryInterface
          The validation factory interface.
 
Field Summary
static ERXLogger log
          logging support
protected  Constructor regularConstructor
          caches the constructor used to build validation exceptions
static String VALIDATION_TEMPLATE_PREFIX
          holds the value 'ValidationTemplate.'
 
Constructor Summary
ERXValidationFactory()
           
 
Method Summary
 void configureFactory()
          Method used to configure the validation factory for operation.
 NSKeyValueCoding contextForException(ERXValidationException erv)
          The context for a given validation exception can be used to resolve keys in validation template.
protected  NSArray convertAdditionalExceptions(NSValidation.ValidationException ex)
          Converts the additional exceptions contained in an Exception to ERXValidationException subclasses.
 ERXValidationException convertException(NSValidation.ValidationException eov)
          Converts a model thrown validation exception into an ERXValidationException.
 ERXValidationException convertException(NSValidation.ValidationException eov, Object value)
          Converts a given model thrown validation exception into an ERXValidationException.
 ERXValidationException createCustomException(EOEnterpriseObject eo, String method)
          Creates a custom validation exception for a given enterprise object and method.
 ERXValidationException createCustomException(EOEnterpriseObject eo, String property, Object value, String method)
          Creates a custom validation exception.
 ERXValidationException createException(EOEnterpriseObject eo, String property, Object value, String type)
          Entry point for creating validation exceptions.
static Object defaultDelegate()
          Returns the default validation delegate that will be set on all validation exceptions created.
static ERXValidationFactory defaultFactory()
          Returns the default factory.
 String messageForException(ERXValidationException erv)
          Entry point for generating an exception message for a given message.
protected  Constructor regularValidationExceptionConstructor()
          Simple method used to lookup and cache the constructor to build validation exceptions.
 void resetTemplateCache(NSNotification n)
          Called when the Localizer is reset.
static void setDefaultDelegate(Object obj)
          Sets the default validation delegate that will be set on all validation exceptions that are created by the factory.
static void setDefaultFactory(ERXValidationFactory aFactory)
          Sets the default factory to be used for converting model thrown exceptions.
 void setDelimiter(String delimiter)
          sets the template delimiter to be used when parsing templates for creating validation exception messages.
 void setValidationExceptionClass(Class class1)
          Sets the validation class to be used when creating validation exceptions.
 boolean shouldRecreateException(ERXValidationException erv, Object value)
          Decides if an existing ERXValidationException should be re-created.
 String templateDelimiter()
          Returns the template delimiter, the default delimiter is "@".
protected  String templateForEntityPropertyType(String entityName, String property, String type, String targetLanguage)
          Finds a template for a given entity, property key, exception type and target language.
 String templateForException(ERXValidationException erv)
          Entry point for finding a template for a given validation exception.
 String templateForKeyPath(String key, String language)
          Get the template for a given key in a given language.
 Class validationExceptionClass()
          Returns the validation exception class to use when creating exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support


VALIDATION_TEMPLATE_PREFIX

public static final String VALIDATION_TEMPLATE_PREFIX
holds the value 'ValidationTemplate.'

See Also:
Constant Field Values

regularConstructor

protected Constructor regularConstructor
caches the constructor used to build validation exceptions

Constructor Detail

ERXValidationFactory

public ERXValidationFactory()
Method Detail

setDefaultFactory

public static void setDefaultFactory(ERXValidationFactory aFactory)
Sets the default factory to be used for converting model thrown exceptions.

Parameters:
aFactory - new factory

defaultFactory

public static ERXValidationFactory defaultFactory()
Returns the default factory. If one has not been set then a factory is created of type ERXValidationFactory.

Returns:
the default validation factory

defaultDelegate

public static Object defaultDelegate()
Returns the default validation delegate that will be set on all validation exceptions created. At the moment delegates should implement the ExceptionDelegateInterface. This will change to an informal implementation soon.

Returns:
the default validation exception delegate.

setDefaultDelegate

public static void setDefaultDelegate(Object obj)
Sets the default validation delegate that will be set on all validation exceptions that are created by the factory. At the moment the delegate set needs to implement the interface ExceptionDelegateInterface.

Parameters:
obj - default validation delegate

setValidationExceptionClass

public void setValidationExceptionClass(Class class1)
Sets the validation class to be used when creating validation exceptions.

Parameters:
class1 - validation exception class

validationExceptionClass

public Class validationExceptionClass()
Returns the validation exception class to use when creating exceptions. If none is specified ERXValidationException is used.

Returns:
class object of validation exceptions to be used.

regularValidationExceptionConstructor

protected Constructor regularValidationExceptionConstructor()
Simple method used to lookup and cache the constructor to build validation exceptions.

Returns:
constructor used to build validation exceptions

createException

public ERXValidationException createException(EOEnterpriseObject eo,
                                              String property,
                                              Object value,
                                              String type)
Entry point for creating validation exceptions. This method is used by all of the other methods to create validation exceptions for an enterprise object, a property key, a value and a type. The type should correspond to one of the validation exception types defined in ERXValidationException.

Parameters:
eo - enterprise object that is failing validation
property - attribute that failed validation
value - that failed validating
type - of the validation exception
Returns:
validation exception for the given information

shouldRecreateException

public boolean shouldRecreateException(ERXValidationException erv,
                                       Object value)
Decides if an existing ERXValidationException should be re-created. This is useful if you have several subclasses of exceptions for different types of objects or messages and the framework can only convert to the base type given the information it has at that point.

Parameters:
erv - previous validation exception
value - value that failed validating
Returns:
yes if the exception should be recreated

createCustomException

public ERXValidationException createCustomException(EOEnterpriseObject eo,
                                                    String method)
Creates a custom validation exception for a given enterprise object and method. This method is just a cover method for calling the four arguement method specifying null for proptery and value.

Parameters:
eo - enterprise object failing validation
Returns:
a custom validation exception for the given criteria

createCustomException

public ERXValidationException createCustomException(EOEnterpriseObject eo,
                                                    String property,
                                                    Object value,
                                                    String method)
Creates a custom validation exception. This is the prefered way of creating custom validation exceptions.

Parameters:
eo - enterprise object failing validation
property - attribute that failed validation
value - that failed validation
method - unique identified usually corresponding to a method name to pick up the validation template
Returns:
custom validation exception

convertException

public ERXValidationException convertException(NSValidation.ValidationException eov)
Converts a model thrown validation exception into an ERXValidationException. This is a cover method for the two argument version passing in null as the value.

Parameters:
eov - validation exception to be converted
Returns:
converted validation exception

convertException

public ERXValidationException convertException(NSValidation.ValidationException eov,
                                               Object value)
Converts a given model thrown validation exception into an ERXValidationException. This method is used by ERXEntityClassDescription to convert model thrown validation exceptions. This isn't a very elegant solution, but until we can register our our validation exception class this is what we have to do.

Parameters:
eov - validation exception to be converted
value - that failed validation
Returns:
converted validation exception

convertAdditionalExceptions

protected NSArray convertAdditionalExceptions(NSValidation.ValidationException ex)
Converts the additional exceptions contained in an Exception to ERXValidationException subclasses.

Parameters:
ex - validation exception
Returns:
NSArray of converted exceptions

messageForException

public String messageForException(ERXValidationException erv)
Entry point for generating an exception message for a given message. The method getMessage off of ERXValidationException calls this method passing in itself as the parameter.

Parameters:
erv - validation exception
Returns:
a localized validation message for the given exception

templateForException

public String templateForException(ERXValidationException erv)
Entry point for finding a template for a given validation exception. Override this method to provide your own template resolution scheme.

Parameters:
erv - validation exception
Returns:
validation template for the given exception

resetTemplateCache

public void resetTemplateCache(NSNotification n)
Called when the Localizer is reset. This will reset the template cache.

Parameters:
n - notification posted when the localizer is reset.

contextForException

public NSKeyValueCoding contextForException(ERXValidationException erv)
The context for a given validation exception can be used to resolve keys in validation template. If a context is not provided for a validation exception then this method will be called if a context is needed for a validation exception. Override this method if you want to provide your own default contexts to validation exception template parsing.

Parameters:
erv - a given validation exception
Returns:
context to be used for this validation exception

templateDelimiter

public String templateDelimiter()
Returns the template delimiter, the default delimiter is "@".

Returns:
template delimiter

setDelimiter

public void setDelimiter(String delimiter)
sets the template delimiter to be used when parsing templates for creating validation exception messages.

Parameters:
delimiter - to be set.

configureFactory

public void configureFactory()
Method used to configure the validation factory for operation. This method is called on the default factory from an observer when the application is finished launching.


templateForEntityPropertyType

protected String templateForEntityPropertyType(String entityName,
                                               String property,
                                               String type,
                                               String targetLanguage)
Finds a template for a given entity, property key, exception type and target language. This method provides the defaulting behaviour needed to handle model thrown validation exceptions.

Parameters:
entityName - name of the entity
property - key name
type - validation exception type
targetLanguage - target language name
Returns:
a templaet for the given set of parameters

templateForKeyPath

public String templateForKeyPath(String key,
                                 String language)
Get the template for a given key in a given language. Uses ERXLocalizer to handle the actual lookup.

Returns:
template for key or null if none is found

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.