PageRenderTime 63ms CodeModel.GetById 13ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 462 lines | 316 code | 114 blank | 32 comment | 10 complexity | b61d615bbc15cdf3aa86f7a5e2bf6f69 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//  GDataStructuredPostalAddress.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE \
 21  || GDATA_INCLUDE_MAPS_SERVICE
 22
 23#define GDATASTRUCTUREDPOSTALADDRESS_DEFINE_GLOBALS 1
 24#import "GDataStructuredPostalAddress.h"
 25
 26#import "GDataValueConstruct.h"
 27
 28//
 29// GDataStructuredPostalAddress private classes
 30//
 31
 32@interface GDataPostalAddressAgent : GDataValueElementConstruct <GDataExtension>
 33@end
 34
 35@implementation GDataPostalAddressAgent
 36+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 37+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 38+ (NSString *)extensionElementLocalName { return @"agent"; }
 39@end
 40
 41@interface GDataPostalAddressCity : GDataValueElementConstruct <GDataExtension>
 42@end
 43
 44@implementation GDataPostalAddressCity
 45+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 46+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 47+ (NSString *)extensionElementLocalName { return @"city"; }
 48@end
 49
 50@interface GDataPostalAddressCountry : GDataValueElementConstruct <GDataExtension>
 51- (NSString *)code;
 52- (void)setCode:(NSString *)str;
 53@end
 54
 55@implementation GDataPostalAddressCountry
 56
 57+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 58+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 59+ (NSString *)extensionElementLocalName { return @"country"; }
 60
 61static NSString* const kCodeAttr = @"code";
 62
 63- (void)addParseDeclarations {
 64
 65  // this is a subclass of GDataValueElementConstruct, which has its own parse
 66  // declarations
 67  [super addParseDeclarations];
 68
 69  NSArray *attrs = [NSArray arrayWithObject:kCodeAttr];
 70  [self addLocalAttributeDeclarations:attrs];
 71
 72  [self addContentValueDeclaration];
 73}
 74
 75- (NSString *)code {
 76  return [self stringValueForAttribute:kCodeAttr];
 77}
 78
 79- (void)setCode:(NSString *)str {
 80  [self setStringValue:str forAttribute:kCodeAttr];
 81}
 82@end
 83
 84@interface GDataPostalAddressFormattedAddress : GDataValueElementConstruct <GDataExtension>
 85@end
 86
 87@implementation GDataPostalAddressFormattedAddress
 88+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 89+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 90+ (NSString *)extensionElementLocalName { return @"formattedAddress"; }
 91@end
 92
 93@interface GDataPostalAddressHouseName : GDataValueElementConstruct <GDataExtension>
 94@end
 95
 96@implementation GDataPostalAddressHouseName
 97+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 98+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 99+ (NSString *)extensionElementLocalName { return @"housename"; }
100@end
101
102@interface GDataPostalAddressNeighborhood : GDataValueElementConstruct <GDataExtension>
103@end
104
105@implementation GDataPostalAddressNeighborhood
106+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
107+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
108+ (NSString *)extensionElementLocalName { return @"neighborhood"; }
109@end
110
111@interface GDataPostalAddressPOBox : GDataValueElementConstruct <GDataExtension>
112@end
113
114@implementation GDataPostalAddressPOBox
115+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
116+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
117+ (NSString *)extensionElementLocalName { return @"pobox"; }
118@end
119
120@interface GDataPostalAddressPostCode : GDataValueElementConstruct <GDataExtension>
121@end
122
123@implementation GDataPostalAddressPostCode
124+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
125+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
126+ (NSString *)extensionElementLocalName { return @"postcode"; }
127@end
128
129@interface GDataPostalAddressRegion : GDataValueElementConstruct <GDataExtension>
130@end
131
132@implementation GDataPostalAddressRegion
133+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
134+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
135+ (NSString *)extensionElementLocalName { return @"region"; }
136@end
137
138@interface GDataPostalAddressStreet : GDataValueElementConstruct <GDataExtension>
139@end
140
141@implementation GDataPostalAddressStreet
142+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
143+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
144+ (NSString *)extensionElementLocalName { return @"street"; }
145@end
146
147@interface GDataPostalAddressSubregion : GDataValueElementConstruct <GDataExtension>
148@end
149
150@implementation GDataPostalAddressSubregion
151+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
152+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
153+ (NSString *)extensionElementLocalName { return @"subregion"; }
154@end
155
156
157//
158// GDataStructuredPostalAddress
159//
160
161// attributes
162static NSString* const kLabelAttr = @"label";
163static NSString* const kMailClassAttr = @"mailClass";
164static NSString* const kPrimaryAttr = @"primary";
165static NSString* const kRelAttr = @"rel";
166static NSString* const kUsageAttr = @"usage";
167
168@implementation GDataStructuredPostalAddress
169
170+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
171+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
172+ (NSString *)extensionElementLocalName { return @"structuredPostalAddress"; }
173
174+ (id)structuredPostalAddress {
175  GDataStructuredPostalAddress *obj = [self object];
176  return obj;
177}
178
179- (void)addParseDeclarations {
180  NSArray *attrs = [NSArray arrayWithObjects:
181                    kLabelAttr, kMailClassAttr, kPrimaryAttr, kRelAttr,
182                    kUsageAttr, nil];
183  [self addLocalAttributeDeclarations:attrs];
184}
185
186- (void)addExtensionDeclarations {
187
188  [super addExtensionDeclarations];
189
190  [self addExtensionDeclarationForParentClass:[self class]
191                                   childClasses:
192   [GDataPostalAddressAgent class],
193   [GDataPostalAddressCity class],
194   [GDataPostalAddressCountry class],
195   [GDataPostalAddressFormattedAddress class],
196   [GDataPostalAddressHouseName class],
197   [GDataPostalAddressNeighborhood class],
198   [GDataPostalAddressPOBox class],
199   [GDataPostalAddressPostCode class],
200   [GDataPostalAddressRegion class],
201   [GDataPostalAddressStreet class],
202   [GDataPostalAddressSubregion class],
203   nil];
204}
205
206#if !GDATA_SIMPLE_DESCRIPTIONS
207- (NSMutableArray *)itemsForDescription {
208
209  static struct GDataDescriptionRecord descRecs[] = {
210    { @"agent",        @"agent",            kGDataDescValueLabeled },
211    { @"city",         @"city",             kGDataDescValueLabeled },
212    { @"country",      @"countryName",      kGDataDescValueLabeled },
213    { @"countryCode",  @"countryCode",      kGDataDescValueLabeled },
214    { @"fmtAddr",      @"formattedAddress", kGDataDescValueLabeled },
215    { @"house",        @"houseName",        kGDataDescValueLabeled },
216    { @"neighborhood", @"neighborhood",     kGDataDescValueLabeled },
217    { @"pobox",        @"POBox",            kGDataDescValueLabeled },
218    { @"postCode",     @"postCode",         kGDataDescValueLabeled },
219    { @"region",       @"region",           kGDataDescValueLabeled },
220    { @"street",       @"street",           kGDataDescValueLabeled },
221    { @"subregion",    @"subregion",        kGDataDescValueLabeled },
222    { nil, nil, (GDataDescRecTypes)0 }
223  };
224
225  NSMutableArray *items = [super itemsForDescription];
226  [self addDescriptionRecords:descRecs toItems:items];
227  return items;
228}
229#endif
230
231#pragma mark -
232
233// extensions
234
235- (NSString *)agent {
236  GDataPostalAddressAgent *obj;
237
238  obj = [self objectForExtensionClass:[GDataPostalAddressAgent class]];
239  return [obj stringValue];
240}
241
242- (void)setAgent:(NSString *)str {
243  GDataPostalAddressAgent *obj;
244
245  obj = [GDataPostalAddressAgent valueWithString:str];
246  [self setObject:obj forExtensionClass:[GDataPostalAddressAgent class]];
247}
248
249- (NSString *)city {
250  GDataPostalAddressCity *obj;
251
252  obj = [self objectForExtensionClass:[GDataPostalAddressCity class]];
253  return [obj stringValue];
254}
255
256- (void)setCity:(NSString *)str {
257  GDataPostalAddressCity *obj;
258
259  obj = [GDataPostalAddressCity valueWithString:str];
260  [self setObject:obj forExtensionClass:[GDataPostalAddressCity class]];
261}
262
263// country name and code are in the same element, but we'll expose them
264// as if they're independent to keep the interface simpler & KVC-compliant
265- (NSString *)countryName {
266  GDataPostalAddressCountry *obj;
267
268  obj = [self objectForExtensionClass:[GDataPostalAddressCountry class]];
269  return [obj stringValue];
270}
271
272- (void)setCountryName:(NSString *)str {
273
274  GDataPostalAddressCountry *obj;
275
276  obj = [self objectForExtensionClass:[GDataPostalAddressCountry class]];
277
278  if (obj == nil && str != nil) {
279    // lacked the element; create one only if we're really setting a value
280    obj = [GDataPostalAddressCountry valueWithString:str];
281    [self setObject:obj forExtensionClass:[GDataPostalAddressCountry class]];
282  }
283  [obj setStringValue:str];
284}
285
286- (NSString *)countryCode {
287  GDataPostalAddressCountry *obj;
288
289  obj = [self objectForExtensionClass:[GDataPostalAddressCountry class]];
290  return [obj code];
291}
292
293- (void)setCountryCode:(NSString *)str {
294  GDataPostalAddressCountry *obj;
295
296  obj = [self objectForExtensionClass:[GDataPostalAddressCountry class]];
297
298  if (obj == nil && str != nil) {
299    // lacked the element; create one only if we're really setting a value
300    obj = [GDataPostalAddressCountry valueWithString:nil];
301    [self setObject:obj forExtensionClass:[GDataPostalAddressCountry class]];
302  }
303  [obj setCode:str];
304}
305
306- (NSString *)formattedAddress {
307  GDataPostalAddressFormattedAddress *obj;
308
309  obj = [self objectForExtensionClass:[GDataPostalAddressFormattedAddress class]];
310  return [obj stringValue];
311}
312
313- (void)setFormattedAddress:(NSString *)str {
314  GDataPostalAddressFormattedAddress *obj;
315
316  obj = [GDataPostalAddressFormattedAddress valueWithString:str];
317  [self setObject:obj forExtensionClass:[GDataPostalAddressFormattedAddress class]];
318}
319
320- (NSString *)houseName {
321  GDataPostalAddressHouseName *obj;
322
323  obj = [self objectForExtensionClass:[GDataPostalAddressHouseName class]];
324  return [obj stringValue];
325}
326
327- (void)setHouseName:(NSString *)str {
328  GDataPostalAddressHouseName *obj;
329
330  obj = [GDataPostalAddressHouseName valueWithString:str];
331  [self setObject:obj forExtensionClass:[GDataPostalAddressHouseName class]];
332}
333
334- (NSString *)neighborhood {
335  GDataPostalAddressNeighborhood *obj;
336
337  obj = [self objectForExtensionClass:[GDataPostalAddressNeighborhood class]];
338  return [obj stringValue];
339}
340
341- (void)setNeighborhood:(NSString *)str {
342  GDataPostalAddressNeighborhood *obj;
343
344  obj = [GDataPostalAddressNeighborhood valueWithString:str];
345  [self setObject:obj forExtensionClass:[GDataPostalAddressNeighborhood class]];
346}
347
348- (NSString *)POBox {
349  GDataPostalAddressPOBox *obj;
350
351  obj = [self objectForExtensionClass:[GDataPostalAddressPOBox class]];
352  return [obj stringValue];
353}
354
355- (void)setPOBox:(NSString *)str {
356  GDataPostalAddressPOBox *obj;
357
358  obj = [GDataPostalAddressPOBox valueWithString:str];
359  [self setObject:obj forExtensionClass:[GDataPostalAddressPOBox class]];
360}
361
362- (NSString *)postCode {
363  GDataPostalAddressPostCode *obj;
364
365  obj = [self objectForExtensionClass:[GDataPostalAddressPostCode class]];
366  return [obj stringValue];
367}
368
369- (void)setPostCode:(NSString *)str {
370  GDataPostalAddressPostCode *obj;
371
372  obj = [GDataPostalAddressPostCode valueWithString:str];
373  [self setObject:obj forExtensionClass:[GDataPostalAddressPostCode class]];
374}
375
376- (NSString *)region {
377  GDataPostalAddressRegion *obj;
378
379  obj = [self objectForExtensionClass:[GDataPostalAddressRegion class]];
380  return [obj stringValue];
381}
382
383- (void)setRegion:(NSString *)str {
384  GDataPostalAddressRegion *obj;
385
386  obj = [GDataPostalAddressRegion valueWithString:str];
387  [self setObject:obj forExtensionClass:[GDataPostalAddressRegion class]];
388}
389
390- (NSString *)street {
391  GDataPostalAddressStreet *obj;
392
393  obj = [self objectForExtensionClass:[GDataPostalAddressStreet class]];
394  return [obj stringValue];
395}
396
397- (void)setStreet:(NSString *)str {
398  GDataPostalAddressStreet *obj;
399
400  obj = [GDataPostalAddressStreet valueWithString:str];
401  [self setObject:obj forExtensionClass:[GDataPostalAddressStreet class]];
402}
403
404- (NSString *)subregion {
405  GDataPostalAddressSubregion *obj;
406
407  obj = [self objectForExtensionClass:[GDataPostalAddressSubregion class]];
408  return [obj stringValue];
409}
410
411- (void)setSubregion:(NSString *)str {
412  GDataPostalAddressSubregion *obj;
413
414  obj = [GDataPostalAddressSubregion valueWithString:str];
415  [self setObject:obj forExtensionClass:[GDataPostalAddressSubregion class]];
416}
417
418// attributes
419
420- (NSString *)label {
421  return [self stringValueForAttribute:kLabelAttr];
422}
423
424- (void)setLabel:(NSString *)str {
425  [self setStringValue:str forAttribute:kLabelAttr];
426}
427
428- (NSString *)mailClass {
429  return [self stringValueForAttribute:kMailClassAttr];
430}
431
432- (void)setMailClass:(NSString *)str {
433  [self setStringValue:str forAttribute:kMailClassAttr];
434}
435
436- (BOOL)isPrimary {
437  return [self boolValueForAttribute:kPrimaryAttr defaultValue:NO];
438}
439
440- (void)setIsPrimary:(BOOL)flag {
441  [self setBoolValue:flag defaultValue:NO forAttribute:kPrimaryAttr];
442}
443
444- (NSString *)rel {
445  return [self stringValueForAttribute:kRelAttr];
446}
447
448- (void)setRel:(NSString *)str {
449  [self setStringValue:str forAttribute:kRelAttr];
450}
451
452- (NSString *)usage {
453  return [self stringValueForAttribute:kUsageAttr];
454}
455
456- (void)setUsage:(NSString *)str {
457  [self setStringValue:str forAttribute:kUsageAttr];
458}
459
460@end
461
462#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_*_SERVICE