2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "EOCompoundDataSource.h"
23 #import <EOControl/EOControl.h>
24 #import "EODataSource+NGExtensions.h"
27 @implementation EOCompoundDataSource
29 - (id)initWithDataSources:(NSArray *)_ds {
30 if ((self = [super init])) {
31 self->sources = [_ds shallowCopy];
37 [[NSNotificationCenter defaultCenter] removeObserver:self];
38 [self->sortOrderings release];
39 [self->auxiliaryQualifier release];
40 [self->sources release];
46 - (void)setSources:(NSArray *)_sources {
47 if (self->sources != _sources) {
48 _sources = [_sources shallowCopy];
49 [self->sources release];
50 self->sources = _sources;
52 NSNotificationCenter *nc;
53 NSEnumerator *enumerator;
56 nc = [NSNotificationCenter defaultCenter];
57 enumerator = [self->sources objectEnumerator];
59 while ((obj = [enumerator nextObject])) {
61 selector:@selector(postDataSourceChangedNotification)
62 name:EODataSourceDidChangeNotification object:obj];
66 [self postDataSourceChangedNotification];
68 - (NSArray *)sources {
72 - (void)setAuxiliaryQualifier:(EOQualifier *)_q {
73 ASSIGN(self->auxiliaryQualifier, _q);
74 [self postDataSourceChangedNotification];
76 - (EOQualifier *)auxiliaryQualifier {
77 return self->auxiliaryQualifier;
80 - (void)setSortOrderings:(NSArray *)_so {
81 if (self->sortOrderings != _so) {
82 _so = [_so shallowCopy];
83 [self->sortOrderings release];
84 self->sortOrderings = _so;
86 [self postDataSourceChangedNotification];
88 - (NSArray *)sortOrderings {
89 return self->sortOrderings;
94 - (NSArray *)fetchObjects {
98 if ((count = [[self sources] count]) == 0) {
102 objs = [[[self sources] objectAtIndex:0] fetchObjects];
109 e = [[self sources] objectEnumerator];
110 while ((ds = [e nextObject])) {
113 o = [ds fetchObjects];
116 a = [NSMutableArray arrayWithCapacity:[o count]];
117 [a addObjectsFromArray:o];
121 objs = [[a shallowCopy] autorelease];
125 return [NSArray array];
127 if ([self auxiliaryQualifier])
128 objs = [objs filteredArrayUsingQualifier:[self auxiliaryQualifier]];
130 if ([self sortOrderings])
131 objs = [objs sortedArrayUsingKeyOrderArray:[self sortOrderings]];
136 - (void)insertObject:(id)_obj {
139 if ((count = [[self sources] count]) == 0)
140 [super insertObject:_obj];
142 [[[self sources] objectAtIndex:0] insertObject:_obj];
147 e = [[self sources] objectEnumerator];
148 while ((ds = [e nextObject])) {
152 [ds insertObject:_obj];
160 /* all datasources failed to insert .. */
161 [super insertObject:_obj];
163 [self postDataSourceChangedNotification];
166 - (void)deleteObject:(id)_obj {
169 if ((count = [[self sources] count]) == 0)
170 [super deleteObject:_obj];
172 [[[self sources] objectAtIndex:0] deleteObject:_obj];
177 e = [[self sources] objectEnumerator];
178 while ((ds = [e nextObject])) {
182 [ds deleteObject:_obj];
190 /* all datasources failed to delete .. */
191 [super deleteObject:_obj];
193 [self postDataSourceChangedNotification];
199 if ((count = [[self sources] count]) == 0)
200 return [super createObject];
202 return [[[self sources] objectAtIndex:0] createObject];
207 e = [[self sources] objectEnumerator];
208 while ((ds = [e nextObject])) {
211 if ((obj = [ds createObject]))
214 /* all datasources failed to create .. */
215 return [super createObject];
217 [self postDataSourceChangedNotification];
220 - (void)updateObject:(id)_obj {
223 if ((count = [[self sources] count]) == 0)
224 [super updateObject:_obj];
226 [[[self sources] objectAtIndex:0] updateObject:_obj];
231 e = [[self sources] objectEnumerator];
232 while ((ds = [e nextObject])) {
236 [ds updateObject:_obj];
244 /* all datasources failed to update .. */
245 [super updateObject:_obj];
247 [self postDataSourceChangedNotification];
250 - (EOClassDescription *)classDescriptionForObjects {
255 if ((count = [[self sources] count]) == 0)
256 return [super classDescriptionForObjects];
259 return [[[self sources] objectAtIndex:0] classDescriptionForObjects];
261 e = [[self sources] objectEnumerator];
262 while ((ds = [e nextObject]) != nil) {
263 EOClassDescription *cd;
265 if ((cd = [ds classDescriptionForObjects]) != nil)
268 /* all datasources failed to create .. */
269 return [super classDescriptionForObjects];
272 @end /* EOCompoundDataSource */