GNUstep Core Data 0.1
NSPropertyDescription.m
1/* Implementation of the NSPropertyDescription class for the GNUstep
2 Core Data framework.
3 Copyright (C) 2005 Free Software Foundation, Inc.
4
5 Written by: Saso Kiselkov <diablos@manga.sk>
6 Date: August 2005
7
8 This file is part of the GNUstep Core Data framework.
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free
22 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
23 */
24
25#import "CoreDataHeaders.h"
26
27@implementation NSPropertyDescription
28
29- (void) dealloc
30{
31 TEST_RELEASE(_name);
32 TEST_RELEASE(_userInfo);
33 TEST_RELEASE(_validationPredicates);
34 TEST_RELEASE(_validationWarnings);
35
36 [super dealloc];
37}
38
39- (NSString *) name
40{
41 return _name;
42}
43
44- (void) setName: (NSString *) aName
45{
46 [self _ensureEditableWithReason: @"Tried to set name of a property "
47 @"already in use."];
48 ASSIGN(_name, aName);
49}
50
51- (NSEntityDescription *) entity
52{
53 return _entity;
54}
55
56- (BOOL) isOptional
57{
58 return _optional;
59}
60
61- (void) setOptional: (BOOL) flag
62{
63 [self _ensureEditableWithReason: @"Tried to optionality of a property "
64 @"already in use."];
65 _optional = flag;
66}
67
68- (BOOL) isTransient
69{
70 return _transient;
71}
72
73- (void) setTransient: (BOOL) flag
74{
75 [self _ensureEditableWithReason: @"Tried to set transient-ness of a"
76 @" property already in use."];
77 _transient = flag;
78}
79
80- (NSDictionary *) userInfo
81{
82 return _userInfo;
83}
84
85- (void) setUserInfo: (NSDictionary *) userInfo
86{
87 [self _ensureEditableWithReason: @"Tried to set user info of a property "
88 @"already in use."];
89 ASSIGN(_userInfo, userInfo);
90}
91
92- (NSArray *) validationPredicates
93{
94 return _validationPredicates;
95}
96
97- (NSArray *) validationWarnings
98{
99 return _validationWarnings;
100}
101
102- (void) setValidationPredicates: (NSArray *) someValidationPredicates
103 withValidationWarnings: (NSArray *) someValidationWarnings
104{
105 [self _ensureEditableWithReason: @"Tried to set validation predicates and "
106 @"validation warnings of a property "
107 @"already in use."];
108 ASSIGN(_validationPredicates, someValidationPredicates);
109 ASSIGN(_validationWarnings, someValidationWarnings);
110}
111
112// NSCopying
113
114- (id) copyWithZone: (NSZone *) zone
115{
116 NSPropertyDescription * property;
117
118 property = [NSPropertyDescription new];
119 [property setName: _name];
120 [property setOptional: _optional];
121 [property setTransient: _transient];
122 [property setUserInfo: _userInfo];
123 [property setValidationPredicates: _validationPredicates
124 withValidationWarnings: _validationWarnings];
125
126 return property;
127}
128
129// NSCoding
130
131- (id) initWithCoder: (NSCoder *) coder
132{
133 if ((self = [super init]))
134 {
135 if ([coder allowsKeyedCoding])
136 {
137 ASSIGN(_name, [coder decodeObjectForKey: @"Name"]);
138 ASSIGN(_userInfo, [coder decodeObjectForKey: @"UserInfo"]);
139 ASSIGN(_validationPredicates, [coder decodeObjectForKey:
140 @"ValidationPredicates"]);
141 ASSIGN(_validationWarnings, [coder decodeObjectForKey:
142 @"ValidationPredicates"]);
143
144 _entity = [coder decodeObjectForKey: @"Entity"];
145
146 _optional = [coder decodeBoolForKey: @"Optional"];
147 _transient = [coder decodeBoolForKey: @"Transient"];
148 }
149 else
150 {
151 ASSIGN(_name, [coder decodeObject]);
152 ASSIGN(_userInfo, [coder decodeObject]);
153 ASSIGN(_validationPredicates, [coder decodeObject]);
154 ASSIGN(_validationWarnings, [coder decodeObject]);
155
156 _entity = [coder decodeObject];
157
158 [coder decodeValueOfObjCType: @encode(typeof(_optional))
159 at: &_optional];
160 [coder decodeValueOfObjCType: @encode(typeof(_transient))
161 at: &_transient];
162 }
163 }
164 return self;
165}
166
167- (void) encodeWithCoder: (NSCoder *) coder
168{
169 if ([coder allowsKeyedCoding])
170 {
171 [coder encodeObject: _name forKey: @"Name"];
172 [coder encodeObject: _userInfo forKey: @"UserInfo"];
173 [coder encodeObject: _validationPredicates
174 forKey: @"ValidationPredicates"];
175 [coder encodeObject: _validationWarnings
176 forKey: @"ValidationWarnings"];
177
178 [coder encodeObject: _entity forKey: @"Entity"];
179
180 [coder encodeBool: _optional forKey: @"Optional"];
181 [coder encodeBool: _transient forKey: @"Transient"];
182 }
183 else
184 {
185 [coder encodeObject: _name];
186 [coder encodeObject: _userInfo];
187 [coder encodeObject: _validationPredicates];
188 [coder encodeObject: _validationWarnings];
189
190 [coder encodeObject: _entity];
191
192 [coder encodeValueOfObjCType: @encode(typeof(_optional))
193 at: &_optional];
194 [coder encodeValueOfObjCType: @encode(typeof(_transient))
195 at: &_transient];
196 }
197}
198
199@end
200
201@implementation NSPropertyDescription (GSCoreDataPrivate)
202
207- (void) _setEntity: (NSEntityDescription *) entity
208{
209 _entity = entity;
210}
211
220- (void) _ensureEditableWithReason: (NSString *) reason
221{
222 NSManagedObjectModel * model;
223
224 model = [_entity managedObjectModel];
225 if (model != nil && [model _isEditable] == NO)
226 {
227 [NSException raise: NSGenericException format: _(reason)];
228 }
229}
230
231@end