EOClassDescription
- Inherits from:
- NSObject
Declared in:
- EOControl/EOClassDescription.h
Class Description
The EOClassDescription class provides a mechanism for extending classes by giving them access to metadata not available in the run-time system. This is achieved as follows:
- EOClassDescription provides a bridge between enterprise objects and the metadata contained in an external source of information, such as an EOModel (EOAccess). It defines a standard API for accessing the information in an external source. It also manages the registration of EOClassDescription objects in your application.
- The EOEnterpriseObject informal protocol declares several EOClassDescription-related methods that define basic enterprise objects behavior, such as undo and validation. The Enterprise Objects Framework extends NSObject by providing implementations of these methods. An enterprise object class can either accept the default implementations or it can provide its own implementation by overriding. This is discussed in more detail in the section "Using EOClassDescription" .
Enterprise Objects Framework implements a default subclass of EOClassDescription in EOAccess, EOEntityClassDescription. EOEntityClassDescription extends the behavior of enterprise objects by deriving information about them (such as NULL constraints and referential integrity rules) from an associated EOModel.
For more information on using EOClassDescription, see the sections
- "How Does It Work?"
- "Using EOClassDescription"
- "EOEntityClassDescription"
- "The EOClassDescription's Delegate"
Constants
In EOClassDescription.h, EOControl defines
the enumeration type EODeleteRule
.
It's constants are:
Constant | Description |
EODeleteRuleNullify | When the source object is deleted, any references a destination object has to the source are removed or "nullified." For example, suppose a department has a to-many relationship to multiple employees. When the department is deleted, any back references an employee has to the department are set to nil. |
EODeleteRuleCascade | When the source object (department) is deleted, any destination objects (employees) are also deleted. |
EODeleteRuleDeny | If the source object (department) has any destination objects (employees), a delete operation is refused. |
EODeleteRuleNoAction | When the source object is deleted, its relationship is
ignored and no action is taken to propagate the deletion to destination
objects.This rule is useful for tuning performance.To perform
a deletion, Enterprise Objects Framework fires all the faults of
the deleted object and then fires any to-many faults that point
back to the deleted object. For example, suppose you have a simple
application based on the sample Movies database. Deleting a Movie
object has the effect of firing a to-one fault for the Movie's
studio relationship, and then firing the to-many movies fault for
that studio. In this scenario, it would make sense to set the delete
rule EODeleteRuleNoAction for Movie's
studio relationship. However, you should use this delete rule with
great caution since it can result in dangling references in your object
graph. |
EOClassDescription.h also defines string constants for the names of the notifications it posts. For more information, see the section "Notifications" .
Method Types
- Managing EOClassDescriptions
- + invalidateClassDescriptionCache
- + registerClassDescription:forClass:
- Getting EOClassDescriptions
- + classDescriptionForClass:
- + classDescriptionForEntityName:
- Creating new object instances
- - createInstanceWithEditingContext:globalID:zone:
- Propagating delete
- - propagateDeleteForObject:editingContext:
- Returning information from the EOClassDescription
- - entityName
- - attributeKeys
- - classDescriptionForDestinationKey:
- - toManyRelationshipKeys
- - toOneRelationshipKeys
- - inverseForRelationshipKey:
- - ownsDestinationObjectsForRelationshipKey:
- - deleteRuleForRelationshipKey:
- Performing validation
- - validateObjectForDelete:
- - validateObjectForSave:
- - validateValue:forKey:
- Providing default characteristics for key display
- - defaultFormatterForKey:
- - defaultFormatterForKeyPath:
- - displayNameForKey:
- Handling newly inserted and newly fetched objects
- - awakeObject:fromFetchInEditingContext:
- - awakeObject:fromInsertionInEditingContext:
- Setting the delegate
- + classDelegate
- + setClassDelegate:
- Getting an object's description
- - userPresentableDescriptionForObject:
- Getting fetch specifications
- - fetchSpecificationNamed:
Class Methods
classDelegate
+ (id)classDelegate
See Also: + setClassDelegate:
classDescriptionForClass:
+ (EOClassDescription *)classDescriptionForClass:(Class)aClass
classDescriptionForEntityName:
+ (EOClassDescription *)classDescriptionForEntityName:(NSString
*)entityName
invalidateClassDescriptionCache
+ (void)invalidateClassDescriptionCache
Flushes the EOClassDescription cache. Because the EOModel objects in an application supply and register EOClassDescriptions on demand, the cache continues to be repopulated as needed after you invalidate it. (The EOModel class is defined in EOAccess.)
You'd use this method when a provider of EOClassDescriptions (such as an EOModel) has newly become available, or is about to go away. However, you should rarely need to directly invoke this method unless you're using an external source of information other than an EOModel.
registerClassDescription:forClass:
+ (void)registerClassDescription:(EOClassDescription
*)description
forClass:(Class)class
setClassDelegate:
+ (void)setClassDelegate:(id)delegate
See Also: + classDelegate
Instance Methods
attributeKeys
- (NSArray *)attributeKeys
EOClassDescription's implementation of this method simply returns.
See Also: - entityName, - toOneRelationshipKeys, - toManyRelationshipKeys
awakeObject:fromFetchInEditingContext:
- (void)awakeObject:(id)object
fromFetchInEditingContext:(EOEditingContext
*)anEditingContext
awakeObject:fromInsertionInEditingContext:
- (void)awakeObject:(id)object
fromInsertionInEditingContext:(EOEditingContext
*)anEditingContext
classDescriptionForDestinationKey:
- (EOClassDescription *)classDescriptionForDestinationKey:(NSString
*)detailKey
[movie classDescriptionForDestinationKey:@"studio"];
might return the class description for the Studio class. EOClassDescription's implementation of this method returns nil.
createInstanceWithEditingContext:globalID:zone:
- (id)createInstanceWithEditingContext:(EOEditingContext
*)anEditingContext
globalID:(EOGlobalID *)globalID
zone:(NSZone *)zone
defaultFormatterForKey:
- (NSFormatter *)defaultFormatterForKey:(NSString
*)key
Returns the default NSFormatter to use when parsing values for assignment to key. EOClassDescription's implementation returns nil. The access layer's EOEntityClassDescription's implementation returns an NSFormatter based on the Objective-C value class specified for key in the associated model file. Code that creates a user interface, like a wizard, can use this method to assign formatters to user interface elements.
defaultFormatterForKeyPath:
- (NSFormatter *)defaultFormatterForKeyPath:(NSString
*)keyPath
Similar to defaultFormatterForKey:, except this method traverses keyPath and returns the formatter for the key at the end of the path (using defaultFormatterForKey:).
deleteRuleForRelationshipKey:
- (EODeleteRule)deleteRuleForRelationshipKey:(NSString
*)relationshipKey
EOClassDescription's implementation of this method returns the delete rule EODeleteRuleNullify. In the common case, the delete rule for an enterprise object is defined in its EOModel. (The EOModel class is defined in EOAccess.)
See Also: - propagateDeleteWithEditingContext: (EOEnterpriseObject)
displayNameForKey:
- (NSString *)displayNameForKey:(NSString
*)key
Returns the default string to use in the user interface when displaying key. By convention, lowercase words are capitalized (for example, "revenue" becomes "Revenue"), and spaces are inserted into words with mixed case (for example, "firstName" becomes "First Name"). This method is useful if you're creating a user interface from only a class description, such as with a wizard or a Direct To Web application.
entityName
- (NSString *)entityName
See Also: - attributeKeys, - toOneRelationshipKeys, - toManyRelationshipKeys
fetchSpecificationNamed:
- (EOFetchSpecification *)fetchSpecificationNamed:(NSString
*)name
nil
.inverseForRelationshipKey:
- (NSString *)inverseForRelationshipKey:(NSString
*)relationshipKey
[employee inverseForRelationshipKey:@"department"];
returns the string "employees".
EOClassDescription's implementation of this method returns nil.
ownsDestinationObjectsForRelationshipKey:
- (BOOL)ownsDestinationObjectsForRelationshipKey:(NSString
*)relationshipKey
propagateDeleteForObject:editingContext:
- (void)propagateDeleteForObject:(id)object
editingContext:(EOEditingContext
*)anEditingContext
See Also: - deleteRuleForRelationshipKey:
toManyRelationshipKeys
- (NSArray *)toManyRelationshipKeys
See Also: - entityName, - toOneRelationshipKeys, - attributeKeys
toOneRelationshipKeys
- (NSArray *)toOneRelationshipKeys
See Also: - entityName, - toManyRelationshipKeys, - attributeKeys
userPresentableDescriptionForObject:
- (NSString *)userPresentableDescriptionForObject:(id)anObject
Returns a short (no longer than 60 characters) description of anObject based on its data. This method enumerates anObject's attributeKeys and returns each attribute's value, separated by commas and with the default formatter applied for numbers and dates.
validateObjectForDelete:
- (NSException *)validateObjectForDelete:(id)object
nil
if
the delete operation should proceed, or return an exception containing
a user-presentable (localized) error message if not. EOClassDescription's
implementation of this method returns nil
.validateObjectForSave:
- (NSException *)validateObjectForSave:(id)object
nil
if
the values are acceptable and the save operation should proceed,
or return an exception containing a user-presentable (localized)
error message if not. EOClassDescription's implementation of this
method returns nil
.validateValue:forKey:
- (NSException *)validateValue:(id
*)valueP
forKey:(NSString *)key
An enterprise object performs custom attribute
specific validation with a method of the form validateKey
.
See the EOValidation protocol specification
for more information.
Notifications
The following notifications are declared by EOClassDescription and posted by enterprise objects in your application.
EOClassDescriptionNeededForClassNotification
EOCONTROL_EXTERN NSString *EOClassDescriptionNeededForClassNotification
EOClassDescriptionNeededForClassNotification
to
notify observers that a class description is needed. The observer
then locates the appropriate class description and registers it
in the application. By default, EOModel objects are registered as
observers for this notification and register EOClassDescriptions
on demand.Notification Object | Enterprise object class |
userInfo Dictionary | None |
EOClassDescriptionNeededForEntityNameNotification
EOCONTROL_EXTERN NSString *EOClassDescriptionNeededForEntityNameNotification
Notification Object | Entity name (NSString) |
userInfo Dictionary | None |