PageRenderTime 72ms CodeModel.GetById 13ms app.highlight 56ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Elements/GDataName.m

http://macfuse.googlecode.com/
Objective C | 319 lines | 206 code | 78 blank | 35 comment | 9 complexity | 13b91a588a90726e400db17aa6d1de81 MD5 | raw file
  1/* Copyright (c) 2009 Google Inc.
  2*
  3* Licensed under the Apache License, Version 2.0 (the "License");
  4* you may not use this file except in compliance with the License.
  5* You may obtain a copy of the License at
  6*
  7*     http://www.apache.org/licenses/LICENSE-2.0
  8*
  9* Unless required by applicable law or agreed to in writing, software
 10* distributed under the License is distributed on an "AS IS" BASIS,
 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12* See the License for the specific language governing permissions and
 13* limitations under the License.
 14*/
 15
 16//
 17//  GDataName.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE
 21
 22#import "GDataName.h"
 23#import "GDataValueConstruct.h"
 24
 25//
 26// private internal classes used as extensions by GDataName
 27//
 28
 29@interface GDataNameAdditional : GDataNameElement <GDataExtension>
 30@end
 31
 32@implementation GDataNameAdditional;
 33+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 34+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 35+ (NSString *)extensionElementLocalName { return @"additionalName"; }
 36@end
 37
 38@interface GDataNameFamily : GDataNameElement <GDataExtension>
 39@end
 40
 41@implementation GDataNameFamily;
 42+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 43+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 44+ (NSString *)extensionElementLocalName { return @"familyName"; }
 45@end
 46
 47@interface GDataNameFull : GDataNameElement <GDataExtension>
 48@end
 49
 50@implementation GDataNameFull;
 51+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 52+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 53+ (NSString *)extensionElementLocalName { return @"fullName"; }
 54@end
 55
 56@interface GDataNameGiven : GDataNameElement <GDataExtension>
 57@end
 58
 59@implementation GDataNameGiven;
 60+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 61+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 62+ (NSString *)extensionElementLocalName { return @"givenName"; }
 63@end
 64
 65@interface GDataNamePrefix : GDataValueElementConstruct <GDataExtension>
 66@end
 67
 68@implementation GDataNamePrefix;
 69+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 70+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 71+ (NSString *)extensionElementLocalName { return @"namePrefix"; }
 72@end
 73
 74@interface GDataNameSuffix : GDataValueElementConstruct <GDataExtension>
 75@end
 76
 77@implementation GDataNameSuffix;
 78+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 79+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 80+ (NSString *)extensionElementLocalName { return @"nameSuffix"; }
 81@end
 82
 83//
 84// GDataNameElement is the base class for the full, given, family, and
 85// additional name elements.  Each name element has a string value and
 86// an optional yomi attribute for pronunciation.
 87//
 88
 89@implementation GDataNameElement
 90
 91static NSString* const kYomiAttr = @"yomi";
 92
 93+ (id)nameElementWithString:(NSString *)str {
 94  // the contacts API does not want empty name elements
 95  if ([str length] == 0) return nil;
 96  
 97  GDataNameElement *obj = [self object];
 98  [obj setStringValue:str];
 99  return obj;
100}
101
102// internal method for converting name element types, since the setters below
103// take a generic GDataNameElement argument, but those don't have the extension
104// methods specifying localName, etc
105
106+ (id)nameElementWithNameElement:(GDataNameElement *)source {
107  GDataNameElement *obj = [self object];
108  [obj setStringValue:[source stringValue]];
109  [obj setYomi:[source yomi]];
110  return obj;
111}
112
113- (void)addParseDeclarations {
114
115  [self addLocalAttributeDeclarations:[NSArray arrayWithObject:kYomiAttr]];
116
117  [self addContentValueDeclaration];
118}
119
120- (NSString *)stringValue {
121  return [self contentStringValue];
122}
123
124- (void)setStringValue:(NSString *)str {
125  [self setContentStringValue:str];
126}
127
128- (NSString *)yomi {
129  return [self stringValueForAttribute:kYomiAttr];
130}
131
132- (void)setYomi:(NSString *)str {
133  // the contacts API does not want empty name elements
134  if ([str length] == 0) str = nil;
135
136  [self setStringValue:str forAttribute:kYomiAttr];
137}
138
139@end
140
141
142//
143// GDataName class
144//
145
146@implementation GDataName
147
148+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
149+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
150+ (NSString *)extensionElementLocalName { return @"name"; }
151
152+ (GDataName *)name {
153  GDataName* obj = [self object];
154  return obj;
155}
156
157+ (GDataName *)nameWithFullNameString:(NSString *)str {
158  GDataName* obj = [self object];
159  [obj setFullNameWithString:str];
160  return obj;
161}
162
163+ (GDataName *)nameWithPrefix:(NSString *)prefix
164                  givenString:(NSString *)first
165             additionalString:(NSString *)middle
166                 familyString:(NSString *)last
167                       suffix:(NSString *)suffix {
168  GDataName* obj = [self object];
169
170  [obj setNamePrefix:prefix];
171  [obj setGivenNameWithString:first];
172  [obj setAdditionalNameWithString:middle];
173  [obj setFamilyNameWithString:last];
174  [obj setNameSuffix:suffix];
175  return obj;
176}
177
178- (void)addExtensionDeclarations {
179
180  [super addExtensionDeclarations];
181
182  [self addExtensionDeclarationForParentClass:[self class]
183                                 childClasses:
184   [GDataNameAdditional class],
185   [GDataNameFamily class],
186   [GDataNameFull class],
187   [GDataNameGiven class],
188   [GDataNamePrefix class],
189   [GDataNameSuffix class],
190   nil];
191}
192
193#if !GDATA_SIMPLE_DESCRIPTIONS
194- (NSMutableArray *)itemsForDescription {
195
196  static struct GDataDescriptionRecord descRecs[] = {
197    { @"prefix",     @"namePrefix",                 kGDataDescValueLabeled },
198    { @"given",      @"givenName.stringValue",      kGDataDescValueLabeled },
199    { @"additional", @"additionalName.stringValue", kGDataDescValueLabeled },
200    { @"family",     @"familyName.stringValue",     kGDataDescValueLabeled },
201    { @"suffix",     @"nameSuffix",                 kGDataDescValueLabeled },
202    { @"full",       @"fullName.stringValue",       kGDataDescValueLabeled },
203    { nil, nil, (GDataDescRecTypes)0 }
204  };
205
206  NSMutableArray *items = [super itemsForDescription];
207  [self addDescriptionRecords:descRecs toItems:items];
208  return items;
209}
210#endif
211
212#pragma mark -
213
214- (GDataNameElement *)additionalName {
215  GDataNameAdditional *obj;
216
217  obj = [self objectForExtensionClass:[GDataNameAdditional class]];
218  return obj;
219}
220
221- (void)setAdditionalName:(GDataNameElement *)obj {
222  GDataNameAdditional *typedObj = [GDataNameAdditional nameElementWithNameElement:obj];
223  [self setObject:typedObj forExtensionClass:[GDataNameAdditional class]];
224}
225
226- (void)setAdditionalNameWithString:(NSString *)str {
227  GDataNameAdditional *obj = [GDataNameAdditional nameElementWithString:str];
228  [self setObject:obj forExtensionClass:[GDataNameAdditional class]];
229}
230
231
232- (GDataNameElement *)familyName {
233  GDataNameFamily *obj;
234
235  obj = [self objectForExtensionClass:[GDataNameFamily class]];
236  return obj;
237}
238
239- (void)setFamilyName:(GDataNameElement *)obj {
240  GDataNameFamily *typedObj = [GDataNameFamily nameElementWithNameElement:obj];
241  [self setObject:typedObj forExtensionClass:[GDataNameFamily class]];
242}
243
244- (void)setFamilyNameWithString:(NSString *)str {
245  GDataNameFamily *obj = [GDataNameFamily nameElementWithString:str];
246  [self setObject:obj forExtensionClass:[GDataNameFamily class]];
247}
248
249
250- (GDataNameElement *)fullName {
251  GDataNameFull *obj;
252
253  obj = [self objectForExtensionClass:[GDataNameFull class]];
254  return obj;
255}
256
257- (void)setFullName:(GDataNameElement *)obj {
258  GDataNameFull *typedObj = [GDataNameFull nameElementWithNameElement:obj];
259  [self setObject:typedObj forExtensionClass:[GDataNameFull class]];
260}
261
262- (void)setFullNameWithString:(NSString *)str {
263  GDataNameFull *obj = [GDataNameFull nameElementWithString:str];
264  [self setObject:obj forExtensionClass:[GDataNameFull class]];
265}
266
267
268- (GDataNameElement *)givenName {
269  GDataNameGiven *obj;
270
271  obj = [self objectForExtensionClass:[GDataNameGiven class]];
272  return obj;
273}
274
275- (void)setGivenName:(GDataNameElement *)obj {
276  GDataNameGiven *typedObj = [GDataNameGiven nameElementWithNameElement:obj];
277  [self setObject:typedObj forExtensionClass:[GDataNameGiven class]];
278}
279
280- (void)setGivenNameWithString:(NSString *)str {
281  GDataNameGiven *obj = [GDataNameGiven nameElementWithString:str];
282  [self setObject:obj forExtensionClass:[GDataNameGiven class]];
283}
284
285
286- (NSString *)namePrefix {
287  GDataNamePrefix *obj;
288
289  obj = [self objectForExtensionClass:[GDataNamePrefix class]];
290  return [obj stringValue];
291}
292
293- (void)setNamePrefix:(NSString *)str {
294  // the contacts API does not want empty name elements
295  if ([str length] == 0) str = nil;
296
297  GDataNamePrefix *obj = [GDataNamePrefix valueWithString:str];
298  [self setObject:obj forExtensionClass:[GDataNamePrefix class]];
299}
300
301
302- (NSString *)nameSuffix {
303  GDataNameSuffix *obj;
304
305  obj = [self objectForExtensionClass:[GDataNameSuffix class]];
306  return [obj stringValue];
307}
308
309- (void)setNameSuffix:(NSString *)str {
310  // the contacts API does not want empty name elements
311  if ([str length] == 0) str = nil;
312
313  GDataNameSuffix *obj = [GDataNameSuffix valueWithString:str];
314  [self setObject:obj forExtensionClass:[GDataNameSuffix class]];
315}
316
317@end
318
319#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE