/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Books/GDataVolumePrice.m

http://macfuse.googlecode.com/ · Objective C · 129 lines · 71 code · 30 blank · 28 comment · 1 complexity · 81710702ce8d6bdcf8cd2e4add1d9417 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. // GDataVolumePrice.m
  17. //
  18. // book price extension, like
  19. // <gbs:price type="RetailPrice">
  20. // <gd:money amount="15.00" currencyCode="USD" />
  21. // <gbs:promotion value="print-digital-bundle" />
  22. // </gbs:price>
  23. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_BOOKS_SERVICE
  24. #import "GDataVolumePrice.h"
  25. #import "GDataValueConstruct.h"
  26. #import "GDataBookConstants.h"
  27. @interface GDataVolumePromotion : GDataValueConstruct <GDataExtension>
  28. @end
  29. @implementation GDataVolumePromotion
  30. + (NSString *)extensionElementURI { return kGDataNamespaceBooks; }
  31. + (NSString *)extensionElementPrefix { return kGDataNamespaceBooksPrefix; }
  32. + (NSString *)extensionElementLocalName { return @"promotion"; }
  33. @end
  34. static NSString* const kTypeAttr = @"type";
  35. @implementation GDataVolumePrice
  36. + (NSString *)extensionElementURI { return kGDataNamespaceBooks; }
  37. + (NSString *)extensionElementPrefix { return kGDataNamespaceBooksPrefix; }
  38. + (NSString *)extensionElementLocalName { return @"price"; }
  39. + (GDataVolumePrice *)volumePriceWithType:(NSString *)type
  40. money:(GDataMoney *)money {
  41. GDataVolumePrice *obj = [self object];
  42. [obj setType:type];
  43. [obj setMoney:money];
  44. return obj;
  45. }
  46. - (void)addParseDeclarations {
  47. NSArray *attrs = [NSArray arrayWithObject:kTypeAttr];
  48. [self addLocalAttributeDeclarations:attrs];
  49. }
  50. - (void)addExtensionDeclarations {
  51. [super addExtensionDeclarations];
  52. [self addExtensionDeclarationForParentClass:[self class]
  53. childClasses:
  54. [GDataMoney class],
  55. [GDataVolumePromotion class],
  56. nil];
  57. }
  58. #if !GDATA_SIMPLE_DESCRIPTIONS
  59. - (NSMutableArray *)itemsForDescription {
  60. static struct GDataDescriptionRecord descRecs[] = {
  61. { @"money", @"money", kGDataDescValueLabeled },
  62. { @"promotion", @"promotion.stringValue", kGDataDescValueLabeled },
  63. { nil, nil, (GDataDescRecTypes)0 }
  64. };
  65. NSMutableArray *items = [super itemsForDescription];
  66. [self addDescriptionRecords:descRecs toItems:items];
  67. return items;
  68. }
  69. #endif
  70. #pragma mark -
  71. //
  72. // attributes
  73. //
  74. - (NSString *)type {
  75. return [self stringValueForAttribute:kTypeAttr];
  76. }
  77. - (void)setType:(NSString *)str {
  78. [self setStringValue:str forAttribute:kTypeAttr];
  79. }
  80. //
  81. // extensions
  82. //
  83. - (GDataMoney *)money {
  84. return [self objectForExtensionClass:[GDataMoney class]];
  85. }
  86. - (void)setMoney:(GDataMoney *)obj {
  87. [self setObject:obj forExtensionClass:[GDataMoney class]];
  88. }
  89. - (NSString *)promotion {
  90. GDataVolumePromotion *obj;
  91. obj = [self objectForExtensionClass:[GDataVolumePromotion class]];
  92. return [obj stringValue];
  93. }
  94. - (void)setPromotion:(NSString *)str {
  95. GDataVolumePromotion *obj = [GDataVolumePromotion valueWithString:str];
  96. [self setObject:obj forExtensionClass:[GDataVolumePromotion class]];
  97. }
  98. @end
  99. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_BOOKS_SERVICE