|
WebObjects 5.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The EOKeyValueCodingAdditions combines (extends) the NSKeyValueCoding,
NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions and EOKeyValueCoding and adds
two more methods--takeValuesFromDictionary
and valuesForKeys
--
which are useful when working with groups of properties.
The EOKeyValueCodingAdditions interface contains two inner classes, EOKeyValueCodingAdditions.DefaultImplementation and EOKeyValueCodingAdditions.Utility. The former provides a default implementation of the interface, making it easy to implement on your own custom classes. The latter is a convenience class that allows you to access the properties of EOKeyValueCodingAdditions objects and non-EOKeyValueCodingAdditions objects using the same code.
Null ValuesSince the WebObjects collections such as NSArray and NSDictionary can't contain
null
as a value, null
must be represented by a special object,
NSKeyValueCoding.NullValue. NSKeyValueCoding.NullValue is a single instance of the
NSKeyValueCoding.Null class and is used by the key-value coding implementations inside
the WebObjects collections.
The default implementations of takeValuesFromDictionary
and
valuesForKeys
translate NSKeyValueCoding.NullValue and null
between NSDictionaries and enterprise objects so the objects don't have to explicitly
test for NSKeyValueCoding.NullValue.
The methods in the EOKeyValueCodingAdditions.DefaultImplementation class are just like the methods defined by the EOKeyValueCodingAdditions interface, except they are static methods and they take an extra argument - the object on which the default implementation should operate.
For example, suppose you want to implement an Employee class that implements
EOKeyValueCodingAdditions using EOKeyValueCodingAdditions.DefaultImplementation.
Employee's valuesForKeys
method would then look like this:
public Object valuesForKeys(NSArray keys) { return EOKeyValueCodingAdditions.DefaultImplementation.valuesForKeys(this, keys); }
Note:Always try to use the default implementation of EOKeyValueCodingAdditions. The default implementations have significant performance optimizations. To benefit from them, EOKeyValueCodingAdditions can be implemented on a custom class as shown above by using the methods in EOKeyValueCodingAdditions.DefaultImplementation; or if your class inherits from an EOF class that implements EOKeyValueCodingAdditions, don't override the inherited implementation. Using a custom implementation incurs significant performance penalties.
UtilityRecall that the EOKeyValueCodingAdditions.Utility class is a convenience that allows you to access the properties of EOKeyValueCodingAdditions objects and non-EOKeyValueCodingAdditions objects using the same code.
Utility's methods are similar to DefaultImplementation's methods in that they are static methods and they take an extra argument, the object on which the method should operate. However, Utility's methods simply check to see if the object on which they operate is an EOKeyValueCodingAdditions object and invoke the corresponding EOKeyValueCodingAdditions method on the object if it is. Otherwise, they invoke the corresponding DefaultImplementation method, passing the object on which to operate.
For example, suppose that you want to access an object with the EOKeyValueCodingAdditions API but you don't know if the object is an EOKeyValueCodingAdditions object. To do so, you simply use the corresponding Utility API, as in the following line of code:
value = EOKeyValueCodingAdditions.Utility.valuesForKeys(keys);
The above line of code is essentially a short-cut for the following:
if (object instanceof EOKeyValueCodingAdditions) { value = ((EOKeyValueCodingAdditions)object).valuesForKeys(keys); } else { value = EOKeyValueCodingAdditions.DefaultImplementation.valuesForKeys(keys); }
NSKeyValueCoding
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCodingAdditions
,
EOKeyValueCoding
,
EOKeyValueCodingAdditions.DefaultImplementation
,
EOKeyValueCodingAdditions.Utility
Inner Class Summary | |
static class |
EOKeyValueCodingAdditions.DefaultImplementation
The EOKeyValueCodingAdditions.DefaultImplementation class provides the WebObjects default implementation of the EOKeyValueCodingAdditions interface. |
static class |
EOKeyValueCodingAdditions.Utility
The EOKeyValueCodingAdditions.Utility class is a convenience that allows you to access the properties of EOKeyValueCodingAdditions objects and non-EOKeyValueCodingAdditions objects using the same code. |
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions |
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCoding |
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor |
Inner classes inherited from class com.webobjects.eocontrol.EOKeyValueCoding |
EOKeyValueCoding.DefaultImplementation, EOKeyValueCoding.Utility |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
KeyPathSeparator |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
NullValue |
Method Summary | |
void |
takeValuesFromDictionary(NSDictionary dictionary)
Sets properties of the receiver with values from dictionary , using
its keys to identify the properties. |
NSDictionary |
valuesForKeys(NSArray keys)
Returns a dictionary containing the property values identified by each of keys . |
Methods inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
takeValueForKeyPath, valueForKeyPath |
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding |
takeValueForKey, valueForKey |
Methods inherited from interface com.webobjects.eocontrol.EOKeyValueCoding |
storedValueForKey, takeStoredValueForKey |
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling |
handleQueryWithUnboundKey, handleTakeValueForUnboundKey, unableToSetNullForKey |
Method Detail |
public void takeValuesFromDictionary(NSDictionary dictionary)
dictionary
, using
its keys to identify the properties. The default implementation invokes
takeValueForKey
for each key-value pair, substituting
null
for NSKeyValueCoding.NullValue values in the dictionary.dictionary
- the key-value pairs to be setNSKeyValueCoding.takeValueForKey(Object, String)
public NSDictionary valuesForKeys(NSArray keys)
keys
. The default implementation invokes valueForKey
for each key in keys
, substituting NSKeyValueCoding.NullValue in
the returned dictionary for returned null
values.keys
- the array of keys whose values are to be retrievedNSKeyValueCoding.valueForKey(String)
|
Last updated Thu Jan 10 18:10:21 PST 2002. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |