PATH  WebObjects 4.0 Documentation > EOControl Reference



EOClassDescription

Inherits From:
Object (Java Client)
NSObject (Yellow Box)

Package:
com.apple.client.eocontrol (Java Client)
com.apple.yellow.eocontrol (WebObjects and Yellow Box)

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:

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

Constants

EOClassDescription defines the following string constants for the names of the notifications it posts:

See the Notifications section for more information on the notifications.

Additionally, EOClassDescription defines an integer constant for each delete rule:

For more information on the delete rules, see the method description for deleteRuleForRelationshipKey .

Method Types

Managing EOClassDescriptions
+ invalidateClassDescriptionCache (Yellow Box only)
+ registerClassDescription
Getting EOClassDescriptions
+ classDescriptionForClass
+ classDescriptionForEntityName
Creating new object instances
- createInstanceWithEditingContext
Propagating delete
- propagateDeleteForObject
Returning information from the EOClassDescription
- entityName
- attributeKeys
- classDescriptionForDestinationKey
- toManyRelationshipKeys
- toOneRelationshipKeys
- inverseForRelationshipKey
- ownsDestinationObjectsForRelationshipKey
- deleteRuleForRelationshipKey
Performing validation
- validateObjectForDelete
- validateObjectForSave
- validateValueForKey
Providing default characteristics for key display (Yellow Box only)
- defaultFormatterForKey (Yellow Box only)
- defaultFormatterForKeyPath (Yellow Box only)
- displayNameForKey (Yellow Box only)
Handling newly inserted and newly fetched objects
- awakeObjectFromFetch
- awakeObjectFromInsertion
Setting the delegate
+ classDelegate
+ setClassDelegate
Getting an object's description (Yellow Box only)
- userPresentableDescriptionForObject (Yellow Box only)

Static Methods


classDelegate

public static java.lang.Object classDelegate ()

Returns the delegate for the EOClassDescription class (as opposed to EOClassDescription instances).

See also: + setClassDelegate


classDescriptionForClass

public static EOClassDescription classDescriptionForClass(java.lang.Class aClass)

Invoked by the default implementations of the EOEnterpriseObject interface method classDescription to return the EOClassDescription for aClass. It's generally not safe to use this method directly-for example, individual EOGenericRecord instances can have different class descriptions. If a class description for aClass isn't found, this method posts an EOClassDescriptionNeededForClassNotification on behalf of the receiver's class, allowing an observer to register a an EOClassDescription.


classDescriptionForEntityName

public static EOClassDescription
classDescriptionForEntityName (java.lang.String entityName)

Returns the EOClassDescription registered under entityName.


invalidateClassDescriptionCache

public static void invalidateEOClassDescriptionCache ()

This method is available for Yellow Box applications only; there is no Java Client equivalent.

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

public static void registerClassDescription(
com.apple.client.eocontrol.EOClassDescription description,
java.lang.Class class)

Registers an EOClassDescription object for class in the EOClassDescription cache. You should rarely need to directly invoke this method unless you're using an external source of information other than an EOModel (EOAccess).


setClassDelegate

public static void setClassDelegate (java.lang.Object delegate)

Sets the delegate for the EOClassDescription class (as opposed to EOClassDescription instances) to delegate. For more information on the class delegate, see the EOClassDescription.ClassDelegate interface specification.

See also: + classDelegate

Instance Methods


attributeKeys

public NSArray attributeKeys ()

Overridden by subclasses to return an array of attribute keys (Strings) for objects described by the receiver. "Attributes" contain immutable data (such as Numbers and Strings), as opposed to "relationships" that are references to other enterprise objects. For example, a class description that describes Movie objects could return the attribute keys "title," "dateReleased," and "rating."

EOClassDescription's implementation of this method simply returns .

See also: - entityName , - toOneRelationshipKeys , - toManyRelationshipKeys


awakeObjectFromFetch

public void awakeObjectFromFetch (
EOEnterpriseObject object,
EOEditingContext anEditingContext)

Overridden by subclasses to perform standard post-fetch initialization for object in anEditingContext. EOClassDescription's implementation of this method does nothing.


awakeObjectFromInsertion

public void awakeObjectFromInsertion (
EOEnterpriseObject object,
EOEditingContext anEditingContext)

Assigns empty arrays to to-many relationship properties of newly inserted enterprise objects. Can be overridden by subclasses to propagate inserts for the newly inserted object in anEditingContext. More specifically, if object has a relationship (or relationships) that propagates the object's primary key and if no object yet exists at the destination of that relationship, subclasses should create the new object at the destination of the relationship. Use this method to put default values in your enterprise object.


classDescriptionForDestinationKey

public EOClassDescription classDescriptionForDestinationKey (java.lang.String detailKey)

Overridden by subclasses to return the class description for objects at the destination of the to-one relationship identified by detailKey. For example, the statement:

movie.classDescriptionForDestinationKey("studio")

might return the class description for the Studio class. EOClassDescription's implementation of this method returns null.


createInstanceWithEditingContext

public EOEnterpriseObject createInstanceWithEditingContext (
EOEditingContext anEditingContext,
EOGlobalID globalID)

Overridden by subclasses to create an object of the appropriate class in anEditingContext with globalID. In typical usage, both of the method's arguments are null. To create the object, the subclass should pass anEditingContext, itself, and aGlobalID to the appropriate constructor. Enterprise Objects Framework uses this method to create new instances of objects when fetching existing enterprise objects or inserting new ones in an interface layer EODisplayGroup. EOClassDescription's implementation of this method returns null.


defaultFormatterForKey

public NSFormatter defaultFormatterForKey (java.lang.String key)

This method is available for Yellow Box applications only; there is no Java Client equivalent.

Returns the default NSFormatter to use when parsing values for assignment to key. EOClassDescription's implementation returns null. The access layer's EOEntityClassDescription's implementation returns an NSFormatter based on the Java valueClass 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

public NSFormatter defaultFormatterForKey (java.lang.String key)

This method is available for Yellow Box applications only; there is no Java Client equivalent.

Similar to defaultFormatterForKey , except this method traverses keyPath and returns the formatter for the key at the end of the path (using defaultFormatterForKey ).


deleteRuleForRelationshipKey

public int deleteRuleForRelationshipKey (java.lang.String relationshipKey)

Overridden by subclasses to return a delete rule indicating how to treat the destination of the given relationship when the receiving object is deleted. The delete rule is one of:

Constant Description
DeleteRuleNullify 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 null.
DeleteRuleCascade When the source object (department) is deleted, any destination objects (employees) are also deleted.
DeleteRuleDeny If the source object (department) has any destination objects (employees), a delete operation is refused.
DeleteRuleNoAction 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'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

public java.lang.String displayNameForKey (java.lang.String key)

This method is available for Yellow Box applications only; there is no Java Client equivalent.

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

public java.lang.String entityName ()

Overridden by subclasses to return a unique type name for objects of this class. For example, the access layer's EOEntityClassDescription returns its EOEntity's name. EOClassDescription's implementation of this method returns null.

See also: - attributeKeys , - toOneRelationshipKeys , - toManyRelationshipKeys


inverseForRelationshipKey

public java.lang.String inverseForRelationshipKey (java.lang.String relationshipKey)

Overridden by subclasses to return the name of the relationship pointing back at the receiver from the destination of the relationship specified by relationshipKey. For example, suppose an Employee object has a relationship called department to a Department object, and Department has a relationship called employees back to Employee. The statement:

employee.inverseForRelationshipKey("department");

returns the string "employees".

EOClassDescription's implementation of this method returns null.


ownsDestinationObjectsForRelationshipKey

public boolean ownsDestinationObjectsForRelationshipKey (java.lang.String relationshipKey)

Overridden by subclasses to return true or false to indicate whether the objects at the destination of the relationship specified by relationshipKey should be deleted if they are removed from the relationship (and not transferred to the corresponding relationship of another object). For example, an Invoice object owns its line items. If a LineItem object is removed from an Invoice it should be deleted since it can't exist outside of an Invoice. EOClassDescription's implementation of this method returns false. In the common case, this behavior for an enterprise object is defined in its EOModel. (The EOModel class is defined in EOAccess.)


propagateDeleteForObject

public void propagateDeleteForObject (
EOEnterpriseObject object,
EOEditingContext anEditingContext)

Propagates a delete operation for object in anEditingContext, according to the delete rules specified in the EOModel. This method is invoked whenever a delete operation needs to be propagated, as indicated by the delete rule specified for the corresponding EOEntity's relationship key. (The EOModel and EOEntity classes are defined in EOAccess.) For more discussion of delete rules, see the EOEnterpriseObject interfacespecification.

See also: - deleteRuleForRelationshipKey


toManyRelationshipKeys

public NSArray toManyRelationshipKeys ()

Overridden by subclasses to return the keys for the to-many relationship properties of the receiver. To-many relationship properties contain arrays of enterprise objects. EOClassDescription's implementation of this method returns null .

See also: - entityName , - toOneRelationshipKeys , - attributeKeys


toOneRelationshipKeys

public NSArray toOneRelationshipKeys ()

Overridden by subclasses to return the keys for the to-one relationship properties of the receiver. To-one relationship properties are other enterprise objects. EOClassDescription's implementation of this method returns null.

See also: - entityName , - toManyRelationshipKeys , - attributeKeys


userPresentableDescriptionForObject

public java.lang.String userPresentableDescriptionForObject (java.lang.Object anObject)

This method is available for Yellow Box applications only; there is no Java Client equivalent.

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

public void validateObjectForDelete (EOEnterpriseObject object)
throws EOValidation.Exception

Overridden by subclasses to determine whether it's permissible to delete object. Subclasses should complete normally if the delete operation should proceed, or raise an exception containing a user-presentable (localized) error message. EOClassDescription's implementation of this method completes normally.


validateObjectForSave

public void validateObjectForSave (EOEnterpriseObject object)
throws EOValidation.Exception

Overridden by subclasses to determine whether the values being saved for object are acceptable. Subclasses should complete normally if the values are acceptable and the save operation should proceed, or raise an exception containing a user-presentable (localized) error message if not. EOClassDescription's implementation of this method completes normally.


validateValueForKey

public java.lang.Object validateValueForKey (
java.lang.Object value,
java.lang.String key)
throws EOValidation.Exception

Overridden by subclasses to validate value. Subclasses should complete normally if the value is acceptable, or raise an exception containing a user-presentable (localized) error message if not. Implementations can replace value by returning a new value.

Notification

The following notifications are declared by EOClassDescription and posted by enterprise objects in your application.


EOClassDescriptionNeededForClassNotification

One of the EOClassDescription-related methods in the EOEnterpriseObject interface to extend the behavior of enterprise objects is classDescription. The first time an enterprise object receives a classDescription message (for example, when changes to the object are being saved to the database), it posts 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

When classDescriptionForEntityName is invoked for a previously unregistered entity name, this notification is broadcast with the requested entity name as the object of the notification. By default, EOModel objects are registered as observers for this notification and register EOClassDescriptions on demand.

Notification Object Entity name (String)
userInfo Dictionary None





Copyright © 1998, Apple Computer, Inc. All rights reserved.