Project Wonder 2.0

er.extensions
Class ERXValidationException

java.lang.Object
  extended byjava.lang.Throwable
      extended byjava.lang.Exception
          extended byjava.lang.RuntimeException
              extended bycom.webobjects.foundation.NSValidation.ValidationException
                  extended byer.extensions.ERXValidationException
All Implemented Interfaces:
NSKeyValueCoding, Serializable

public class ERXValidationException
extends NSValidation.ValidationException
implements NSKeyValueCoding

ERXValidationExceptions extends the regular NSValidation.ValidationException to add template based resolution of the validation exception. See more information about resolving templates in the ERXValidationFactory.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding
NSKeyValueCoding._BooleanFieldBinding, NSKeyValueCoding._BooleanMethodBinding, NSKeyValueCoding._FieldBinding, NSKeyValueCoding._ForwardingBinding, NSKeyValueCoding._KeyBinding, NSKeyValueCoding._KeyBindingCreation, NSKeyValueCoding._MethodBinding, NSKeyValueCoding._NumberFieldBinding, NSKeyValueCoding._NumberMethodBinding, NSKeyValueCoding._ReflectionKeyBindingCreation, NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor
 
Field Summary
protected  NSKeyValueCoding _context
          holds a reference to the context of the exception
protected  NSArray additionalExceptions
          caches any set additionalExceptions
static String CustomMethodException
          corresponds to a custom method exception
protected  Object delegate
          holds a reference to the exception delegate
static String ExceedsMaximumLengthException
          corresponds to a model thrown 'maximum length of attribute exceeded' exception
static String InvalidNumberException
          corresponds to a number formatter exception
static ERXLogger log
          logging support
static String MandatoryToManyRelationshipException
          corresponds to a model thrown 'manditory toMany relationship' exception
static String MandatoryToOneRelationshipException
          corresponds to a model thrown 'mandatory toOne relationship' exception
protected  String message
          caches the validation message
protected  String method
          holds the method if one is provided
static String NullPropertyException
          corresponds to a model thrown 'null property' exception
protected  Object object
          holds the object that failed validation
static String ObjectRemovalException
          corresponds to a model thrown 'object removal' exception
static String ObjectsRemovalException
          corresponds to a model thrown 'objects removal' exception
protected  String targetLanguage
          holds the target language if provided
protected  String type
          holds the type of the exception
protected  Object value
          holds the value that failed validation
static String ValueConversionException
          corresponds to a model thrown 'Error converting value of class' exception
 
Fields inherited from class com.webobjects.foundation.NSValidation.ValidationException
_CLASS, AdditionalExceptionsKey, ValidatedKeyUserInfoKey, ValidatedObjectUserInfoKey
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding
_CLASS, NullValue
 
Constructor Summary
ERXValidationException(String type, Object object, String key)
          Default constructor that builds a validation exception without the failed value specified.
ERXValidationException(String type, Object object, String key, Object value)
          Default constructor that builds a validation exception based on the type, object, key and failed value.Usually for creating custom validation exceptions the ERXValidationFactory should be used.
 
Method Summary
 NSArray additionalExceptions()
          Cover method to return any additional exceptions that occurred.
 EOAttribute attribute()
          Cover method for getting the attribute corresponding to the propertyKey and entity off of the objet.
 NSKeyValueCoding context()
          The current context of the validation exception.
 Object delegate()
          Gets the current delegate for this validation exception.
 String displayNameForEntity()
          Generates a displayable and localized version of the current object's entity name.
 String displayNameForProperty()
          Generates a displayable and localized version of the current propertyKey (also called key).
 EOEnterpriseObject eoObject()
          Cover method that casts the object of the validation exception to an EOEnterpriseObject.
 boolean equals(Object anotherObject)
          Compares this exception to anything else.
 String getMessage()
          Gets the message for this exception.
 boolean isCustomMethodException()
          Convience method to determine if this exception was a custom thrown exception instead of a model thrown exception.
protected  String localizedDisplayNameForKey(String key)
          Creates a localized display name for a given key using the class description's displayNameForKey and then using a localizer for the current "targetLanguage" or the current localizer to translate the string.
 String method()
          Returns method name.
 Object object()
          Overrides super implementation to allow for setable object value.
 String propertyKey()
          Cover method for returning the key of the validation exception under the name propertyKey.
 void setAdditionalExceptions(NSArray exceptions)
          Sets the array of additional exceptions that has occurried.
 void setContext(NSKeyValueCoding context)
          Sets the context that can be used to resolve key bindings in validation templates.
 void setDelegate(Object obj)
          Sets the delegate for the current validation exception.
 void setMethod(String aMethod)
          Sets the custom method name that threw the validation exception.
 void setObject(Object aValue)
          Sets the object that failed validation.
 void setTargetLanguage(String aValue)
          Sets the target language to use when rendering the validation message.
 void setType(String aType)
          Sets the validation type of this exception.
 void setValue(Object aValue)
          Sets the value that failed validation.
 void takeValueForKey(Object obj, String key)
          Implementation of the key value coding.
 String targetLanguage()
          Returns the target language to display the validation message in.
 String toString()
          Returns the formatted description of the validation exception without calling getMessage.
 String type()
          Cover method to return the type of the validation exception.
 Object value()
          Returns the value that failed validation.
 Object valueForKey(String key)
          Implementation of key value coding.
 
Methods inherited from class com.webobjects.foundation.NSValidation.ValidationException
aggregateExceptionWithExceptions, exceptionAddingEntriesToUserInfo, exceptionWithObjectAndKey, key, userInfo
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support


NullPropertyException

public static final String NullPropertyException
corresponds to a model thrown 'null property' exception

See Also:
Constant Field Values

InvalidNumberException

public static final String InvalidNumberException
corresponds to a number formatter exception

See Also:
Constant Field Values

MandatoryToOneRelationshipException

public static final String MandatoryToOneRelationshipException
corresponds to a model thrown 'mandatory toOne relationship' exception

See Also:
Constant Field Values

MandatoryToManyRelationshipException

public static final String MandatoryToManyRelationshipException
corresponds to a model thrown 'manditory toMany relationship' exception

See Also:
Constant Field Values

ObjectRemovalException

public static final String ObjectRemovalException
corresponds to a model thrown 'object removal' exception

See Also:
Constant Field Values

ObjectsRemovalException

public static final String ObjectsRemovalException
corresponds to a model thrown 'objects removal' exception

See Also:
Constant Field Values

ExceedsMaximumLengthException

public static final String ExceedsMaximumLengthException
corresponds to a model thrown 'maximum length of attribute exceeded' exception

See Also:
Constant Field Values

ValueConversionException

public static final String ValueConversionException
corresponds to a model thrown 'Error converting value of class' exception

See Also:
Constant Field Values

CustomMethodException

public static final String CustomMethodException
corresponds to a custom method exception

See Also:
Constant Field Values

message

protected String message
caches the validation message


method

protected String method
holds the method if one is provided


type

protected String type
holds the type of the exception


value

protected Object value
holds the value that failed validation


object

protected Object object
holds the object that failed validation


targetLanguage

protected String targetLanguage
holds the target language if provided


additionalExceptions

protected NSArray additionalExceptions
caches any set additionalExceptions


_context

protected volatile NSKeyValueCoding _context
holds a reference to the context of the exception


delegate

protected volatile Object delegate
holds a reference to the exception delegate

Constructor Detail

ERXValidationException

public ERXValidationException(String type,
                              Object object,
                              String key)
Default constructor that builds a validation exception without the failed value specified. If you want to have validation templates that refer to the value that didn't pass validation use the four argument constructor. Usually for creating custom validation exceptions the ERXValidationFactory should be used.

Parameters:
type - of the exception, should be one of the constaints defined in this class.
object - that is throwing the exception
key - property key that failed validation

ERXValidationException

public ERXValidationException(String type,
                              Object object,
                              String key,
                              Object value)
Default constructor that builds a validation exception based on the type, object, key and failed value.Usually for creating custom validation exceptions the ERXValidationFactory should be used.

Parameters:
type - of the exception, should be one of the constaints defined in this class.
object - that is throwing the exception
key - property key that failed validation
value - that failed validation
Method Detail

getMessage

public String getMessage()
Gets the message for this exception.

Returns:
the correctly formatted validation exception.

valueForKey

public Object valueForKey(String key)
Implementation of key value coding. Uses the default implementation.

Specified by:
valueForKey in interface NSKeyValueCoding
Parameters:
key - to look up
Returns:
result of the lookup on the object

takeValueForKey

public void takeValueForKey(Object obj,
                            String key)
Implementation of the key value coding. Uses the default implementation.

Specified by:
takeValueForKey in interface NSKeyValueCoding
Parameters:
obj - value to be set on this exception
key - to be set

isCustomMethodException

public boolean isCustomMethodException()
Convience method to determine if this exception was a custom thrown exception instead of a model thrown exception. A custom exception would be an exception that you throw in your validateFoo method if a particular constraint is not valid.

Returns:
if this exception is a custom thrown exception.

method

public String method()
Returns method name. The method name is only set if the validation exception is a custom validation exception.

Returns:
custom method name.

setMethod

public void setMethod(String aMethod)
Sets the custom method name that threw the validation exception.

Parameters:
aMethod - name to be set.

eoObject

public EOEnterpriseObject eoObject()
Cover method that casts the object of the validation exception to an EOEnterpriseObject.

Returns:
object cast as an enterprise object.

object

public Object object()
Overrides super implementation to allow for setable object value.

Returns:
object object for this exception.

propertyKey

public String propertyKey()
Cover method for returning the key of the validation exception under the name propertyKey.

Returns:
the key of the validation exception

attribute

public EOAttribute attribute()
Cover method for getting the attribute corresponding to the propertyKey and entity off of the objet.

Returns:
EOAttribute corresponding to the propertyKey and entity.

type

public String type()
Cover method to return the type of the validation exception. The corresponds to one of the constant strings defined in this class.

Returns:
the type of this validation exception.

setType

public void setType(String aType)
Sets the validation type of this exception. Should correspond to one of the type constants defined in this class. All of the model thrown validation exceptions should have the correct type already set.

Parameters:
aType - name to set on this validation exception.

value

public Object value()
Returns the value that failed validation.

Returns:
failed validation value.

setValue

public void setValue(Object aValue)
Sets the value that failed validation.

Parameters:
aValue - that failed validation

setObject

public void setObject(Object aValue)
Sets the object that failed validation.

Parameters:
aValue - object that failed validation

targetLanguage

public String targetLanguage()
Returns the target language to display the validation message in. If a target language is not set then the current default language for the current thread is used.

Returns:
target language if one is set.

setTargetLanguage

public void setTargetLanguage(String aValue)
Sets the target language to use when rendering the validation message. Only set a target language if you want to override the current language of the thread.

Parameters:
aValue - name fo the language to render the validation exception in.

delegate

public Object delegate()
Gets the current delegate for this validation exception. If one is not set then the default delegate for the ERXValidationFactory is returned.

Returns:
delegate for this validation exception.

setDelegate

public void setDelegate(Object obj)
Sets the delegate for the current validation exception. The delegate can intervine to provide a different template for the validation exception or resolve the template in a different manner.

Parameters:
obj - delegate to be used for this validation exception.

context

public NSKeyValueCoding context()
The current context of the validation exception. Context objects are mainly used for resolving keys in validation templates. When validation exceptions are thrown in D2W pages the current D2WContext is set as the current context on the exceptions. If a context is not set then the contextForException is called off of the default ERXValidationFactory. When this also returns null, then the exception will be used as its context. This is needed because of some of the templates in ERDirectToWeb which use context.propertyKey and will display ? if none is given.

Returns:
current context for the validation exception.

setContext

public void setContext(NSKeyValueCoding context)
Sets the context that can be used to resolve key bindings in validation templates.

Parameters:
context - of the current exception

setAdditionalExceptions

public void setAdditionalExceptions(NSArray exceptions)
Sets the array of additional exceptions that has occurried.

Parameters:
exceptions - array of additional exceptions

additionalExceptions

public NSArray additionalExceptions()
Cover method to return any additional exceptions that occurred. The reason this method is needed is because we wanted to have the ability to set the additional exceptions.

Returns:
array of additional exceptions

displayNameForProperty

public String displayNameForProperty()
Generates a displayable and localized version of the current propertyKey (also called key).

Returns:
localized displayable version of the current propertyKey.

displayNameForEntity

public String displayNameForEntity()
Generates a displayable and localized version of the current object's entity name.

Returns:
localized displayable version of an object's entity name.

localizedDisplayNameForKey

protected String localizedDisplayNameForKey(String key)
Creates a localized display name for a given key using the class description's displayNameForKey and then using a localizer for the current "targetLanguage" or the current localizer to translate the string.

Parameters:
key - to be translated
Returns:
localized and display version of the given key.

equals

public boolean equals(Object anotherObject)
Compares this exception to anything else.

Returns:
description of the validation exception

toString

public String toString()
Returns the formatted description of the validation exception without calling getMessage.

Returns:
description of the validation exception

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

Copyright © 2002 – 2004 Project Wonder.