PageRenderTime 48ms CodeModel.GetById 21ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 180 lines | 126 code | 29 blank | 25 comment | 10 complexity | fc9481d8b6ed65bdd01f951c99b323e7 MD5 | raw file
  1/* Copyright (c) 2007 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//  GDataGeoPt.m
 18//
 19//  NOTE: As of July 2007, GDataGeoPt is deprecated.  Use GDataGeo instead.
 20//
 21
 22#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CALENDAR_SERVICE
 23
 24#import "GDataGeoPt.h"
 25#import "GDataDateTime.h"
 26
 27@implementation GDataGeoPt
 28// geoPt element, as in
 29//   <gd:geoPt lat="27.98778" lon="86.94444" elev="8850.0"/>
 30//
 31// http://code.google.com/apis/gdata/common-elements.html#gdGeoPt
 32
 33+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 34+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 35+ (NSString *)extensionElementLocalName { return @"geoPt"; }
 36
 37+ (GDataGeoPt *)geoPtWithLabel:(NSString *)label
 38                           lat:(NSNumber *)lat
 39                           lon:(NSNumber *)lon
 40                          elev:(NSNumber *)elev
 41                          time:(GDataDateTime *)aTime {
 42  GDataGeoPt *obj = [self object];
 43  [obj setLabel:label];
 44  [obj setLat:lat];
 45  [obj setLon:lon];
 46  [obj setElev:elev];
 47  [obj setTime:aTime];
 48  return obj;
 49}
 50
 51- (id)initWithXMLElement:(NSXMLElement *)element
 52                  parent:(GDataObject *)parent {
 53  self = [super initWithXMLElement:element
 54                            parent:parent];
 55  if (self) {
 56    [self setLabel:[self stringForAttributeName:@"label"
 57                                    fromElement:element]];
 58    [self setLat:[self doubleNumberForAttributeName:@"lat"
 59                                        fromElement:element]];
 60    [self setLon:[self doubleNumberForAttributeName:@"lon"
 61                                        fromElement:element]];
 62    [self setElev:[self doubleNumberForAttributeName:@"elev"
 63                                         fromElement:element]];
 64    [self setTime:[self dateTimeForAttributeName:@"time"
 65                                     fromElement:element]];
 66  }
 67  return self;
 68}
 69
 70- (void)dealloc {
 71  [label_ release];
 72  [lat_ release];
 73  [lon_ release];
 74  [elev_ release];
 75  [time_ release];
 76  [super dealloc];
 77}
 78
 79- (id)copyWithZone:(NSZone *)zone {
 80  GDataGeoPt* newObj = [super copyWithZone:zone];
 81  [newObj setLabel:[self label]];
 82  [newObj setLat:[self lat]];
 83  [newObj setLon:[self lon]];
 84  [newObj setElev:[self elev]];
 85  [newObj setTime:[[[self time] copyWithZone:zone] autorelease]];
 86  return newObj;
 87}
 88
 89- (BOOL)isEqual:(GDataGeoPt *)other {
 90  if (self == other) return YES;
 91  if (![other isKindOfClass:[GDataGeoPt class]]) return NO;
 92
 93  // the stringValue of an NSNumber is a rounded version; compare those
 94  // rather than non-rounded versions
 95  return [super isEqual:other]
 96    && AreEqualOrBothNil([self label], [other label])
 97    && AreEqualOrBothNil([[self lat] stringValue], [[other lat] stringValue])
 98    && AreEqualOrBothNil([[self lon] stringValue], [[other lon] stringValue])
 99    && AreEqualOrBothNil([[self elev] stringValue], [[other elev] stringValue])
100    && AreEqualOrBothNil([self time], [other time]);
101}
102
103#if !GDATA_SIMPLE_DESCRIPTIONS
104- (NSMutableArray *)itemsForDescription {
105  static struct GDataDescriptionRecord descRecs[] = {
106    { @"label", @"label",            kGDataDescValueLabeled },
107    { @"lat",   @"lat",              kGDataDescValueLabeled },
108    { @"lon",   @"lon",              kGDataDescValueLabeled },
109    { @"elev",  @"elev",             kGDataDescValueLabeled },
110    { @"time",  @"time.stringValue", kGDataDescValueLabeled },
111    { nil, nil, (GDataDescRecTypes)0 }
112  };
113
114  NSMutableArray *items = [super itemsForDescription];
115  [self addDescriptionRecords:descRecs toItems:items];
116  return items;
117}
118#endif
119
120- (NSXMLElement *)XMLElement {
121
122  NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:@"gd:geoPt"];
123
124  [self addToElement:element attributeValueIfNonNil:[self label] withName:@"label"];
125  [self addToElement:element attributeValueIfNonNil:[[self lat] stringValue] withName:@"lat"];
126  [self addToElement:element attributeValueIfNonNil:[[self lon] stringValue] withName:@"lon"];
127  [self addToElement:element attributeValueIfNonNil:[[self elev] stringValue] withName:@"elev"];
128  [self addToElement:element attributeValueIfNonNil:[[self time] RFC3339String] withName:@"time"];
129
130  return element;
131}
132
133- (NSString *)label {
134  return label_;
135}
136
137- (void)setLabel:(NSString *)str {
138  [label_ autorelease];
139  label_ = [str copy];
140}
141
142- (NSNumber *)lat {
143  return lat_;
144}
145
146- (void)setLat:(NSNumber *)num {
147  [lat_ autorelease];
148  lat_ = [num copy];
149}
150
151- (NSNumber *)lon {
152  return lon_;
153}
154
155- (void)setLon:(NSNumber *)num {
156  [lon_ autorelease];
157  lon_ = [num copy];
158}
159
160- (NSNumber *)elev {
161  return elev_;
162}
163
164- (void)setElev:(NSNumber *)num {
165  [elev_ autorelease];
166  elev_ = [num copy];
167}
168
169- (GDataDateTime *)time {
170  return time_;
171}
172
173- (void)setTime:(GDataDateTime *)cdate {
174  [time_ autorelease];
175  time_ = [cdate retain];
176}
177
178@end
179
180#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CALENDAR_SERVICE