WebObjects 5.2.3

com.webobjects.foundation
Class NSValidation.DefaultImplementation

java.lang.Object
  extended bycom.webobjects.foundation.NSValidation.DefaultImplementation
Enclosing class:
NSValidation

public static class NSValidation.DefaultImplementation
extends Object

The methods in the NSValidation.DefaultImplementation class are just like the methods defined by the NSValidation interface, except they are static methods and they take an additional argument, which is the object on which the default implementation should operate.

For example, suppose an Employee class implements NSValidation using NSValidation.DefaultImplementation. Employee's validateValueForKey method would then look like this:

public Object validateValueForKey(Object value,String key){ return NSValidation.DefaultImplementation.validateValueForKey(this,value,key)}

The NSValidation.DefaultImplementation methods search for property-specific methods of the form validateKey and invoke them if they exist. Thus an NSValidation class should implement a validate method for each property that has associated validation logic. For example, a validateAge method could check that the value a user enters as an age is within acceptable limits and throw an NSValidation.ValidationException if it finds an unacceptable value.

Because custom validation logic was implemented in the validateKey methods, implementing it from scratch in NSValidation methods is rarely needed. Rather, the default implementation provided by NSValidation.DefaultImplementation is generally sufficient.

Note: Always use the default implementation of NSValidation provided by the foundation package. The default implementations have significant performance optimizations. To benefit from them, implement NSValidation on a custom class as shown above by using the methods in NSValidation.DefaultImplementation or, if your class inherits from an WebObjects class that implements NSValidation, don't override the inherited implementation. Using a custom implementation incurs significant performance penalties.

See Also:
NSValidation.validateValueForKey(java.lang.Object, java.lang.String), NSValidation.validateTakeValueForKeyPath(java.lang.Object, java.lang.String)

Method Summary
static Object validateTakeValueForKeyPath(Object object, Object value, String keyPath)
          Confirms that value is legal for an objects's property, which is named by keyPath, and assigns the value to the property if it's legal (and if value is different from the current value).
static Object validateValueForKey(Object object, Object value, String key)
          Confirms that value is legal for the NSValidation's property, which is named by key, and returns the validated value if it's legal, or throws an NSValidation.ValidationException if it isn't.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

validateTakeValueForKeyPath

public static Object validateTakeValueForKeyPath(Object object,
                                                 Object value,
                                                 String keyPath)
                                          throws NSValidation.ValidationException
Confirms that value is legal for an objects's property, which is named by keyPath, and assigns the value to the property if it's legal (and if value is different from the current value).

Parameters:
object - object on the destination showed by the keypath
value - value corresponding to the keypath
keyPath - relative path of the method
Returns:
NSValidation implementor with the new value assigned to it
Throws:
NSValidation.ValidationException - value isn't legal to NSValidation
See Also:
NSValidation.validateTakeValueForKeyPath(java.lang.Object, java.lang.String)

validateValueForKey

public static Object validateValueForKey(Object object,
                                         Object value,
                                         String key)
                                  throws NSValidation.ValidationException
Confirms that value is legal for the NSValidation's property, which is named by key, and returns the validated value if it's legal, or throws an NSValidation.ValidationException if it isn't.

Parameters:
object - object on the destination showed by the keypath
value - value corresponding to the keypath
key - property of object
Returns:
the new value for the NSValidation's implementor
Throws:
NSValidation.ValidationException - value isn't legal to NSValidation
See Also:
NSValidation.validateValueForKey(java.lang.Object, java.lang.String)

Last updated Thu Oct 21 15:04:16 PDT 2004.

Copyright © 2004 Apple Computer, Inc.