mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-01 22:42:51 +08:00
Since OM 2.0 connection of relationships happened during the object mapping operation instead of aggregately at the end of the process. In this commit, we have introduced a lightweight queue for deferring portions of the mapping operation until a larger aggregate mapping has completed. The changes are as follows: * Introduced RKMappingOperationQueue for queueing portions of mapping. This is a synchronous queue modeled off of NSOperationQueue that does NOT use threading (for Core Data friendliness). * RKObjectMappingOperation now has a RKMappingOperationQueue queue property that defaults to nil * RKObjectMappingOperation instances built via RKObjectMapper will has a mapping operation queue assigned to the property. * If a queue is present, RKManagedObjectMappingOperation will use it to defer the connection of relationships. * At the end of an RKObjectMapper process, the mapping operation queue used by all mapping operations created during the process will be executed. This allows all relationships to be connected after all object creation has completed. The queue is general purpose, though currently only used for the connection of relationships.
73 lines
3.1 KiB
Objective-C
73 lines
3.1 KiB
Objective-C
//
|
|
// RKObjectMapper.h
|
|
// RestKit
|
|
//
|
|
// Created by Blake Watters on 5/6/11.
|
|
// Copyright 2011 Two Toasters
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#import "RKObjectMapping.h"
|
|
#import "RKObjectMappingOperation.h"
|
|
#import "RKObjectMappingResult.h"
|
|
#import "RKObjectMappingProvider.h"
|
|
#import "RKMappingOperationQueue.h"
|
|
#import "../Support/Support.h"
|
|
|
|
/**
|
|
Maps parsed primitive dictionary and arrays into objects. This is the primary entry point
|
|
for an external object mapping operation.
|
|
*/
|
|
@class RKObjectMapper;
|
|
|
|
@protocol RKObjectMapperDelegate <NSObject>
|
|
|
|
@optional
|
|
|
|
- (void)objectMapperWillBeginMapping:(RKObjectMapper*)objectMapper;
|
|
- (void)objectMapperDidFinishMapping:(RKObjectMapper*)objectMapper;
|
|
- (void)objectMapper:(RKObjectMapper*)objectMapper didAddError:(NSError*)error;
|
|
- (void)objectMapper:(RKObjectMapper*)objectMapper didFindMappableObject:(id)object atKeyPath:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)mapping;
|
|
- (void)objectMapper:(RKObjectMapper*)objectMapper didNotFindMappableObjectAtKeyPath:(NSString*)keyPath;
|
|
|
|
- (void)objectMapper:(RKObjectMapper*)objectMapper willMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)objectMapping;
|
|
- (void)objectMapper:(RKObjectMapper*)objectMapper didMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)objectMapping;
|
|
- (void)objectMapper:(RKObjectMapper*)objectMapper didFailMappingFromObject:(id)sourceObject toObject:(id)destinationObject withError:(NSError*)error atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)objectMapping;
|
|
@end
|
|
|
|
@interface RKObjectMapper : NSObject {
|
|
id _sourceObject;
|
|
id _targetObject;
|
|
RKObjectMappingProvider* _mappingProvider;
|
|
id<RKObjectMapperDelegate> _delegate;
|
|
NSMutableArray* _errors;
|
|
RKMappingOperationQueue *_operationQueue;
|
|
}
|
|
|
|
@property (nonatomic, readonly) id sourceObject;
|
|
@property (nonatomic, assign) id targetObject;
|
|
@property (nonatomic, readonly) RKObjectMappingProvider* mappingProvider;
|
|
@property (nonatomic, assign) id<RKObjectMapperDelegate> delegate;
|
|
@property (nonatomic, readonly) NSArray* errors;
|
|
|
|
+ (id)mapperWithObject:(id)object mappingProvider:(RKObjectMappingProvider*)mappingProvider;
|
|
- (id)initWithObject:(id)object mappingProvider:(RKObjectMappingProvider*)mappingProvider;
|
|
|
|
// Primary entry point for the mapper. Examines the type of object and processes it appropriately...
|
|
- (RKObjectMappingResult*)performMapping;
|
|
- (NSUInteger)errorCount;
|
|
|
|
@end
|