/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Contacts/GDataEntryContact.m

http://macfuse.googlecode.com/ · Objective C · 150 lines · 94 code · 37 blank · 19 comment · 2 complexity · 9cd4f9a8f388496bb8d62d3f67ab80d3 MD5 · raw file

  1. /* Copyright (c) 2008 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. // GDataEntryContact.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE
  19. #import "GDataEntryContact.h"
  20. #import "GDataContactConstants.h"
  21. // phonetic name
  22. @interface GDataContactYomiName : GDataValueElementConstruct <GDataExtension>
  23. @end
  24. @implementation GDataContactYomiName
  25. + (NSString *)extensionElementURI { return kGDataNamespaceContact; }
  26. + (NSString *)extensionElementPrefix { return kGDataNamespaceContactPrefix; }
  27. + (NSString *)extensionElementLocalName { return @"yomiName"; }
  28. @end
  29. @implementation GDataEntryContact
  30. + (GDataEntryContact *)contactEntryWithName:(GDataName *)name {
  31. GDataEntryContact *obj = [self object];
  32. [obj setNamespaces:[GDataContactConstants contactNamespaces]];
  33. [obj setName:name];
  34. return obj;
  35. }
  36. + (GDataEntryContact *)contactEntryWithFullNameString:(NSString *)str {
  37. GDataName *name = [GDataName nameWithFullNameString:str];
  38. GDataEntryContact *obj = [self contactEntryWithName:name];
  39. return obj;
  40. }
  41. + (GDataEntryContact *)contactEntryWithTitle:(NSString *)title {
  42. GDataEntryContact *obj = [self object];
  43. [obj setNamespaces:[GDataContactConstants contactNamespaces]];
  44. [obj setTitleWithString:title];
  45. return obj;
  46. }
  47. #pragma mark -
  48. + (NSString *)standardEntryKind {
  49. return kGDataCategoryContact;
  50. }
  51. + (void)load {
  52. [self registerEntryClass];
  53. }
  54. - (void)addExtensionDeclarations {
  55. [super addExtensionDeclarations];
  56. // ContactEntry extensions
  57. Class entryClass = [self class];
  58. [self addExtensionDeclarationForParentClass:entryClass
  59. childClasses:
  60. [GDataGroupMembershipInfo class],
  61. nil];
  62. }
  63. #if !GDATA_SIMPLE_DESCRIPTIONS
  64. - (NSMutableArray *)itemsForDescription {
  65. static struct GDataDescriptionRecord descRecs[] = {
  66. { @"group", @"groupMembershipInfos", kGDataDescArrayDescs },
  67. { @"version>=3:yomi", @"yomi", kGDataDescValueLabeled },
  68. { nil, nil, (GDataDescRecTypes)0 }
  69. };
  70. NSMutableArray *items = [super itemsForDescription];
  71. [self addDescriptionRecords:descRecs toItems:items];
  72. return items;
  73. }
  74. #endif
  75. + (NSString *)defaultServiceVersion {
  76. return kGDataContactDefaultServiceVersion;
  77. }
  78. #pragma mark -
  79. - (NSString *)yomi {
  80. GDATA_DEBUG_ASSERT_MIN_SERVICE_VERSION(kGDataContactServiceV3);
  81. GDataContactYomiName *obj = [self objectForExtensionClass:[GDataContactYomiName class]];
  82. return [obj stringValue];
  83. }
  84. - (void)setYomi:(NSString *)str {
  85. GDATA_DEBUG_ASSERT_MIN_SERVICE_VERSION(kGDataContactServiceV3);
  86. GDataContactYomiName *obj = nil;
  87. if ([str length] > 0) {
  88. obj = [GDataContactYomiName valueWithString:str];
  89. }
  90. [self setObject:obj forExtensionClass:[GDataContactYomiName class]];
  91. }
  92. - (NSArray *)groupMembershipInfos {
  93. return [self objectsForExtensionClass:[GDataGroupMembershipInfo class]];
  94. }
  95. - (void)setGroupMembershipInfos:(NSArray *)arr {
  96. [self setObjects:arr forExtensionClass:[GDataGroupMembershipInfo class]];
  97. }
  98. - (void)addGroupMembershipInfo:(GDataGroupMembershipInfo *)obj {
  99. [self addObject:obj forExtensionClass:[GDataGroupMembershipInfo class]];
  100. }
  101. - (void)removeGroupMembershipInfo:(GDataGroupMembershipInfo *)obj {
  102. [self removeObject:obj forExtensionClass:[GDataGroupMembershipInfo class]];
  103. }
  104. #pragma mark -
  105. - (GDataGroupMembershipInfo *)groupMembershipInfoWithHref:(NSString *)href {
  106. GDataGroupMembershipInfo *groupInfo;
  107. groupInfo = [GDataUtilities firstObjectFromArray:[self groupMembershipInfos]
  108. withValue:href
  109. forKeyPath:@"href"];
  110. return groupInfo;
  111. }
  112. @end
  113. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CONTACTS_SERVICE