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
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.
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.
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);
}