home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / EOFault.h < prev    next >
Encoding:
Text File  |  1996-09-11  |  6.6 KB  |  198 lines

  1. // EOFault.h
  2. // Copyright (c) 1995, NeXT Software, Inc.  All rights reserved.
  3. //
  4. // An EOFault represents a Object (or a collection of objects) that haven't
  5. // yet been fetched from their external ObjectStore.  When an object
  6. // that has relationships is fetched, EOFaults are created for the
  7. // destinations of those relationships (unless the corresponding objects have
  8. // already been fetched and uniqued).
  9. //
  10. // You can create a fault for a single object--called an "object fault"--or
  11. // for many objects described by a particular qualifier--called an "array
  12. // fault." To-one relationships result in object faults, while to-many
  13. // relationships result in array faults.  An object fault loads the real
  14. // object whenever you message it (with some exceptions).  An array fault
  15. // loads its objects as soon as you send it any message that requires accessing
  16. // the contents of the array (-objectAtIndex:, -count, and so on).  Objects of
  17. // either type are called "fault objects".
  18. //
  19. // You can use fault objects to defer a fetch--that is, set up for a fetch
  20. // while your channel is in the middle of another operation.  For example,
  21. // your Enterprise Object may need to fetch objects in its
  22. // -takeValue:forKey: method, but since this can be invoked during a fetch,
  23. // it has to defer its own fetch.
  24. //
  25.  
  26. #import <Foundation/Foundation.h>
  27.  
  28. @class EOFaultHandler;
  29.  
  30. @interface EOFault
  31. {
  32.     Class isa;
  33.     EOFaultHandler *_handler;
  34. }
  35.  
  36. //
  37. // Handled locally by the fault class
  38. //
  39. + (void)initialize;
  40. + (Class)superclass;
  41. + (Class)class;
  42. + (id)self;
  43.  
  44. + (id)retain;
  45. + (void)release;
  46. + (id)autorelease;
  47. + (unsigned)retainCount;
  48.  
  49. + (BOOL)isKindOfClass:(Class)aClass;
  50. + (void)doesNotRecognizeSelector:(SEL)sel;
  51. + (BOOL)respondsToSelector:(SEL)sel;
  52.  
  53. //
  54. // Fault management
  55. //
  56. + (void)makeObjectIntoFault:(id)object withHandler:(EOFaultHandler *)handler;
  57.     // Turn the object into a fault.
  58.     // usually called by higher level constructors like
  59.     // faultForGlobalID:editingContext: or
  60.     // arrayFaultWithSourceGlobalID:relationshipName:editingContext:.
  61.  
  62. + (BOOL)isFault:(id)object;
  63.     // Returns YES if object is a fault object, NO otherwise.  You should use
  64.     // this method if you need to know whether an object is in fact a fault
  65.     // object.
  66.  
  67. + (void)clearFault:(id)fault;
  68.     // Turns fault into a freshly initialized instance of the target class.
  69.     // Does NOT fetch data for the new instance. This will raise if
  70.     // invoked with an object that isn't a fault object.  You'll rarely need
  71.     // to use this method.
  72.  
  73. + (EOFaultHandler *)handlerForFault:(id)fault;
  74.     // the handler for this fault, or nil if not a fault
  75.  
  76. + (Class)targetClassForFault:(id)fault;
  77.     // Returns the class that will be instantiated when fault is fetched
  78.     // or one of its superclasses.
  79.  
  80. //
  81. // Forwarded to the faultHandler. Usually it could
  82. // respond to the method without fetching the fault.
  83. //
  84. - (Class)superclass;
  85. - (Class)class;
  86.  
  87. - (BOOL)isKindOfClass:(Class)class;
  88. - (BOOL)isMemberOfClass:(Class)class;
  89. - (BOOL)conformsToProtocol:(Protocol *)protocol;
  90. - (BOOL)respondsToSelector:(SEL)sel;
  91. - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
  92.  
  93. - (id)retain;
  94. - (void)release;
  95. - (id)autorelease;
  96. - (unsigned)retainCount;
  97.  
  98. - (NSString *)description;
  99. - (NSString *)descriptionWithIndent:(unsigned)level;
  100. - (NSString *)descriptionWithLocale:(NSDictionary *)locale;
  101. - (NSString *)descriptionWithLocale:(NSDictionary *)locale indent:(unsigned)level;
  102. - (NSString *)eoDescription;
  103. - (NSString *)eoShallowDescription;
  104.     // All these methods falls back to description
  105.  
  106. //
  107. // dealloc clear the fault and call release on the resulting object.
  108. //
  109. - (void)dealloc;
  110.  
  111. //
  112. // These methods are handled directly by the EOFault class
  113. //
  114. - (NSZone *)zone;
  115. - (BOOL)isProxy; // Always NO.
  116.  
  117. //
  118. // This message causes a fetch.  It is convenient to have a generic method
  119. // which will cause a fault to trip.
  120. //
  121. - (id)self;
  122.  
  123. //
  124. // Cause the fault to fire by calling handler to complete
  125. // initialization (the handler is reponsible for sending a clearFault:)
  126. // and forwarding on the message.
  127. //
  128. - (void)doesNotRecognizeSelector:(SEL)sel;
  129. - (void)forwardInvocation:(NSInvocation *)invocation;
  130.  
  131. @end
  132.  
  133.  
  134. // When an object is made into a fault, a handler must be assigned
  135. // to finish initialization when the fault is fired.  Subclasses of
  136. // EOFaultHandler can be created to implement this behavior. 
  137. // Subclasses add the additional instance variables to EOFaultHandler
  138. // (such as the object primary key, or EOQualifier) that will be needed
  139. // to finish object initialization.
  140. //
  141. @interface EOFaultHandler : NSObject
  142. {
  143.     Class _targetClass;  // the first 8 bytes of
  144.     void *_extraData;    // the faulted object
  145.  
  146.     unsigned _extraRefCount;
  147. }
  148.  
  149. - (void)setTargetClass:(Class)target extraData:(void *)data;
  150. - (Class)targetClass;
  151. - (void *)extraData;
  152.     // FaultHandler accessor Methods
  153.  
  154. - (void)incrementExtraRefCount;
  155. - (BOOL)decrementExtraRefCountWasZero;
  156. - (unsigned)extraRefCount;
  157.     // Called when the fault is initialised and on every retain/release
  158.  
  159. - (NSString *)descriptionForObject:object;
  160.     // Return the description for the fault
  161.  
  162. //
  163. // Forwarded messages from the fault
  164. //
  165. - (Class)classForFault:(id)fault;
  166.     // classForFault: is returning the real fault class. It could be a
  167.     // targetClass subclass. If faultClass is different than targetClass
  168.     // the fault handler can fire the fault.
  169.     // The default implementation is calling -targetClass.
  170.  
  171. - (BOOL)isKindOfClass:(Class)class forFault:(id)fault;
  172. - (BOOL)isMemberOfClass:(Class)class forFault:(id)fault;
  173. - (BOOL)conformsToProtocol:(Protocol *)protocol forFault:(id)fault;
  174. - (BOOL)respondsToSelector:(SEL)sel forFault:(id)fault;
  175. - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector forFault:(id)fault;
  176.  
  177. - (void)completeInitializationOfObject:(id)object;
  178.     // Overriden by subclasses to complete the initialization of
  179.     // an object when its fault has been accessed.  For instance
  180.     // a database object fault would use this method to fetch the 
  181.     // object contents from the server and hand the values to the
  182.     // object. This method is responsible to handle the clearFault.
  183.     // Note that the faultHandler will be released by the clearFault:
  184.     // method.
  185.     // The default implementation raise.
  186.  
  187. - (BOOL)shouldPerformInvocation:(NSInvocation *)invocation;
  188.     // This method is called just before firing the fault.
  189.     // If this method return NO the fault is not fired, and the value
  190.     // returned to the caller is the return value stored in the invocation.
  191.     // The invocation's target is set to the fault.
  192.     // The default implementation return YES.
  193.  
  194. - (void)faultWillFire:(id)object;
  195.     // This method is called at the begining of -clearFault.
  196.     // The default implementation do nothing.
  197. @end
  198.