PageRenderTime 31ms CodeModel.GetById 11ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Maps/GDataEntryMapFeature.m

http://macfuse.googlecode.com/
Objective C | 157 lines | 102 code | 36 blank | 19 comment | 8 complexity | 27f451c620c09c87b8f947bbe233a62b 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//  GDataEntryMapFeature.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_MAPS_SERVICE
 21
 22#import "GDataMapConstants.h"
 23#import "GDataEntryMapFeature.h"
 24
 25@implementation GDataEntryMapFeature
 26
 27+ (id)featureEntryWithTitle:(NSString *)str {
 28
 29  GDataEntryMapFeature *obj = [self object];
 30
 31  [obj setNamespaces:[GDataMapConstants mapsNamespaces]];
 32
 33  [obj setTitleWithString:str];
 34
 35  return obj;
 36}
 37
 38#pragma mark -
 39
 40+ (NSString *)standardEntryKind {
 41  return kGDataCategoryMapFeature;
 42}
 43
 44+ (void)load {
 45  [self registerEntryClass];
 46}
 47
 48- (void)addExtensionDeclarations {
 49
 50  [super addExtensionDeclarations];
 51
 52  Class entryClass = [self class];
 53
 54  [self addExtensionDeclarationForParentClass:entryClass
 55                                 childClasses:
 56   [GDataStructuredPostalAddress class],
 57   [GDataCustomProperty class],
 58   nil];
 59}
 60
 61#if !GDATA_SIMPLE_DESCRIPTIONS
 62- (NSMutableArray *)itemsForDescription {
 63
 64  NSString *kmlString = nil;
 65  NSArray *kmlValues = [self KMLValues];
 66
 67  if ([kmlValues count] > 0) {
 68    NSXMLElement *kmlElem = [kmlValues objectAtIndex:0];
 69    kmlString = [kmlElem XMLString];
 70  }
 71
 72  struct GDataDescriptionRecord descRecs[] = {
 73    { @"postal",     @"postalAddress",    kGDataDescValueLabeled   },
 74    { @"properties", @"customProperties", kGDataDescArrayDescs     },
 75    { @"KML",        kmlString,           kGDataDescValueIsKeyPath },
 76    { nil, nil, (GDataDescRecTypes)0 }
 77  };
 78
 79  NSMutableArray *items = [super itemsForDescription];
 80  [self addDescriptionRecords:descRecs toItems:items];
 81  return items;
 82}
 83#endif
 84
 85+ (NSString *)defaultServiceVersion {
 86  return kGDataMapsDefaultServiceVersion;
 87}
 88
 89#pragma mark -
 90
 91- (void)setPostalAddress:(GDataStructuredPostalAddress *)obj {
 92  [self setObject:obj forExtensionClass:[GDataStructuredPostalAddress class]];
 93}
 94
 95- (GDataStructuredPostalAddress *)postalAddress {
 96  return [self objectForExtensionClass:[GDataStructuredPostalAddress class]];
 97}
 98
 99- (NSArray *)customProperties {
100  return [self objectsForExtensionClass:[GDataCustomProperty class]];
101}
102
103- (void)setCustomProperties:(NSArray *)array {
104  [self setObjects:array forExtensionClass:[GDataCustomProperty class]];
105}
106
107- (void)addCustomProperty:(GDataCustomProperty *)obj {
108  [self addObject:obj forExtensionClass:[GDataCustomProperty class]];
109}
110
111// wrappers around the content element, which contains the KML
112
113- (NSArray *)KMLValues {
114  NSArray *array = [[self content] XMLValues];
115  return array;
116}
117
118- (void)setKMLValues:(NSArray *)arr {
119  GDataEntryContent *content = [self content];
120  if (content == nil) {
121    content = [GDataEntryContent contentWithXMLValue:nil
122                                                type:kGDataContentTypeKML];
123    [self setContent:content];
124  } else {
125    [content setType:kGDataContentTypeKML];
126  }
127  [content setChildXMLElements:arr];
128}
129
130- (void)addKMLValue:(NSXMLNode *)node {
131  GDataEntryContent *content = [self content];
132  if (content == nil) {
133    content = [GDataEntryContent contentWithXMLValue:node
134                                                type:kGDataContentTypeKML];
135    [self setContent:content];
136  } else {
137    [content setType:kGDataContentTypeKML];
138    [content addChildXMLElement:node];
139  }
140}
141
142// convenience accessors
143- (GDataCustomProperty *)customPropertyWithName:(NSString *)name {
144  NSArray *array = [self customProperties];
145  GDataCustomProperty *obj = [GDataUtilities firstObjectFromArray:array
146                                                   withValue:name
147                                                  forKeyPath:@"name"];
148  return obj;
149}
150
151- (GDataLink *)viewLink {
152  return [self linkWithRelAttributeValue:kGDataLinkMapView];
153}
154
155@end
156
157#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_MAPS_SERVICE