Files
RestKit/Code/ObjectMapping/RKObjectMappingProvider.m
Blake Watters f3c0995d5e Implementation of Object Mapping 2.0 design:
* Removed RestKit from inheritance hierarchy
  * Mappings are implemented as concrete classes
  * Mapper is much more flexible & powerful
  * Much more robust error handling
  * Serialization is reimplemented as an object mapping operation
  * Added ability to serialize to JSON natively
  * Reworked Core Data integration
  * Simplified the codebase substantially
2011-06-11 19:26:56 -04:00

56 lines
1.5 KiB
Objective-C

//
// RKStaticObjectMappingProvider.m
// RestKit
//
// Created by Jeremy Ellison on 5/6/11.
// Copyright 2011 Two Toasters. All rights reserved.
//
#import "RKObjectMappingProvider.h"
@implementation RKObjectMappingProvider
- (id)init {
if ((self = [super init])) {
_mappings = [NSMutableDictionary new];
_serializationMappings = [NSMutableDictionary new];
}
return self;
}
- (void)dealloc {
[_mappings release];
[_serializationMappings release];
[super dealloc];
}
- (RKObjectMapping*)objectMappingForKeyPath:(NSString*)keyPath {
return [_mappings objectForKey:keyPath];
}
- (void)setMapping:(RKObjectMapping*)mapping forKeyPath:(NSString*)keyPath {
[_mappings setValue:mapping forKey:keyPath];
}
- (void)setSerializationMapping:(RKObjectMapping *)mapping forClass:(Class)objectClass {
[_serializationMappings setValue:mapping forKey:NSStringFromClass(objectClass)];
}
- (RKObjectMapping*)serializationMappingForClass:(Class)objectClass {
return (RKObjectMapping*)[_serializationMappings objectForKey:NSStringFromClass(objectClass)];
}
- (NSDictionary*)objectMappingsByKeyPath {
return _mappings;
}
- (void)registerMapping:(RKObjectMapping*)objectMapping withRootKeyPath:(NSString*)keyPath {
// TODO: Should generate logs
[self setMapping:objectMapping forKeyPath:keyPath];
RKObjectMapping* inverseMapping = [objectMapping inverseMapping];
inverseMapping.rootKeyPath = keyPath;
[self setSerializationMapping:inverseMapping forClass:objectMapping.objectClass];
}
@end