]> err.no Git - sope/blob - sope-core/NGExtensions/EOExt.subproj/EOFetchSpecification+plist.m
8049e2e72deb24f021bc4a1aaa1448791c4f2ebe
[sope] / sope-core / NGExtensions / EOExt.subproj / EOFetchSpecification+plist.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include <NGExtensions/EOFetchSpecification+plist.h>
23 #include <EOControl/EOControl.h>
24 #include "common.h"
25
26 @implementation EOFetchSpecification(plist)
27
28 - (id)initWithDictionary:(NSDictionary *)_dictionary {
29   if ((self = [self init])) {
30     id tmp;
31     
32     if ((tmp = [_dictionary objectForKey:@"qualifier"])) {
33       if ([tmp isKindOfClass:[NSDictionary class]])
34         tmp = [EOQualifier qualifierToMatchAllValues:tmp];
35       else
36         tmp = [EOQualifier qualifierWithQualifierFormat:tmp];
37       
38       [self setQualifier:tmp];
39     }
40     
41     if ((tmp = [_dictionary objectForKey:@"sortOrderings"])) {
42       NSArray        *sos = nil;
43       EOSortOrdering *so;
44       
45       if ([tmp isKindOfClass:[NSArray class]]) {
46         NSMutableArray *result  = nil;
47         NSEnumerator   *objEnum;
48         id             obj;
49         
50         objEnum = [tmp objectEnumerator];
51         result = [NSMutableArray arrayWithCapacity:8];
52         while ((obj = [objEnum nextObject])) {
53           so = [[EOSortOrdering alloc] initWithPropertyList:obj owner:nil];
54           [so autorelease];
55           if (so)
56             [result addObject:so];
57         }
58         sos = [NSArray arrayWithArray:result];
59       }
60       else {
61         so = [[[EOSortOrdering alloc] initWithPropertyList:tmp owner:nil] 
62                                autorelease];
63           
64         if (so)
65           sos = [NSArray arrayWithObject:so];
66       }
67       [self setSortOrderings:sos];
68     }
69     
70     if ((tmp = [_dictionary objectForKey:@"fetchLimit"])) {
71       if ([tmp respondsToSelector:@selector(intValue)])
72         [self setFetchLimit:[tmp intValue]];
73       else
74         NSLog(@"%s: invalid fetchLimit key !", __PRETTY_FUNCTION__);
75     }
76     
77     if ((tmp = [_dictionary objectForKey:@"hints"])) {
78       if ([tmp isKindOfClass:[NSDictionary class]])
79         [self setHints:tmp];
80       else
81         NSLog(@"%s: invalid hints key !", __PRETTY_FUNCTION__);
82     }
83     
84     if ([self->hints objectForKey:@"addDocumentsAsObserver"] == nil) {
85       NSMutableDictionary *hnts;
86
87       hnts = [[NSMutableDictionary alloc] initWithDictionary:self->hints];
88       [hnts setObject:[NSNumber numberWithBool:NO]
89             forKey:@"addDocumentsAsObserver"];
90       [self setHints:hnts];
91       [hnts release];
92     }
93   }
94   return self;
95 }
96 - (id)initWithString:(NSString *)_string {
97   EOQualifier *q;
98   
99   q = [EOQualifier qualifierWithQualifierFormat:_string];
100   
101   return [self initWithEntityName:nil
102                qualifier:q
103                sortOrderings:nil
104                usesDistinct:NO isDeep:NO hints:nil];
105 }
106
107 - (id)initWithPropertyList:(id)_plist owner:(id)_owner {
108   if ([_plist isKindOfClass:[NSDictionary class]])
109     return [self initWithDictionary:_plist];
110   
111   if ([_plist isKindOfClass:[NSString class]])
112     return [self initWithString:_plist];
113   
114   if ([_plist isKindOfClass:[self class]]) {
115     [self release];
116     return [_plist copy];
117   }
118
119   [self release];
120   return nil;
121 }
122 - (id)initWithPropertyList:(id)_plist {
123   return [self initWithPropertyList:_plist owner:nil];
124 }
125
126 @end /* EOFetchSpecification(plist) */