2
Copyright (C) 2002-2005 SKYRIX Software AG
4
This file is part of SOPE.
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
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.
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
23
#include "SoClassSecurityInfo.h"
26
#if APPLE_RUNTIME || NeXT_RUNTIME
27
@interface NSObject(Miss)
28
- (void)subclassResponsibility:(SEL)cmd;
32
@implementation SoClass
34
static BOOL debugOn = NO;
36
- (id)initWithSoSuperClass:(SoClass *)_soClass {
37
if ((self = [super init])) {
38
self->soSuperClass = [_soClass retain];
39
self->slots = [[NSMutableDictionary alloc] init];
44
return [self initWithSoSuperClass:nil];
48
[self->security release];
49
[self->slots release];
50
[self->soSuperClass release];
56
- (SoClass *)soSuperClass {
57
return self->soSuperClass;
60
/* keys (traverse hierarchy) */
62
- (BOOL)hasKey:(NSString *)_key inContext:(id)_ctx {
63
if ([self valueForSlot:_key] != nil)
66
return [self->soSuperClass hasKey:_key inContext:_ctx];
69
- (id)lookupKey:(NSString *)_key inContext:(id)_ctx {
72
if ((value = [self valueForSlot:_key]))
75
return [self->soSuperClass lookupKey:_key inContext:_ctx];
78
- (NSArray *)allKeys {
82
keys = [NSMutableSet setWithCapacity:64];
83
for (soClass = self; soClass != nil; soClass = [soClass soSuperClass])
84
[keys addObjectsFromArray:[soClass slotNames]];
85
return [keys allObjects];
88
/* slots (only works on the exact class) */
90
- (void)setValue:(id)_value forSlot:(NSString *)_key {
92
[self logWithFormat:@"set value for slot '%@': %@", _key, _value];
94
if ([_key length] == 0) {
95
[self logWithFormat:@"attempt to set value for invalid slot '%@'", _key];
98
[self->slots setObject:(_value ? _value : [NSNull null]) forKey:_key];
100
- (id)valueForSlot:(NSString *)_key {
103
value = [self->slots objectForKey:_key];
105
[self logWithFormat:@"queried value for slot '%@': %@", _key, value];
108
- (NSArray *)slotNames {
109
return self->slots ? [self->slots allKeys] : [NSArray array];
114
- (SoClassSecurityInfo *)soClassSecurityInfo {
115
if (self->security == nil)
116
self->security = [[SoClassSecurityInfo alloc] initWithSoClass:self];
117
return self->security;
120
- (NSException *)validateKey:(NSString *)_key inContext:(id)_ctx {
122
nil means: access fully granted
124
IMPORTANT: to properly support acquisition, this method must return
125
nil on keys which should be acquired (since validateKey is called before
126
the lookup is performed) !
130
r = [NSString stringWithFormat:@"tried to access private key %@", _key];
131
return [NSException exceptionWithName:@"KeyDenied" reason:r userInfo:nil];
136
- (id)instantiateObject {
137
[self subclassResponsibility:_cmd];
141
- (NSClassDescription *)soClassDescription {
145
- (NSString *)className {
151
- (id)copyWithZone:(NSZone *)_zone {
153
This is required on OSX because the class is used as a dict-key in
156
return [self retain];
161
- (NSString *)description {
164
ms = [NSMutableString stringWithCapacity:64];
165
[ms appendFormat:@"<0x%08X[%@]:", self,
166
NSStringFromClass((Class)*(void**)self)];
168
if (self->soSuperClass)
169
[ms appendFormat:@" super=0x%08X", self->soSuperClass];
171
[ms appendString:@" root"];
173
if ([self->slots count] > 0) {
174
[ms appendFormat:@" slots=%@",
175
[[self->slots allKeys] componentsJoinedByString:@","]];
178
[ms appendString:@">"];