]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WebDAV/SoObjectResultEntry.m
renamed packages as discussed in the developer list
[sope] / sope-appserver / NGObjWeb / WebDAV / SoObjectResultEntry.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo 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   OGo 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 OGo; 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 // $Id$
22
23 #include "SoObjectResultEntry.h"
24 #include "common.h"
25
26 @implementation SoObjectResultEntry
27
28 - (id)initWithURI:(NSString *)_href object:(id)_o values:(NSDictionary *)_d {
29   self->href   = [_href copy];
30   self->values = [_d retain];
31   self->object = [_o retain];
32   return self;
33 }
34
35 - (void)dealloc {
36   [self->href   release];
37   [self->values release];
38   [self->object release];
39   [super dealloc];
40 }
41
42 /* keys */
43
44 - (NSArray *)attributeKeys {
45   return [self->values allKeys];
46 }
47
48 /* dict */
49
50 - (NSArray *)allKeys {
51   return [self->values allKeys];
52 }
53 - (NSEnumerator *)keyEnumerator {
54   return [self->values keyEnumerator];
55 }
56 - (id)objectForKey:(id)_key {
57   return [self->values objectForKey:_key];
58 }
59
60 /* KVC */
61
62 - (BOOL)kvcIsPreferredInKeyPath {
63   /*
64     This is difficult to grasp. It says, that the WOKeyPathAssociation
65     should *always* use -valueForKey:, even if the object has an accessors
66     method matching the key.
67     It's required for all "storage" type objects.
68   */
69   return YES;
70 }
71
72 - (id)valueForKey:(NSString *)_key {
73   if ([_key isEqualToString:@"{DAV:}href"])
74     return self->href;
75   else if ([_key isEqualToString:@"{DAV:}status"])
76     return nil;
77   else {
78 #if 1
79     return [self->values objectForKey:_key];
80 #else
81     id v = [self->values objectForKey:_key];
82     [self logWithFormat:@"key %@: %@", _key, v];
83     return v;
84 #endif
85   }
86 }
87
88 /* description */
89
90 - (NSString *)description {
91   NSMutableString *ms;
92   
93   ms = [NSMutableString stringWithCapacity:64];
94   [ms appendFormat:@"<0x%08X[%@]:", self,
95         NSStringFromClass((Class)*(void**)self)];
96   
97   if (self->href)
98     [ms appendFormat:@" uri=%@", self->href];
99
100   if (self->object) {
101     [ms appendFormat:@" obj=0x%08X[%@]", 
102           self->object, NSStringFromClass([self->object class])];
103   }
104   
105   if ([self->values count] > 0) {
106     NSEnumerator *e;
107     NSString *k;
108     
109     [ms appendString:@" values"];
110     e = [self->values keyEnumerator];
111     while ((k = [e nextObject]))
112       [ms appendFormat:@":%@=%@", k, [self->values objectForKey:k]];
113   }
114   
115   [ms appendString:@">"];
116   return ms;
117 }
118
119 @end /* SoObjectResultEntry */
120
121 @implementation SoObjectErrorEntry
122
123 - (id)initWithURI:(NSString *)_href object:(id)_o error:(NSException *)_e {
124   self->href   = [_href copy];
125   self->error  = [_e retain];
126   self->object = [_o retain];
127   return self;
128 }
129
130 - (void)dealloc {
131   [self->object release];
132   [self->href   release];
133   [self->error  release];
134   [super dealloc];
135 }
136
137 /* dict */
138
139 - (NSArray *)allKeys {
140   return nil;
141 }
142 - (NSEnumerator *)keyEnumerator {
143   return nil;
144 }
145 - (id)objectForKey:(id)_key {
146   return nil;
147 }
148
149 /* KVC */
150
151 - (BOOL)kvcIsPreferredInKeyPath {
152   return YES;
153 }
154
155 - (id)valueForKey:(NSString *)_key {
156   if ([_key isEqualToString:@"{DAV:}href"])
157     return self->href;
158   else if ([_key isEqualToString:@"{DAV:}status"])
159     return self->error;
160   else
161     return nil;
162 }
163
164 /* description */
165
166 - (NSString *)description {
167   NSMutableString *ms;
168   
169   ms = [NSMutableString stringWithCapacity:64];
170   [ms appendFormat:@"<0x%08X[%@]:", self,
171         NSStringFromClass((Class)*(void**)self)];
172   
173   if (self->href)
174     [ms appendFormat:@" uri=%@", self->href];
175
176   if (self->object) {
177     [ms appendFormat:@" obj=0x%08X[%@]", 
178           self->object, NSStringFromClass([self->object class])];
179   }
180
181   if (self->error)
182     [ms appendFormat:@" error=%@", self->error];
183   
184   [ms appendString:@">"];
185   return ms;
186 }
187
188 @end /* SoObjectErrorEntry */