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, the sections below can be referred

EOClassDescription.Concepts

How Does It Work?

As noted above, Enterprise Objects Framework implements a default subclass of EOClassDescription in EOAccess, EOEntityClassDescription. In the typical scenario in which an enterprise object has a corresponding model file, a particular operation (such as validating a value) results in the broadcast of an EOClassDescriptionNeeded... notification (an ClassDescriptionNeededForClassNotification or an ClassDescriptionNeededForEntityNameNotification ). When an EOModel object receives such a notification, it registers the metadata (class description) for the EOEntity on which the enterprise object is based. (EOModel and EOEntity are defined in EOAccess.)

An enterprise object takes advantage of the metadata registered for it by using the EOClassDescription related methods defined in the EOEnterpriseObject interface (and implemented in EOCustomObject and EOGenericRecord). Primary among these methods is classDescription, which returns the class description associated with the enterprise object. Through this class description the enterprise object has access to all of the information relating to its entity in a model file.

In addition to methods that return information based on an enterprise object's class description, the EOClassDescription related methods the EOEnterpriseObject interface defines include methods that are automatically invoked when a particular operation occurs. These include validation methods and methods that are invoked whenever an enterprise object is inserted or fetched.

Using EOClassDescription

For the most part, you do not need to programmatically interact with EOClassDescription. It extends the behavior of the enterprise objects transparently. However, there are two cases in which you need to programmatically interact with it:

Working with Objects That Don't Have EOModels

Although an EOModel is the most common source of an EOClassDescription for a class, it isn't the only one. Objects that don't have an EOModel can implement EOClassDescription methods directly as instance methods, and the rest of the Framework will treat them just as it does enterprise objects that have this information provided by an external EOModel.

There are a few reasons you might want to do this. First of all, if the object implements the methods entityName, attributeKeys, toOneRelationshipKeys , and toOneRelationshipKeys, EOEditingContexts can snapshot the object and thereby provide undo for it.

Secondly, you might want to implement EOClassDescription's validation or referential integrity methods to add these features to the classes.

Implementing EOClassDescription methods on a per class basis in this way is a good alternative to creating a subclass of EOClassDescription.

EOEntityClassDescription

There are only three methods in EOClassDescription that have meaningful implementations (that is, that don't either return null or simply return without doing anything): invalidateClassDescriptionCache, registerClassDescription, and propagateDeleteForObject. The default behavior of the rest of the methods in Enterprise Objects Framework comes from the implementation in the access layer's EOClassDescription subclass EOEntityClassDescription. the EOEntityClassDescription class specification can be referred to.

The EOClassDescription's Delegate

A delegate can be assigned to the EOClassDescription class. EOClassDescription sends the message shouldPropagateDeleteForObject to its delegate when delete propagation is about to take place for a particular object. The delegate can either allow or deny the operation for a specified relationship key. For more information, see the method description for shouldPropagateDeleteForObject.

Registering for a Notification

Here is a code sample for registering for the ClassDescriptionNeededFor... notifications.

private static final Class[] parameters = new Class[] { com.webobjects.foundation.NSNotification.class };
private static final NSSelector classDescriptionNeededForClassSelector = new NSSelector("myMethodForClass", parameters);
private static final NSSelector classDescriptionNeededForEntityNameSelector = new NSSelector("myMethodForEntityName", parameters);


// register to receive the notifications
NSNotificationCenter notificationCenter = NSNotificationCenter.defaultCenter();

notificationCenter.addObserver(this, classDescriptionNeededForClassSelector, EOClassDescription.ClassDescriptionNeededForClassNotification, null);

notificationCenter.addObserver(this, classDescriptionNeededForEntityNameSelector, EOClassDescription.ClassDescriptionNeededForEntityNameNotification, null);

// write the methods invoked when the notification occurs

public void myMethodForClass(NSNotification notification) {
Class targetClass = (Class) notification.object();
// do some stuff, decide if you need to register a new class description, etc.
EOClassDescription.registerClassDescription(newClassDescription, targetClass);
}

public void myMethodForEntity(NSNotification notification) {
String entityName = (String) notification.object();
// do some stuff, decide if you need to register a new class description, etc.
EOClassDescription.registerClassDescription(newClassDescription, aClass);
}