4
Copyright (C) 1996 Free Software Foundation, Inc.
6
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
9
This file is part of the GNUstep Database Library.
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Library General Public
13
License as published by the Free Software Foundation; either
14
version 2 of the License, or (at your option) any later version.
16
This library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Library General Public License for more details.
21
You should have received a copy of the GNU Library General Public
22
License along with this library; see the file COPYING.LIB.
23
If not, write to the Free Software Foundation,
24
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#include "EOModelGroup.h"
30
#import <EOControl/EOClassDescription.h>
33
@implementation EOModelGroup
35
static EOModelGroup *defaultGroup = nil;
36
static id<EOModelGroupClassDelegation> classDelegate = nil;
38
+ (void)setDefaultGroup:(EOModelGroup *)_group {
39
ASSIGN(defaultGroup, _group);
42
+ (EOModelGroup *)defaultGroup {
48
group = [[self classDelegate] defaultModelGroup];
51
group = [self globalModelGroup];
56
+ (EOModelGroup *)globalModelGroup {
57
static EOModelGroup *globalModelGroup = nil;
58
NSEnumerator *bundles;
62
return globalModelGroup;
64
globalModelGroup = [[EOModelGroup alloc] init];
66
bundles = [[NSBundle allBundles] objectEnumerator];
67
while ((bundle = [bundles nextObject])) {
71
paths = [[bundle pathsForResourcesOfType:@"eomodel" inDirectory:nil]
74
while ((path = [paths nextObject])) {
77
model = [[EOModel alloc] initWithContentsOfFile:path];
79
NSLog(@"WARNING: couldn't load model %@", path);
82
[globalModelGroup addModel:model];
87
return globalModelGroup;
90
+ (void)setClassDelegate:(id<EOModelGroupClassDelegation>)_delegate {
91
ASSIGN(classDelegate, _delegate);
93
+ (id<EOModelGroupClassDelegation>)classDelegate {
98
self->nameToModel = [[NSMutableDictionary allocWithZone:[self zone]] init];
103
RELEASE(self->nameToModel);
107
/* instance delegate */
109
- (void)setDelegate:(id<EOModelGroupDelegation>)_delegate {
110
self->delegate = _delegate;
112
- (id<EOModelGroupDelegation>)delegate {
113
return self->delegate;
118
- (void)addModel:(EOModel *)_model {
121
name = [_model name];
122
if (name == nil) name = [[_model path] lastPathComponent];
124
if ([self->nameToModel objectForKey:name]) {
125
[NSException raise:@"NSInvalidArgumentException"
126
format:@"model group %@ already contains model named %@",
130
[self->nameToModel setObject:_model forKey:name];
132
[[NSNotificationCenter defaultCenter]
133
postNotificationName:@"EOModelAddedNotification"
137
- (void)removeModel:(EOModel *)_model {
140
allNames = [self->nameToModel allKeysForObject:_model];
141
[self->nameToModel removeObjectsForKeys:allNames];
143
[[NSNotificationCenter defaultCenter]
144
postNotificationName:@"EOModelInvalidatedNotification"
148
- (EOModel *)addModelWithFile:(NSString *)_path {
151
model = [[EOModel alloc] initWithContentsOfFile:_path];
156
[self addModel:model];
161
- (EOModel *)modelNamed:(NSString *)_name {
162
return [self->nameToModel objectForKey:_name];
164
- (EOModel *)modelWithPath:(NSString *)_path {
169
p = [_path stringByStandardizingPath];
170
if (p == nil) p = _path;
172
e = [self->nameToModel objectEnumerator];
173
while ((m = [e nextObject])) {
176
mp = [[m path] stringByStandardizingPath];
177
if (mp == nil) mp = [m path];
185
- (NSArray *)modelNames {
186
return [self->nameToModel allKeys];
188
- (NSArray *)models {
189
return [self->nameToModel allValues];
192
- (void)loadAllModelObjects {
193
[[self->nameToModel allValues] makeObjectsPerformSelector:_cmd];
198
- (EOEntity *)entityForObject:(id)_object {
202
e = [self->nameToModel objectEnumerator];
203
while ((m = [e nextObject])) {
206
if ((entity = [m entityForObject:_object]))
212
- (EOEntity *)entityNamed:(NSString *)_name {
216
e = [self->nameToModel objectEnumerator];
217
while ((m = [e nextObject])) {
220
if ((entity = [m entityNamed:_name]))
226
- (EOFetchSpecification *)fetchSpecificationNamed:(NSString *)_name
227
entityNamed:(NSString *)_entityName
229
return [[self entityNamed:_entityName] fetchSpecificationNamed:_name];
234
- (NSString *)description {
235
return [NSString stringWithFormat:@"<%@[0x%08X]: models=%@>",
236
NSStringFromClass([self class]),
238
[[self modelNames] componentsJoinedByString:@","]];
241
@end /* EOModelGroup */