2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
22 #include <EOControl/EODetailDataSource.h>
23 #include <EOControl/EOClassDescription.h>
24 #include <EOControl/EOKeyValueCoding.h>
27 @implementation EODetailDataSource
29 - (id)initWithMasterClassDescription:(EOClassDescription *)_cd
30 detailKey:(NSString *)_relKey
32 if ((self = [super init])) {
33 self->masterClassDescription = [_cd retain];
35 [self qualifyWithRelationshipKey:_relKey ofObject:nil];
40 - (id)initWithMasterDataSource:(EODataSource *)_ds
41 detailKey:(NSString *)_relKey
43 if ((self = [self initWithMasterClassDescription:nil detailKey:_relKey])) {
44 self->masterDataSource = [_ds retain];
50 return [self initWithMasterClassDescription:nil detailKey:nil];
54 [self->detailKey release];
55 [self->masterObject release];
56 [self->masterClassDescription release];
57 [self->masterDataSource release];
63 - (void)setMasterClassDescription:(EOClassDescription *)_cd {
64 ASSIGN(self->masterClassDescription, _cd);
66 - (EOClassDescription *)masterClassDescription {
67 return self->masterClassDescription;
70 - (EODataSource *)masterDataSource {
71 return self->masterDataSource;
76 - (id)editingContext {
77 return [[self masterObject] editingContext];
83 return self->masterObject;
85 - (NSString *)detailKey {
86 return self->detailKey;
89 - (void)qualifyWithRelationshipKey:(NSString *)_relKey ofObject:(id)_object {
92 tmp = self->detailKey;
93 self->detailKey = [_relKey copy];
96 ASSIGN(self->masterObject, _object);
101 - (NSArray *)fetchObjects {
105 if ((eo = [self masterObject]) == nil)
106 return [NSArray array];
108 if ((dk = [self detailKey]) == nil)
109 return [NSArray arrayWithObject:eo];
111 return [eo valueForKey:dk];
114 - (void)insertObject:(id)_object {
118 if ((eo = [self masterObject]) == nil) {
119 [NSException raise:@"NSInternalInconsistencyException"
121 @"detail datasource %@ has no master object set "
122 @"for insertion of object %@",
125 if ((dk = [self detailKey]) == nil) {
126 [NSException raise:@"NSInternalInconsistencyException"
128 @"detail datasource %@ has no detail key set "
129 @"for insertion of object %@ into master %@",
133 [eo addObject:_object toBothSidesOfRelationshipWithKey:dk];
136 - (void)deleteObject:(id)_object {
140 if ((eo = [self masterObject]) == nil) {
141 [NSException raise:@"NSInternalInconsistencyException"
143 @"detail datasource %@ has no master object set "
144 @"for deletion of object %@",
147 if ((dk = [self detailKey]) == nil) {
148 [NSException raise:@"NSInternalInconsistencyException"
150 @"detail datasource %@ has no detail key set "
151 @"for deletion of object %@ from master %@",
155 [eo removeObject:_object fromPropertyWithKey:dk];
158 @end /* EODetailDataSource */