-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCoreDeserializer.h
85 lines (70 loc) · 2.46 KB
/
CoreDeserializer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// CoreDeserializer.h
// Core Resource
//
// Created by Mike Laurence on 3/11/10.
// Copyright 2010 Mike Laurence.
//
#import <Foundation/Foundation.h>
#import "CoreManager.h"
/**
The job of CoreDeserializers is to transform serialized resource strings into
CoreResource-formatted collections (nested arrays & dictionaries). They do pass
actual resources to their targets at the time of completion, but the generation
of said resources is handed off to individual CoreResource classes, where
customized domain logic is better placed. This also allows for direct creates
and updates using property dictionaries and such, much like in ActiveRecord
where you can call #update_attributes with a hash.
*/
@interface CoreDeserializer : NSOperation {
id source;
NSString *sourceString;
Class resourceClass;
NSString *format;
CoreManager *coreManager;
NSManagedObjectContext *managedObjectContext;
// Results
NSError *error;
id resources;
// Target
id target;
SEL action;
}
@property (nonatomic, retain) id source;
@property (nonatomic, readonly) NSString* sourceString;
@property (nonatomic, assign) Class resourceClass;
@property (nonatomic, retain) NSString* format;
@property (nonatomic, retain) CoreManager *coreManager;
@property (nonatomic, retain) id target;
@property (nonatomic, assign) SEL action;
- (id) initWithSource:(id)source andResourceClass:(Class)clazz;
#pragma mark -
#pragma mark Source
- (NSString*) sourceString;
#pragma mark -
#pragma mark Format determination
- (NSString*) formatFromHeader:(NSString*)header inDictionary:(SEL)dictionarySelector;
- (NSString*) allowedFormatsFromString:(NSString*)string;
#pragma mark -
#pragma mark Deserialization
/**
Generates resources from a serialized string.
Must be overriden in subclasses to accomodate different formats, etc.
*/
- (NSArray*) resourcesFromString:(NSString*)string;
/**
Generates resources from CoreResource-formatted data collections
(basically just hands off generation to the root resource class, with a few specific options)
*/
- (NSArray*) resourcesFromData:(id)data;
@end
@interface CoreJSONDeserializer : CoreDeserializer
- (id) resourcesFromJSONData:(id)jsonData;
- (id) resourceDataFromJSONData:(id)jsonData;
- (id) resourceDataFromJSONArray:(NSArray*)array;
- (id) resourceDataFromJSONDictionary:(NSDictionary*)dict;
@end
#ifdef DDXMLDocument
@interface CoreXMLDeserializer : CoreDeserializer
@end
#endif