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

  1. // EOModelGroup.h
  2. // Copyright (c) 1995, NeXT Software, Inc. All rights reserved. 
  3.  
  4. #import <Foundation/Foundation.h>
  5. #import <EOAccess/EODefines.h>
  6.  
  7. @class EOModel;
  8. @class EOEntity;
  9. @class EORelationship;
  10. @class EOGlobalID;
  11.  
  12. // EOModelGroup represents an aggregation of related models.  When a
  13. // model in the group needs to resolve a foreign relationship to another
  14. // model, it looks that model up in its group.
  15. //
  16. // The default model group contains all models for an application and any
  17. // frameworks the application references. The entity name space among all
  18. // of these models is global and consequently the same entity name should
  19. // not appear in any two of these models. All cross model information is
  20. // represented in the models by the entity name only and binding the name
  21. // to an actual entity is done at runtime within the EOModelGroup.
  22. //
  23. // In the majority of cases the default model group should be sufficient
  24. // for applications. However, if different model grouping semantics are
  25. // needed, programmers can create their own model group instance, add
  26. // whatever models they like, and then replace the defaultModelGroup with
  27. // the one they just created.
  28. //
  29. @interface EOModelGroup : NSObject
  30. {
  31.     NSMutableDictionary *_modelsByName;
  32.     NSMutableDictionary *_subEntitiesCache;
  33.     id _delegate;
  34.     struct {
  35.         unsigned int entityNamed:1;
  36.         unsigned int relationshipForRow:1;
  37.         unsigned int subEntityForEntity:1;
  38.         unsigned int failedToLookupClassNamed:1;
  39.         unsigned int classForObjectWithGlobalID:1;
  40.         unsigned int _RESERVED:27;
  41.     } _delegateRespondsTo;
  42. }
  43. + (EOModelGroup *)defaultGroup;
  44. + (void)setDefaultGroup:(EOModelGroup *)group;
  45.     // The default defaultGroup is [EOModelGroup globalModelGroup];
  46.  
  47. + (EOModelGroup *)globalModelGroup;
  48.     // returns a model group composed of all models in the resource directory
  49.     // of the mainBundle, and all bundles and frameworks loaded into the app.
  50.  
  51. + (void)setDelegate:(id)delegate;
  52. + (id)delegate;
  53.     // Class delegate to answer defaultModelGroup.
  54.  
  55. - (NSArray *)models;
  56.     // Returns all models in group.
  57.  
  58. - (NSArray *)modelNames;
  59.     // Returns the names of all models in group.
  60.  
  61. - (EOModel *)modelNamed:(NSString *)name;
  62.     // Returns EOModel with given name, or nil if its not already loaded.
  63.  
  64. - (EOModel *)modelWithPath:(NSString *)path;
  65.     // If existing model at that path is available, it is returned.
  66.     // Otherwise, returns nil.
  67.  
  68. - (void)addModel:(EOModel *)model;
  69.     // adds model to group
  70.  
  71. - (void)addModelWithFile:(NSString *)path;
  72.     // shortcut for adding a model obtained with
  73.     // [[EOModel alloc] initWithContentsOfFile:path]
  74.  
  75. - (void)removeModel:(EOModel *)model;
  76.     // removes model from group and unbinds connections of other models
  77.     // in group from it.
  78.  
  79. - (EOEntity *)entityNamed:(NSString *)entityName;
  80.     // returns the entity with the given name within any of the models
  81.     // in the group, or nil.
  82.  
  83. - (void)loadAllModelObjects;
  84.     // This method will load any EOEntities, EOStoredProcedures, and
  85.     // EORelationships that have not yet been loaded from the .eomodeld
  86.  
  87. - (id)delegate;
  88. - (void)setDelegate:(id)delegate;
  89.     // Return/Set the delegate on the EOModelGroup.    
  90. @end
  91.  
  92. // Notifications:
  93. EOACCESS_EXTERN NSString *EOModelAddedNotification;
  94.     // Sent when a model is added to the model group.
  95.     // [notification object] is the added EOModel.
  96.  
  97. EOACCESS_EXTERN NSString *EOModelInvalidatedNotification;
  98.     // Notification send out by model group when model removed from group
  99.     // [notication object] is the invalidated model.  This is sent, for instance,
  100.     // inside InterfaceBuilder when the use has saved changes to a model in
  101.     // EOModeler and the objects in IB must be brought back in sync.  The old model
  102.     // is flushed and receivers of the notication (like dataSources) can call
  103.     // modelNamed: to refetch their models.
  104.  
  105. @interface NSObject (NSModelGroupClassDelegate)
  106. - (EOModelGroup *)defaultModelGroup;
  107.     // if class delegate implements, it should return the model
  108.     // group to be returned in response to [EOModelGroup defaultGroup]
  109. @end
  110.  
  111. @interface NSObject (NSModelGroupDelegate)
  112. - (EOModel *)modelGroup:(EOModelGroup *)group entityNamed:(NSString *)name;
  113.     // if delegate implements, the are reponsible for finding and
  114.     // returning the model for the given entity.
  115.  
  116. // These methods are set on EOModelGroup rether than EOEntity to provide a single point
  117. // in the code to alter the database to objects mapping.
  118.  
  119. - (EORelationship *)entity:(EOEntity *)entity relationshipForRow:(NSDictionary *)row relationship:(EORelationship *)relationship;
  120.     // Invoked when relationships are instantiated on a newly
  121.     // fetched object. The delegate can use the information in the row to
  122.     // determine with which entity the target eo should be associated and replace
  123.     // the relationship appropriately.
  124.  
  125. - (EOEntity *)subEntityForEntity:(EOEntity *)entity primaryKey:(NSDictionary *)primaryKey isFinal:(BOOL *)flag;
  126.     // Allows delegate fine tune inheritance by telling the framework from which sub-entity
  127.     // an object should be fetched based on its primary key.  The entity returned
  128.     // must be a sub-entity of the entity passed in.  If the the delegate does knows
  129.     // that the object should be fetched from the returned entity and not one of its sub-entities, 
  130.     // isFinal should be set to YES.  
  131.  
  132. - (Class)entity:(EOEntity *)entity failedToLookupClassNamed:(NSString *)className;
  133.     // Invoked when the class name specified in the entity cannot be found in the runtime.
  134.     // The delegate can take action (such as loading a bundle) to provide the entity with a
  135.     // class for name. If the delegate cannot provide anything, or if there
  136.     // is no delegate, EOGenericRecord is used.
  137.  
  138. - (Class)entity:(EOEntity *)entity classForObjectWithGlobalID:(EOGlobalID *)globalID;
  139.     // Used to fine tune inheritance.  The delegate can use information in the globalID to
  140.     // determine a subclass to be used in place of the one specified in the entity.
  141.  
  142. @end
  143.