/FSKit/Source/Common/FSKContributorRepository.m

http://fskit.googlecode.com/ · Objective C · 111 lines · 72 code · 16 blank · 23 comment · 6 complexity · 0cc83e1d6fb8aebaf59b25e4506819ca MD5 · raw file

  1. //
  2. // FSKUserRepository.m
  3. // FSKit
  4. //
  5. // Created by Logan Allred on 8/24/08.
  6. // Copyright 2008 RedBugz Software. All rights reserved.
  7. //
  8. #import "FSKContributorRepository.h"
  9. #import "FSKContributorReadRequest.h"
  10. @implementation FSKContributorRepository
  11. static FSKContributorRepository *sharedInstance = nil;
  12. + (FSKContributorRepository*)instanceWithConnection:(FSKConnection *)aConnection
  13. {
  14. @synchronized(self) {
  15. if (sharedInstance == nil) {
  16. [[self alloc] initWithConnection:aConnection]; // assignment not done here
  17. }
  18. }
  19. return sharedInstance;
  20. }
  21. + (id)allocWithZone:(NSZone *)zone
  22. {
  23. @synchronized(self) {
  24. if (sharedInstance == nil) {
  25. sharedInstance = [super allocWithZone:zone];
  26. return sharedInstance; // assignment and return on first allocation
  27. }
  28. }
  29. return nil; //on subsequent allocation attempts return nil
  30. }
  31. - (id)copyWithZone:(NSZone *)zone
  32. {
  33. return self;
  34. }
  35. - (id)retain
  36. {
  37. return self;
  38. }
  39. - (NSUInteger)retainCount
  40. {
  41. return UINT_MAX; //denotes an object that cannot be released
  42. }
  43. - (void)release
  44. {
  45. //do nothing
  46. }
  47. - (id)autorelease
  48. {
  49. return self;
  50. }
  51. - (id)initWithConnection:(FSKConnection *)aConnection
  52. {
  53. if ((self = [super init]) != nil)
  54. {
  55. repository = [[[FSKRepository alloc] initWithIdentifier:[self className]] retain];
  56. connection = [aConnection retain];
  57. }
  58. return self;
  59. }
  60. - (void)dealloc
  61. {
  62. [connection release];
  63. [repository release];
  64. [super dealloc];
  65. }
  66. - (FSKContributor *)contributorForId:(NSString *)contributorId;
  67. {
  68. // FSKUser *cachedUser = [cache objectForKey:userId];
  69. // if (!cachedUser)
  70. // {
  71. // // fetch and put in cache
  72. // cachedUser = [[FSKUser alloc] init];
  73. // [cachedUser setValue:userId forKey:@"userId"];
  74. //
  75. // [FSKUserReadRequest fetchUserDataWithIds:[NSSet setWithObject:userId] parameters:nil connection:connection delegate:self selector:@selector(request:didReturnResponse:)];
  76. // }
  77. //
  78. // return cachedUser;
  79. return nil;
  80. }
  81. - (void)request:(FSKRequest *)request
  82. didReturnResponse:(FSKResponse *)response
  83. {
  84. NSLog(@"%s %@", __PRETTY_FUNCTION__, response);
  85. // FSKUserResponse *userResponse = (FSKUserResponse *)response;
  86. // FSKUser *responseUser = [[userResponse userList] lastObject];
  87. // FSKUser *cachedUser = [cache objectForKey:[responseUser userId]];
  88. // [cache setObject:responseUser forKey:[[userResponse valueForKey:@"requestedIds"] lastObject]];
  89. }
  90. - (void)request:(FSKRequest *)request
  91. didFailWithError:(FSKError *)error
  92. {
  93. NSLog(@"%s %@", __PRETTY_FUNCTION__, error);
  94. }
  95. @end