In WebObjects, applications that use the Enterprise Objects Framework must enlist the help of the EOEditingContext class to archive enterprise objects. The primary reason is so that EOEditingContext can keep track, from one database transaction to the next, of the objects it is designed to manage. But using an EOEditingContext for archiving also benefits your application in these other ways:
// WebScript example - encodeWithCoder:(NSCoder *)aCoder { [EOEditingContext encodeObject:self withCoder:aCoder]; } - initWithCoder:(NSCoder *)aDecoder { [EOEditingContext initObject:self withCoder:aDecoder]; return self; }Even though the Java packages provide a different archiving mechanism, your Java classes should use the Foundation archiving mechanism. In Java, the NSCoding protocol is called the Coding interface, and it declares only one method, encodeWithCoder. If your class conforms to the Coding interface, it should also implement a constructor that takes a Coder object as an argument. (This is the equivalent of the initWithCoder: method.)
// Java example public void encodeWithCoder(Coder aCoder) { EditingContext.encodeObjectWithCoder(this, aCoder); } public MyClass(Coder aDecoder) { EditingContext.initObjectWithCoder(this, aDecoder); }The enterprise object simply passes on responsibility for archiving and unarchiving itself to the EOEditingContext class, by invoking the encodeObject:withCoder: and initObject:withCoder: class methods and passing a reference to itself (self) as one of the arguments. The editing context takes care of the rest. (See the EOEditingContext class specification in the Enterprise Objects Class Reference for more information.)
Table of Contents Next Section