This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
COSchema.m
70 lines (62 loc) · 1.86 KB
/
COSchema.m
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
#import "COSchema.h"
#import "COSchemaRegistry.h"
#import "COSchemaTemplate.h"
#import "COType.h"
#import <EtoileFoundation/Macros.h>
@implementation COSchema
@synthesize name = name_;
- (id) initWithSchemaTemplate: (COSchemaTemplate *)aTemplate
registry: (COSchemaRegistry *)aRegistry
{
SUPERINIT;
parentRegistry_ = aRegistry;
name_ = [[aTemplate name] copy];
parent_ = [[aTemplate parent] copy];
// setup dictionaries
COSchema *parentSchema = [self parent];
typeForAttribute_ = [[NSMutableDictionary alloc] init];
schemaNameForAttribute_ = [[NSMutableDictionary alloc] init];
if (parentSchema != nil)
{
[typeForAttribute_ addEntriesFromDictionary: parentSchema->typeForAttribute_];
[schemaNameForAttribute_ addEntriesFromDictionary: parentSchema->schemaNameForAttribute_];
}
[typeForAttribute_ addEntriesFromDictionary: [aTemplate typeForAttribute]];
[schemaNameForAttribute_ addEntriesFromDictionary: [aTemplate schemaNameForAttribute]];
return self;
}
- (void) dealloc
{
[name_ release];
[parent_ release];
[typeForAttribute_ release];
[schemaNameForAttribute_ release];
[super dealloc];
}
- (COSchema *) parent
{
return [parentRegistry_ schemaForName: parent_];
}
- (NSSet *) propertyNames
{
NSMutableSet *result;
if (parent_ == nil)
{
result = [NSMutableSet set];
}
else
{
result = [NSMutableSet setWithSet: [[self parent] propertyNames]];
}
[result addObjectsFromArray: [typeForAttribute_ allKeys]];
return [NSSet setWithSet: result];
}
- (COType) typeForProperty: (NSString *)aProperty
{
return [typeForAttribute_ objectForKey: aProperty];
}
- (COSchema *) schemaForProperty: (NSString *)aProperty
{
return [parentRegistry_ schemaForName: [schemaNameForAttribute_ objectForKey: aProperty]];
}
@end