2 Copyright (C) 2002-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
24 #include "SoClassSecurityInfo.h"
27 #if APPLE_RUNTIME || NeXT_RUNTIME
28 @interface NSObject(Miss)
29 - (void)subclassResponsibility:(SEL)cmd;
33 @implementation SoClass
35 static BOOL debugOn = NO;
37 - (id)initWithSoSuperClass:(SoClass *)_soClass {
38 if ((self = [super init])) {
39 self->soSuperClass = [_soClass retain];
40 self->slots = [[NSMutableDictionary alloc] init];
45 return [self initWithSoSuperClass:nil];
49 [self->security release];
50 [self->slots release];
51 [self->soSuperClass release];
57 - (SoClass *)soSuperClass {
58 return self->soSuperClass;
61 /* keys (traverse hierarchy) */
63 - (BOOL)hasKey:(NSString *)_key inContext:(id)_ctx {
64 if ([self valueForSlot:_key] != nil)
67 return [self->soSuperClass hasKey:_key inContext:_ctx];
70 - (id)lookupKey:(NSString *)_key inContext:(id)_ctx {
73 if ((value = [self valueForSlot:_key]))
76 return [self->soSuperClass lookupKey:_key inContext:_ctx];
79 - (NSArray *)allKeys {
83 keys = [NSMutableSet setWithCapacity:64];
84 for (soClass = self; soClass != nil; soClass = [soClass soSuperClass])
85 [keys addObjectsFromArray:[soClass slotNames]];
86 return [keys allObjects];
89 /* slots (only works on the exact class) */
91 - (void)setValue:(id)_value forSlot:(NSString *)_key {
93 [self logWithFormat:@"set value for slot '%@': %@", _key, _value];
95 if ([_key length] == 0) {
96 [self logWithFormat:@"attempt to set value for invalid slot '%@'", _key];
99 [self->slots setObject:(_value ? _value : [NSNull null]) forKey:_key];
101 - (id)valueForSlot:(NSString *)_key {
104 value = [self->slots objectForKey:_key];
106 [self logWithFormat:@"queried value for slot '%@': %@", _key, value];
109 - (NSArray *)slotNames {
110 return self->slots ? [self->slots allKeys] : [NSArray array];
115 - (SoClassSecurityInfo *)soClassSecurityInfo {
116 if (self->security == nil)
117 self->security = [[SoClassSecurityInfo alloc] initWithSoClass:self];
118 return self->security;
121 - (NSException *)validateKey:(NSString *)_key inContext:(id)_ctx {
123 nil means: access fully granted
125 IMPORTANT: to properly support acquisition, this method must return
126 nil on keys which should be acquired (since validateKey is called before
127 the lookup is performed) !
131 r = [NSString stringWithFormat:@"tried to access private key %@", _key];
132 return [NSException exceptionWithName:@"KeyDenied" reason:r userInfo:nil];
137 - (id)instantiateObject {
138 [self subclassResponsibility:_cmd];
142 - (NSClassDescription *)soClassDescription {
146 - (NSString *)className {
152 - (id)copyWithZone:(NSZone *)_zone {
154 This is required on OSX because the class is used as a dict-key in
157 return [self retain];
162 - (NSString *)description {
165 ms = [NSMutableString stringWithCapacity:64];
166 [ms appendFormat:@"<0x%08X[%@]:", self,
167 NSStringFromClass((Class)*(void**)self)];
169 if (self->soSuperClass)
170 [ms appendFormat:@" super=0x%08X", self->soSuperClass];
172 [ms appendString:@" root"];
174 if ([self->slots count] > 0) {
175 [ms appendFormat:@" slots=%@",
176 [[self->slots allKeys] componentsJoinedByString:@","]];
179 [ms appendString:@">"];