ERXValidationFactory Class Reference

Collaboration diagram for ERXValidationFactory:

Collaboration graph
[legend]

List of all members.

Classes

interface  ExceptionDelegateInterface
interface  FactoryInterface

Public Member Functions

void configureFactory ()
NSKeyValueCoding contextForException (ERXValidationException erv)
ERXValidationException convertException (NSValidation.ValidationException eov, Object value)
ERXValidationException convertException (NSValidation.ValidationException eov)
ERXValidationException createCustomException (EOEnterpriseObject eo, String property, Object value, String method)
ERXValidationException createCustomException (EOEnterpriseObject eo, String method)
ERXValidationException createException (EOEnterpriseObject eo, String property, Object value, String type)
String messageForException (ERXValidationException erv)
void resetTemplateCache (NSNotification n)
void setDelimiter (String delimiter)
void setValidationExceptionClass (Class class1)
boolean shouldRecreateException (ERXValidationException erv, Object value)
String templateDelimiter ()
String templateForException (ERXValidationException erv)
String templateForKeyPath (String key, String language)
Class validationExceptionClass ()

Static Public Member Functions

static Object defaultDelegate ()
static ERXValidationFactory defaultFactory ()
static void setDefaultDelegate (Object obj)
static void setDefaultFactory (ERXValidationFactory aFactory)

Static Public Attributes

static final Logger log = Logger.getLogger(ERXValidationFactory.class)
static final String VALIDATION_TEMPLATE_PREFIX = "ValidationTemplate."

Protected Member Functions

NSArray convertAdditionalExceptions (NSValidation.ValidationException ex)
Constructor regularValidationExceptionConstructor ()
String templateForEntityPropertyType (String entityName, String property, String type, String targetLanguage)

Protected Attributes

Constructor regularConstructor

Static Package Functions

 [static initializer]

Private Attributes

Hashtable _cache = new Hashtable(1000)
String _delimiter = "@@"
Class _validationExceptionClass

Static Private Attributes

static ERXValidationFactory _defaultFactory
static Object _defaultValidationDelegate = null
static NSDictionary _mappings
static Class[] _regularConstructor = new Class[] { String.class, Object.class, String.class, Object.class }
static final Class[] EDI_FE_ARGS = new Class[] { ERXValidationException.class }
static final String EDI_MFE_METHOD_NAME = "messageForException"
static final String EDI_TFE_METHOD_NAME = "templateForException"
static final String UNDEFINED_VALIDATION_TEMPLATE = "Undefined Validation Template"


Detailed Description

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

Member Function Documentation

[static initializer] (  )  [static, package]

In the static initializer the mapping dictionary is created.

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.

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

NSArray convertAdditionalExceptions ( NSValidation.ValidationException  ex  )  [protected]

Converts the additional exceptions contained in an Exception to ERXValidationException subclasses.

Parameters:
ex validation exception
Returns:
NSArray of converted exceptions

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

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

ERXValidationException createCustomException ( EOEnterpriseObject  eo,
String  property,
Object  value,
String  method 
)

Creates a custom validation exception. This is the preferred 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

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 argument method specifying null for property and value.

Parameters:
eo enterprise object failing validation
method name of the method to use to look up the validation exception template, for instance "FirstNameCanNotMatchLastNameValidationException"
Returns:
a custom validation exception for the given criteria

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

static Object defaultDelegate (  )  [static]

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.

static ERXValidationFactory defaultFactory (  )  [static]

Returns the default factory. If one has not been set then a factory is created of type ERXValidationFactory.

Returns:
the default validation factory

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

Constructor regularValidationExceptionConstructor (  )  [protected]

Simple method used to lookup and cache the constructor to build validation exceptions.

Returns:
constructor used to build validation exceptions

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.

static void setDefaultDelegate ( Object  obj  )  [static]

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

static void setDefaultFactory ( ERXValidationFactory  aFactory  )  [static]

Sets the default factory to be used for converting model thrown exceptions.

Parameters:
aFactory new factory

void setDelimiter ( String  delimiter  ) 

sets the template delimiter to be used when parsing templates for creating validation exception messages.

Parameters:
delimiter to be set.

void setValidationExceptionClass ( Class  class1  ) 

Sets the validation class to be used when creating validation exceptions.

Parameters:
class1 validation exception class

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

String templateDelimiter (  ) 

Returns the template delimiter, the default delimiter is "@".

Returns:
template delimiter

String templateForEntityPropertyType ( String  entityName,
String  property,
String  type,
String  targetLanguage 
) [protected]

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

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

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

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.


Member Data Documentation

Hashtable _cache = new Hashtable(1000) [private]

holds the template cache for a given set of keys

holds a reference to the default validation factory

Object _defaultValidationDelegate = null [static, private]

holds a reference to the default validation delegate

String _delimiter = "@@" [private]

holds the default template delimiter, "@@"

NSDictionary _mappings [static, private]

holds the default mappings that map model thrown validation strings to exception types

Class [] _regularConstructor = new Class[] { String.class, Object.class, String.class, Object.class } [static, private]

Regular ERXValidationException constructor parameters

Class _validationExceptionClass [private]

holds the validation exception class

final Class [] EDI_FE_ARGS = new Class[] { ERXValidationException.class } [static, private]

holds the class argument array for delegate validation exception messages

final String EDI_MFE_METHOD_NAME = "messageForException" [static, private]

holds the method name 'messageForException'

final String EDI_TFE_METHOD_NAME = "templateForException" [static, private]

holds the method name 'templateForException'

final Logger log = Logger.getLogger(ERXValidationFactory.class) [static]

logging support

Constructor regularConstructor [protected]

caches the constructor used to build validation exceptions

final String UNDEFINED_VALIDATION_TEMPLATE = "Undefined Validation Template" [static, private]

holds the marker for an un defined validation template

final String VALIDATION_TEMPLATE_PREFIX = "ValidationTemplate." [static]

holds the value 'ValidationTemplate.'


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:17 2012 for Project Wonder by  doxygen 1.5.8