Implemented by:
- EOKeyValueCodingAdditions
- EOEnterpriseObject
- EOCustomObject
- EOGenericRecord
- Implements:
- (com.apple.client.eocontrol only) NSKeyValueCoding
- Package:
- com.apple.client.eocontrol
- com.apple.yellow.eocontrol
The EOKeyValueCoding interface defines Enterprise Objects Framework's main data transport mechanism, in which the properties of an object are accessed indirectly by name (or key), rather than directly through invocation of an accessor method or as instance variables. Thus, all of an object's properties can be accessed in a consistent manner. EOCustomObject and EOGenericRecord provide default implementations of EOKeyValueCoding, which are sufficient for most purposes.
The basic methods for accessing an object's values are takeValueForKey, which sets the value for the property identified by the specified key, and valueForKey, which returns the value for the property identified by the specified key. The default implementations provided by EOCustomObject use the accessor methods normally implemented by objects (or to access instance variables directly if need be), so that you don't have to write special code simply to integrate your objects into the Enterprise Objects Framework.
The corresponding methods takeStoredValueForKey and storedValueForKey are
similar, but they're considered to be a private API, for use by
the Framework for transporting data to and from trusted sources.
For example, takeStoredValueForKey
is used
to initialize an object's properties with values fetched from
the database, whereas takeValueForKey
is
used to modify an object's properties to values provided by a
user or other business logic. How these methods work and how they're
used by the framework is discussed in more detail in the section "Stored Value Methods".
The remaining methods, handleQueryWithUnboundKey, handleTakeValueForUnboundKey, and unableToSetNullForKey, are provided to handle error conditions. The default versions of handleQueryWithUnboundKey and handleTakeValueForUnboundKey throw an exception.
For more information on EOKeyValueCoding, see the sections:
EOKeyValueCoding defines the following int
constants to
be used as possible arguments for the createKeyValueBindingForKey and keyValueBindingForKey methods. The
argument indicates whether the return value, a EOKeyValueCoding.KeyBinding object,
binds a class/key pair to a mechanism to set the value for a key
or to retrieve it.
Constant | Description |
SetKeyBindingMask | Designates a binding as one responsible for setting an object's value. |
StoredKeyBindingMask | Designates a binding as one responsible for retrieving an object's value. |
NSKeyValueCoding (com.apple.client.eocontrol only)
- takeValueForKey
- valueForKey
- Accessing values
- storedValueForKey
- takeStoredValueForKey
- takeValueForKey
- valueForKey
- Handling error conditions
- handleQueryWithUnboundKey
- handleTakeValueForUnboundKey
- unableToSetNullForKey
public abstract Object
handleQueryWithUnboundKey
(String key)
public abstract void
handleTakeValueForUnboundKey
(
Object value,
String key)
public abstract Object
storedValueForKey
(String key)
storedValueForKey
looks
for a method named _getLastName or _lastName.storedValueForKey
looks
for an instance variable named _lastName
or lastName
.storedValueForKey
searches
for a public accessor method based on key.
For the key "lastName", this would be getLastName or lastName.storedValueForKey
calls handleTakeValueForUnboundKey.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 useStoredAccessor to return false.
And as with valueForKey
, you can prevent
direct access of an instance variable with the method the static method accessInstanceVariablesDirectly.
public abstract void
takeStoredValueForKey
(
Object value,
String key)
takeStoredValueForKey
looks
for a method named _setLastName.takeStoredValueForKey
looks
for an instance variable named _lastName
or lastName
.takeStoredValueForKey
searches
for a public accessor method based on key.
For the key "lastName", this would be setLastName.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 useStoredAccessor to return false.
And as with valueForKey
, you can prevent
direct access of an instance variable with the method the static method accessInstanceVariablesDirectly.
public abstract void
takeValueForKey
(
Object value,
String key)
The default implementation provided by EOCustomObject works as follows:
set
Key
,
invoking it if there is one._set
Key
, invoking
it if there is one.takeValueForKey
searches
for an instance variable based on key and
sets the value directly. For the key "lastName", this would
be _lastName
or lastName
.public abstract void
unableToSetNullForKey
(String key)
int
or
a float
). EOCustomObject's implementation throws
an exception. Subclasses can override it to handle the request in
some other way, such as by substituting zero or a sentinel value
and invoking takeValueForKey again.public abstract Object
valueForKey
(String key)
The default implementation provided by EOCustomObject works as follows:
valueForKey
looks
for a method named getLastName or lastName.valueForKey
looks
for a method named _getLastName or _lastName.valueForKey
searches
for an instance variable based on key and
returns its value directly. For the key "lastName", this would
be _lastName or lastName.handleQueryWithUnboundKey
.