|
WebObjects 5.2.3 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
EOKeyValueCodingインターフェースは、NSKeyValueCodingとNSKeyValueCoding.ErrorHandlingインターフェースを拡張します。
EOKeyValueCodingのメソッド takeStoredValueForKey
と storedValueForKey
は、信頼できるデータストアとデータを送受信するために使用されます。
For example, takeStoredValueForKey
is used to initialize an object's
properties with values fetched from the database, whereas NSKeyValueCoding's
takeValueForKey
is used to modify an object's properties to values
provided by a user (from a graphical user interface) or other business logic.
The EOKeyValueCoding interface contains two inner classes, EOKeyValueCoding.DefaultImplementation and EOKeyValueCoding.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 EOKeyValueCoding objects and non-EOKeyValueCoding objects using the same code.
Default ImplementationThe methods in the EOKeyValueCoding.DefaultImplementation class are just like the methods defined by the EOKeyValueCoding interface, except they are static methods and they take an extra argument - the object on which the default implementation should operate.
For example, suppose it is wanted to implement an Employee class that implements
EOKeyValueCoding using EOKeyValueCoding.DefaultImplementation. Employee's
storedValueForKey
method would then look like this:
public Object storedValueForKey(String key) { return EOKeyValueCoding.DefaultImplementation.storedValueForKey(this, key); }
Note:Always try to use the default implementation of EOKeyValueCoding. The default implementations have significant performance optimizations. To benefit from them, EOKeyValueCoding can be implemented on a custom class as shown above by using the methods in EOKeyValueCoding.DefaultImplementation; or if your class inherits from an EOF class that implements EOKeyValueCoding, don't override the inherited implementation. Using a custom implementation incurs significant performance penalties.
UtilityRecall that the EOKeyValueCoding.Utility class is a convenience that allows to access the properties of EOKeyValueCoding objects and non-EOKeyValueCoding 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 EOKeyValueCoding object and invoke the corresponding EOKeyValueCoding 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 EOKeyValueCoding API but you don't know if the object is an EOKeyValueCoding object. To do so, you simply use the corresponding Utility API, as in the following line of code:
value = EOKeyValueCoding.Utility.storedValueForKey(key);
The above line of code is essentially a short-cut for the following:
if (object instanceof EOKeyValueCoding) { value = ((EOKeyValueCoding)object).storedValueForKey(key); } else { value = EOKeyValueCoding.DefaultImplementation.storedValueForKey(key); }Preventing Special Stored Accessors
If you always want the method of EOKeyValueCoding to work exactly like the corresponding methods on NSKeyValueCoding, implement the static method
public static boolean canAccessFieldsDirectly()
on your EOKeyValueCoding class to return false
.
An EOKeyValueCoding class doesn't have to implement this method. It's an optional
method that allows a class to tailor key-value coding behavior. By default, the
key-value implementation provided by EOKeyValueCoding.DefaultImplementation does
use private accessors. An EOKeyValueCoding class can override this behavior by
implementing this method to return false
, in which case the key-value
coding methods don't use private accessors.
This method isn't strictly part of this interface because static methods can't be formally declared in an interface. However, this method is so closely related to the interface as to be considered part of it.
NSKeyValueCoding
,
NSKeyValueCoding.ErrorHandling
,
EOKeyValueCoding.DefaultImplementation
,
EOKeyValueCoding.Utility
Nested Class Summary | |
static class |
EOKeyValueCoding.DefaultImplementation
The EOKeyValueCoding.DefaultImplementation class provides the WebObjects default implementation of the EOKeyValueCoding interface. |
static class |
EOKeyValueCoding.Utility
The EOKeyValueCoding.Utility class is a convenience that allows you to access the properties of EOKeyValueCoding objects and non-EOKeyValueCoding objects using the same code. |
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding |
NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.ValueAccessor |
Field Summary |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
NullValue |
Method Summary | |
Object |
storedValueForKey(String key)
Returns the property identified by key . |
void |
takeStoredValueForKey(Object value,
String key)
Sets the property identified by key to value . |
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding |
takeValueForKey, valueForKey |
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling |
handleQueryWithUnboundKey, handleTakeValueForUnboundKey, unableToSetNullForKey |
Method Detail |
public Object storedValueForKey(String key)
Returns the property identified by key
. This method is used
when the value is retrieved for storage in an object store (generally, this
is ultimately in a database) or for inclusion in a snapshot. The default
implementation provided by EOKeyValueCoding.DefaultImplementation is similar
to the implementation of NSKeyValueCoding.DefaultImplementation's
valueForKey
, but it resolves key
with a different
method and field search order:
key
(a
method preceded by an underbar). For example, with a key of "value",
storedValueForKey
looks for a method named
_getValue
, _isValue
or _value
.key
and returns its value directly. For
example, with a key of "value", storedValueForKey
looks
for a field named _value
, _isValue
,
value
, or isValue
.storedValueForKey
searches for a public accessor method based
on key
. For the key "value", this would be
getValue
, isValue
or value
.key
is unknown, storedValueForKey
calls
handleQueryWithUnboundKey
, defined in
NSKeyValueCoding.ErrorHandling.This different search order allows an object to bypass processing that is
performed before returning a value through public API. However, if you always
want to use the search order in valueForKey
, you can implement the
static method shouldUseStoredAccessors
to return false
.
And as with valueForKey
, you can prevent direct access of a field
with the static method canAccessFieldsDirectly
.
key
- the property of the object
key
NSKeyValueCoding
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.valueForKey(String)
,
NSKeyValueCoding.ErrorHandling.handleQueryWithUnboundKey(String)
public void takeStoredValueForKey(Object value, String key)
Sets the property identified by key
to value
.
This method is used to initialize the receiver with values from an object
store (generally, this is ultimately from a database) or to restore a value
from a snapshot. The default implementation provided by
EOKeyValueCoding.DefaultImplementation is similar to the implementation of
NSKeyValueCoding.DefaultImplementation's takeValueForKey
,
but it resolves key
with a different method and field search
order:
key
(a
method preceded by an underbar). For example, with a key of "value",
takeStoredValueForKey
looks for a method named
_setValue
.key
and sets its value directly. For example,
with a key of "value", takeStoredValueForKey
looks for a field named _value
, _isValue
,
value
, or isValue
.
takeStoredValueForKey
searches for a public accessor method
based on key
. For the key "value", this would be
setValue
.
key
is unknown, takeStoredValueForKey
calls handleTakeValueForUnboundKey
.
This different search order allows an object to bypass processing that
is performed before setting a value through public API. However, if you
always want to use the search order in takeValueForKey
, you
can implement the static method shouldUseStoredAccessors
to
return false
. And as with takeValueForKey
, you
can prevent direct access of a field with the static method
canAccessFieldsDirectly
.
value
- the value to store in the receiverkey
- the property of the objectNSKeyValueCoding
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.takeValueForKey(Object, String)
,
NSKeyValueCoding.ErrorHandling.handleTakeValueForUnboundKey(Object, String)
|
Last updated Thu Oct 21 15:04:16 PDT 2004. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |