ModelGroup
Extends:
next.util.NextObject
Class Description
A ModelGroup represents an aggregation of related models (see the Model class specification for more information on models). When a model in the group needs to resolve a relationship to an entity in another model, it looks for that model in its group. Model groups allow applications to load entities and their properties only as they're needed, by distributing them among separate Models.The default model group contains all models for an application, as well as any frameworks the application references. It is automatically created on demand. The entity name space among all of these models is global; consequently, the same entity name shouldn't appear in any two of the models. All cross-model information is represented in the models by entity name only. Binding the entity name to an actual entity is done at run-time within the ModelGroup.
Setting Up A Model Group Programmatically
In the majority of applications, the automatic creation of the default model group is sufficient. However, if your particular application requires different model grouping semantics, you can create your own ModelGroup instance, add the appropriate models, and then use that instance to replace the default ModelGroup. The following code demonstrates the process:
String modelPath; // Assume this exists
ModelGroup group = new ModelGroup();
group.addModelWithPath(modelPath);
ModelGroup.setDefaultGroup(group);
Accessing Models Within a Model Group
Each model lives within a group and can form connections to other models in its group. A model can find a related model using the statement:
this.modelGroup().modelNamed(name);
A data source can locate a model using the statement:
ModelGroup.defaultGroup().modelNamed(name);
EOModeler puts models with identical names in separate groups to allow you to load two models with the same name at the same time.
Assigning ModelGroup Delegates
Your ModelGroup object should have a delegate which can influence how it finds and loads models. In addition to the delegates you assign to ModelGroup instances, the ModelGroup class itself can have a delegate. The class delegate implements a single method-defaultModelGroup
-while the instance delegate can implement the methods defined in the ModelGroupDelegates interface. For more information on ModelGroup class delegate and instance delegate methods, see the ModelGroupClassDelegates and ModelGroupDelegates interface specifications, respectively. - Constructors
- ModelGroup
- Accessing the models in a group
- addModel
- addModelWithFile
- addModelWithPath
- modelNamed
- modelNames
- models
- modelWithPath
- removeModel
- addModelWithFile
- Accessing model groups
- defaultGroup
- setDefaultGroup
- globalModelGroup
- modelGroupForObjectStoreCoordinator
- setModelGroup
- setDefaultGroup
- Searching a group for an entity
- entityNamed
- Searching a group for an object
- entityForObject
- Loading all of a group's objects
- loadAllModelObjects
- Assigning a delegate
- setClassDelegate
- classDelegate
- setDelegate
- delegate
- classDelegate
Constructors
ModelGroup
publicnext.eo.ModelGroup
()
Creates a new ModelGroup that contains no models.
Static Methods
classDelegate
public static java.lang.ObjectclassDelegate
()
Returns the ModelGroup's class delegate. This delegate optionally implements the defaultModelGroup
method (see the ModelGroupClassDelegates interface specification for more information).
See also:
setClassDelegate
defaultGroup
public static next.eo.ModelGroupdefaultGroup
()
Returns the default ModelGroup. Unless you've either specified a default model group with setDefaultGroup
or implemented the defaultModelGroup
class delegate method to return a non-null
value, this method is equivalent to globalModelGroup
.
See also:
classDelegate
globalModelGroup
public static next.eo.ModelGroupglobalModelGroup
()
Returns a ModelGroup composed of all models in the resource directory of the main bundle, as well as those in all the bundles and frameworks loaded into the application.
See also:
defaultGroup
modelGroupForObjectStoreCoordinator
public static next.eo.ModelGroupmodelGroupForObjectStoreCoordinator
(next.eo.ObjectStoreCoordinator anObjectStoreCoord
inator)
Returns the ModelGroup used by anObjectStoreCoordinator.
See also:
setModelGroup
setClassDelegate
public static voidsetClassDelegate
(java.lang.Object anObject)
Assigns anObject as the ModelGroup's class delegate. The class delegate is optional; it allows you to determine the default model group (see the ModelGroupClassDelegates interface specification for more information).
See also:
classDelegate
setDefaultGroup
public static voidsetDefaultGroup
(next.eo.ModelGroup group)
Sets the default model group to group. If you've implemented the defaultModelGroup
class delegate method to return a non-null
value, the delegate's return value overrides group as the default model group.
See also:
defaultGroup
, setClassDelegate
setModelGroup
public static voidsetModelGroup
(next.eo.ModelGroup group,
next.eo.ObjectStoreCoordinator anObjectStoreCoordinator)
Assigns group to anObjectStoreCoordinator. By default, an ObjectStoreCoordinators uses the defaultGroup
. You might want to assign a different group to an ObjectStoreCoordinator if you need to scope models to particular coordinators-if different models have the same name, or if different entities in different models have the same name.
See also:
modelGroupForObjectStoreCoordinator
Instance Methods
addModel
public voidaddModel
(next.eo.Model model)
public void addModel
(java.io.File aFile)
Adds a model to the receiver, sets the model's model group to the receiver, and posts a ModelAddedNotification. Throws an exception if the receiver already contains a Model object with the same name as the specified model.
If aFile is provided, creates a new Model object with the contents of aFile, and adds that model to perform the addition. However, the typical way to add a model to a group using a file is with the method addModelWithPath
.
See also:
models
, removeModel
addModelWithFile
public voidaddModelWithFile
(java.lang.String path)
Creates a Model object with the contents of the file identified by path, and adds the newly created model to the receiver. Throws an exception if for any reason it cannot create the model from the file specified by path. Adds the new model to the receiver with addModel
. The typical way to add a model to a group using a file is with the method addModelWithPath
.
addModelWithPath
public voidaddModelWithPath
(java.lang.String path)
Creates a Model object with the contents of the file identified by path, and adds the newly created model to the receiver. Adds the new model to the receiver with addModel
. Throws an exception if for any reason it cannot create the model from the file specified by path.
delegate
public java.lang.Objectdelegate
()
Returns the receiver's delegate, which is different from the class delegate. Each ModelGroup object can have it's own delegate in addition to the delegate that's assigned to the ModelGroup class.
See also:
setDelegate
, classDelegate
entityForObject
public next.eo.EntityentityForObject
(java.lang.Object object)
Returns the Entity associated with object from any of the models in the receiver that handle object, or null
if none of the entities in the receiver handles object.
See also:
entityForObject
(Model)
entityNamed
public next.eo.EntityentityNamed
(java.lang.String entityName)
Searches each of the Models in the receiver for the entity specified by entityName, and returns the entity if found. Returns null
if it is unable to find the specified entity.
See also:
entityNamed
(Model)
loadAllModelObjects
public voidloadAllModelObjects
()
Sends loadAllModelObjects
to each of the receiver's Models, thereby loading any Entities, Attributes, Relationships, and StoredProcedures that haven't yet been loaded from each of the Models in the receiver.
modelNamed
public next.eo.ModelmodelNamed
(java.lang.String modelName)
Returns the Model named modelName if it's part of the receiver, or null
if the receiver doesn't contain a Model object with the specified name.
See also:
modelNames
, models
modelNames
public next.util.ImmutableVectormodelNames
()
Returns an array containing the names of all of the Models in the receiver, or an empty array if the receiver contains no Models. The order of the model names in the array isn't defined.
See also:
modelNamed
, models
models
public next.util.ImmutableVectormodels
()
Returns an array containing the receiver's Models, or an empty array if the receiver contains no Models. The order of the models in the array isn't defined.
See also:
modelNamed
, modelNames
modelWithPath
public next.eo.ModelmodelWithPath
(java.lang.String path)
If the receiver contains a Model object whose path (as determined by sending path
to the Model object) is equal to path, that Model is returned. Otherwise, returns null
. java.lang.String's equals
method is used to compare the paths, and each path is standardized before comparison.
See also:
modelNamed
removeModel
public voidremoveModel
(next.eo.Model aModel)
Removes aModel from the receiver, and unbinds any connections to aModel from other Models in the receiver. Posts a ModelInvalidatedNotification to the default notification center after removing aModel from the receiver.
setDelegate
public voidsetDelegate
(java.lang.Object anObject)
Sets the receiver's delegate to anObject.
See also:
delegate
ModelGroup declares and posts the following notifications.
ModelAddedNotification
Sent by a ModelGroup when a Model object is added to the group. This notification is sent, for instance, inside Interface Builder when the user has saved changes to a model in EOModeler and the objects in Interface Builder must be brought back in sync. The old model is flushed and receivers of the notification (like data sources) can invokemodelNamed
to re-fetch their models.
Notification Object | The newly added model. |
Userinfo | None |
ModelInvalidatedNotification
Sent by a ModelGroup when a Model object is removed from the group. This notification is sent, for instance, inside Interface Builder when the user has saved changes to a model in EOModeler and the objects in Interface Builder must be brought back in sync. The old model is flushed and receivers of the notification (like data sources) can invokemodelNamed
to re-fetch their models.
Notification Object | The invalidated model. |
Userinfo | None |