]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/SOGo/SOGoObject.m
03087268b06e5a65be7b0a8d333c4a99c21d357c
[scalable-opengroupware.org] / SOGo / SoObjects / SOGo / SOGoObject.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 "SOGoObject.h"
24 #include "SOGoUserFolder.h"
25 #include "common.h"
26
27 @implementation SOGoObject
28
29 - (BOOL)doesRetainContainer {
30   return YES;
31 }
32
33 - (id)initWithName:(NSString *)_name inContainer:(id)_container {
34   if ((self = [super init])) {
35     self->nameInContainer = [_name copy];
36     self->container = 
37       [self doesRetainContainer] ? [_container retain] : _container;
38   }
39   return self;
40 }
41 - (id)init {
42   return [self initWithName:nil inContainer:nil];
43 }
44
45 - (void)dealloc {
46   if ([self doesRetainContainer])
47     [self->container release];
48   [self->nameInContainer release];
49   [super dealloc];
50 }
51
52 /* accessors */
53
54 - (NSString *)nameInContainer {
55   return self->nameInContainer;
56 }
57 - (id)container {
58   return self->container;
59 }
60
61 /* ownership */
62
63 - (NSString *)ownerInContext:(id)_ctx {
64   return [[self container] ownerInContext:_ctx];
65 }
66
67 /* looking up shared objects */
68
69 - (SOGoUserFolder *)lookupUserFolder {
70   if (![self->container respondsToSelector:_cmd])
71     return nil;
72   
73   return [self->container lookupUserFolder];
74 }
75 - (SOGoGroupsFolder *)lookupGroupsFolder {
76   return [[self lookupUserFolder] lookupGroupsFolder];
77 }
78
79 - (void)sleep {
80   if ([self doesRetainContainer])
81     [self->container release];
82   self->container = nil;
83 }
84
85 /* operations */
86
87 - (NSException *)delete {
88   return [NSException exceptionWithHTTPStatus:500 /* not implemented */
89                       reason:@"delete not yet implemented, sorry ..."];
90 }
91
92 /* KVC hacks */
93
94 - (id)valueForUndefinedKey:(NSString *)_key {
95   return nil;
96 }
97
98 /* WebDAV */
99
100 - (NSString *)davDisplayName {
101   return [self nameInContainer];
102 }
103
104 - (id)DELETEAction:(id)_ctx {
105   return [self delete];
106 }
107
108 /* description */
109
110 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
111   if (self->nameInContainer != nil) 
112     [_ms appendFormat:@" name=%@", self->nameInContainer];
113   if (self->container != nil) {
114     [_ms appendFormat:@" container=0x%08X/%@", 
115            self->container, [self->container valueForKey:@"nameInContainer"]];
116   }
117 }
118
119 - (NSString *)description {
120   NSMutableString *ms;
121
122   ms = [NSMutableString stringWithCapacity:64];
123   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
124   [self appendAttributesToDescription:ms];
125   [ms appendString:@">"];
126   return ms;
127 }
128
129 @end /* SOGoObject */