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 <EOControl/EODetailDataSource.h>
24 #include <EOControl/EOClassDescription.h>
25 #include <EOControl/EOKeyValueCoding.h>
28 @implementation EODetailDataSource
30 - (id)initWithMasterClassDescription:(EOClassDescription *)_cd
31 detailKey:(NSString *)_relKey
33 if ((self = [super init])) {
34 self->masterClassDescription = [_cd retain];
36 [self qualifyWithRelationshipKey:_relKey ofObject:nil];
41 - (id)initWithMasterDataSource:(EODataSource *)_ds
42 detailKey:(NSString *)_relKey
44 if ((self = [self initWithMasterClassDescription:nil detailKey:_relKey])) {
45 self->masterDataSource = [_ds retain];
51 return [self initWithMasterClassDescription:nil detailKey:nil];
55 [self->detailKey release];
56 [self->masterObject release];
57 [self->masterClassDescription release];
58 [self->masterDataSource release];
64 - (void)setMasterClassDescription:(EOClassDescription *)_cd {
65 ASSIGN(self->masterClassDescription, _cd);
67 - (EOClassDescription *)masterClassDescription {
68 return self->masterClassDescription;
71 - (EODataSource *)masterDataSource {
72 return self->masterDataSource;
77 - (id)editingContext {
78 return [[self masterObject] editingContext];
84 return self->masterObject;
86 - (NSString *)detailKey {
87 return self->detailKey;
90 - (void)qualifyWithRelationshipKey:(NSString *)_relKey ofObject:(id)_object {
93 tmp = self->detailKey;
94 self->detailKey = [_relKey copy];
97 ASSIGN(self->masterObject, _object);
102 - (NSArray *)fetchObjects {
106 if ((eo = [self masterObject]) == nil)
107 return [NSArray array];
109 if ((dk = [self detailKey]) == nil)
110 return [NSArray arrayWithObject:eo];
112 return [eo valueForKey:dk];
115 - (void)insertObject:(id)_object {
119 if ((eo = [self masterObject]) == nil) {
120 [NSException raise:@"NSInternalInconsistencyException"
122 @"detail datasource %@ has no master object set "
123 @"for insertion of object %@",
126 if ((dk = [self detailKey]) == nil) {
127 [NSException raise:@"NSInternalInconsistencyException"
129 @"detail datasource %@ has no detail key set "
130 @"for insertion of object %@ into master %@",
134 [eo addObject:_object toBothSidesOfRelationshipWithKey:dk];
137 - (void)deleteObject:(id)_object {
141 if ((eo = [self masterObject]) == nil) {
142 [NSException raise:@"NSInternalInconsistencyException"
144 @"detail datasource %@ has no master object set "
145 @"for deletion of object %@",
148 if ((dk = [self detailKey]) == nil) {
149 [NSException raise:@"NSInternalInconsistencyException"
151 @"detail datasource %@ has no detail key set "
152 @"for deletion of object %@ from master %@",
156 [eo removeObject:_object fromPropertyWithKey:dk];
159 @end /* EODetailDataSource */