home *** CD-ROM | disk | FTP | other *** search
- // EOModelGroup.h
- // Copyright (c) 1995, NeXT Software, Inc. All rights reserved.
-
- #import <Foundation/Foundation.h>
- #import <EOAccess/EODefines.h>
-
- @class EOModel;
- @class EOEntity;
- @class EORelationship;
- @class EOGlobalID;
-
- // EOModelGroup represents an aggregation of related models. When a
- // model in the group needs to resolve a foreign relationship to another
- // model, it looks that model up in its group.
- //
- // The default model group contains all models for an application and any
- // frameworks the application references. The entity name space among all
- // of these models is global and consequently the same entity name should
- // not appear in any two of these models. All cross model information is
- // represented in the models by the entity name only and binding the name
- // to an actual entity is done at runtime within the EOModelGroup.
- //
- // In the majority of cases the default model group should be sufficient
- // for applications. However, if different model grouping semantics are
- // needed, programmers can create their own model group instance, add
- // whatever models they like, and then replace the defaultModelGroup with
- // the one they just created.
- //
- @interface EOModelGroup : NSObject
- {
- NSMutableDictionary *_modelsByName;
- NSMutableDictionary *_subEntitiesCache;
- id _delegate;
- struct {
- unsigned int entityNamed:1;
- unsigned int relationshipForRow:1;
- unsigned int subEntityForEntity:1;
- unsigned int failedToLookupClassNamed:1;
- unsigned int classForObjectWithGlobalID:1;
- unsigned int _RESERVED:27;
- } _delegateRespondsTo;
- }
- + (EOModelGroup *)defaultGroup;
- + (void)setDefaultGroup:(EOModelGroup *)group;
- // The default defaultGroup is [EOModelGroup globalModelGroup];
-
- + (EOModelGroup *)globalModelGroup;
- // returns a model group composed of all models in the resource directory
- // of the mainBundle, and all bundles and frameworks loaded into the app.
-
- + (void)setDelegate:(id)delegate;
- + (id)delegate;
- // Class delegate to answer defaultModelGroup.
-
- - (NSArray *)models;
- // Returns all models in group.
-
- - (NSArray *)modelNames;
- // Returns the names of all models in group.
-
- - (EOModel *)modelNamed:(NSString *)name;
- // Returns EOModel with given name, or nil if its not already loaded.
-
- - (EOModel *)modelWithPath:(NSString *)path;
- // If existing model at that path is available, it is returned.
- // Otherwise, returns nil.
-
- - (void)addModel:(EOModel *)model;
- // adds model to group
-
- - (void)addModelWithFile:(NSString *)path;
- // shortcut for adding a model obtained with
- // [[EOModel alloc] initWithContentsOfFile:path]
-
- - (void)removeModel:(EOModel *)model;
- // removes model from group and unbinds connections of other models
- // in group from it.
-
- - (EOEntity *)entityNamed:(NSString *)entityName;
- // returns the entity with the given name within any of the models
- // in the group, or nil.
-
- - (void)loadAllModelObjects;
- // This method will load any EOEntities, EOStoredProcedures, and
- // EORelationships that have not yet been loaded from the .eomodeld
-
- - (id)delegate;
- - (void)setDelegate:(id)delegate;
- // Return/Set the delegate on the EOModelGroup.
- @end
-
- // Notifications:
- EOACCESS_EXTERN NSString *EOModelAddedNotification;
- // Sent when a model is added to the model group.
- // [notification object] is the added EOModel.
-
- EOACCESS_EXTERN NSString *EOModelInvalidatedNotification;
- // Notification send out by model group when model removed from group
- // [notication object] is the invalidated model. This is sent, for instance,
- // inside InterfaceBuilder when the use has saved changes to a model in
- // EOModeler and the objects in IB must be brought back in sync. The old model
- // is flushed and receivers of the notication (like dataSources) can call
- // modelNamed: to refetch their models.
-
- @interface NSObject (NSModelGroupClassDelegate)
- - (EOModelGroup *)defaultModelGroup;
- // if class delegate implements, it should return the model
- // group to be returned in response to [EOModelGroup defaultGroup]
- @end
-
- @interface NSObject (NSModelGroupDelegate)
- - (EOModel *)modelGroup:(EOModelGroup *)group entityNamed:(NSString *)name;
- // if delegate implements, the are reponsible for finding and
- // returning the model for the given entity.
-
- // These methods are set on EOModelGroup rether than EOEntity to provide a single point
- // in the code to alter the database to objects mapping.
-
- - (EORelationship *)entity:(EOEntity *)entity relationshipForRow:(NSDictionary *)row relationship:(EORelationship *)relationship;
- // Invoked when relationships are instantiated on a newly
- // fetched object. The delegate can use the information in the row to
- // determine with which entity the target eo should be associated and replace
- // the relationship appropriately.
-
- - (EOEntity *)subEntityForEntity:(EOEntity *)entity primaryKey:(NSDictionary *)primaryKey isFinal:(BOOL *)flag;
- // Allows delegate fine tune inheritance by telling the framework from which sub-entity
- // an object should be fetched based on its primary key. The entity returned
- // must be a sub-entity of the entity passed in. If the the delegate does knows
- // that the object should be fetched from the returned entity and not one of its sub-entities,
- // isFinal should be set to YES.
-
- - (Class)entity:(EOEntity *)entity failedToLookupClassNamed:(NSString *)className;
- // Invoked when the class name specified in the entity cannot be found in the runtime.
- // The delegate can take action (such as loading a bundle) to provide the entity with a
- // class for name. If the delegate cannot provide anything, or if there
- // is no delegate, EOGenericRecord is used.
-
- - (Class)entity:(EOEntity *)entity classForObjectWithGlobalID:(EOGlobalID *)globalID;
- // Used to fine tune inheritance. The delegate can use information in the globalID to
- // determine a subclass to be used in place of the one specified in the entity.
-
- @end
-