2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "EOCompoundDataSource.h"
24 #import <EOControl/EOControl.h>
25 #import "EODataSource+NGExtensions.h"
28 @implementation EOCompoundDataSource
30 - (id)initWithDataSources:(NSArray *)_ds {
31 if ((self = [super init])) {
32 self->sources = [_ds shallowCopy];
38 [[NSNotificationCenter defaultCenter] removeObserver:self];
39 [self->sortOrderings release];
40 [self->auxiliaryQualifier release];
41 [self->sources release];
47 - (void)setSources:(NSArray *)_sources {
48 if (self->sources != _sources) {
49 _sources = [_sources shallowCopy];
50 [self->sources release];
51 self->sources = _sources;
53 NSNotificationCenter *nc;
54 NSEnumerator *enumerator;
57 nc = [NSNotificationCenter defaultCenter];
58 enumerator = [self->sources objectEnumerator];
60 while ((obj = [enumerator nextObject])) {
62 selector:@selector(postDataSourceChangedNotification)
63 name:EODataSourceDidChangeNotification object:obj];
67 [self postDataSourceChangedNotification];
69 - (NSArray *)sources {
73 - (void)setAuxiliaryQualifier:(EOQualifier *)_q {
74 ASSIGN(self->auxiliaryQualifier, _q);
75 [self postDataSourceChangedNotification];
77 - (EOQualifier *)auxiliaryQualifier {
78 return self->auxiliaryQualifier;
81 - (void)setSortOrderings:(NSArray *)_so {
82 if (self->sortOrderings != _so) {
83 _so = [_so shallowCopy];
84 [self->sortOrderings release];
85 self->sortOrderings = _so;
87 [self postDataSourceChangedNotification];
89 - (NSArray *)sortOrderings {
90 return self->sortOrderings;
95 - (NSArray *)fetchObjects {
99 if ((count = [[self sources] count]) == 0) {
103 objs = [[[self sources] objectAtIndex:0] fetchObjects];
110 e = [[self sources] objectEnumerator];
111 while ((ds = [e nextObject])) {
114 o = [ds fetchObjects];
117 a = [NSMutableArray arrayWithCapacity:[o count]];
118 [a addObjectsFromArray:o];
122 objs = [[a shallowCopy] autorelease];
126 return [NSArray array];
128 if ([self auxiliaryQualifier])
129 objs = [objs filteredArrayUsingQualifier:[self auxiliaryQualifier]];
131 if ([self sortOrderings])
132 objs = [objs sortedArrayUsingKeyOrderArray:[self sortOrderings]];
137 - (void)insertObject:(id)_obj {
140 if ((count = [[self sources] count]) == 0)
141 [super insertObject:_obj];
143 [[[self sources] objectAtIndex:0] insertObject:_obj];
148 e = [[self sources] objectEnumerator];
149 while ((ds = [e nextObject])) {
153 [ds insertObject:_obj];
161 /* all datasources failed to insert .. */
162 [super insertObject:_obj];
164 [self postDataSourceChangedNotification];
167 - (void)deleteObject:(id)_obj {
170 if ((count = [[self sources] count]) == 0)
171 [super deleteObject:_obj];
173 [[[self sources] objectAtIndex:0] deleteObject:_obj];
178 e = [[self sources] objectEnumerator];
179 while ((ds = [e nextObject])) {
183 [ds deleteObject:_obj];
191 /* all datasources failed to delete .. */
192 [super deleteObject:_obj];
194 [self postDataSourceChangedNotification];
200 if ((count = [[self sources] count]) == 0)
201 return [super createObject];
203 return [[[self sources] objectAtIndex:0] createObject];
208 e = [[self sources] objectEnumerator];
209 while ((ds = [e nextObject])) {
212 if ((obj = [ds createObject]))
215 /* all datasources failed to create .. */
216 return [super createObject];
218 [self postDataSourceChangedNotification];
221 - (void)updateObject:(id)_obj {
224 if ((count = [[self sources] count]) == 0)
225 [super updateObject:_obj];
227 [[[self sources] objectAtIndex:0] updateObject:_obj];
232 e = [[self sources] objectEnumerator];
233 while ((ds = [e nextObject])) {
237 [ds updateObject:_obj];
245 /* all datasources failed to update .. */
246 [super updateObject:_obj];
248 [self postDataSourceChangedNotification];
251 - (EOClassDescription *)classDescriptionForObjects {
256 if ((count = [[self sources] count]) == 0)
257 return [super classDescriptionForObjects];
260 return [[[self sources] objectAtIndex:0] classDescriptionForObjects];
262 e = [[self sources] objectEnumerator];
263 while ((ds = [e nextObject])) {
264 EOClassDescription *cd;
266 if ((cd = [ds classDescriptionForObjects]))
269 /* all datasources failed to create .. */
270 return [super classDescriptionForObjects];
273 @end /* EOCompoundDataSource */