~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/NGObjWeb/SoObjects/SoClass.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2002-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 "SoClass.h"
 
23
#include "SoClassSecurityInfo.h"
 
24
#include "common.h"
 
25
 
 
26
#if APPLE_RUNTIME || NeXT_RUNTIME
 
27
@interface NSObject(Miss)
 
28
- (void)subclassResponsibility:(SEL)cmd;
 
29
@end
 
30
#endif
 
31
 
 
32
@implementation SoClass
 
33
 
 
34
static BOOL debugOn = NO;
 
35
 
 
36
- (id)initWithSoSuperClass:(SoClass *)_soClass {
 
37
  if ((self = [super init])) {
 
38
    self->soSuperClass = [_soClass retain];
 
39
    self->slots        = [[NSMutableDictionary alloc] init];
 
40
  }
 
41
  return self;
 
42
}
 
43
- (id)init {
 
44
  return [self initWithSoSuperClass:nil];
 
45
}
 
46
 
 
47
- (void)dealloc {
 
48
  [self->security     release];
 
49
  [self->slots        release];
 
50
  [self->soSuperClass release];
 
51
  [super dealloc];
 
52
}
 
53
 
 
54
/* hierachy */
 
55
 
 
56
- (SoClass *)soSuperClass {
 
57
  return self->soSuperClass;
 
58
}
 
59
 
 
60
/* keys (traverse hierarchy) */
 
61
 
 
62
- (BOOL)hasKey:(NSString *)_key inContext:(id)_ctx {
 
63
  if ([self valueForSlot:_key] != nil)
 
64
    return YES;
 
65
  
 
66
  return [self->soSuperClass hasKey:_key inContext:_ctx];
 
67
}
 
68
 
 
69
- (id)lookupKey:(NSString *)_key inContext:(id)_ctx {
 
70
  id value;
 
71
  
 
72
  if ((value = [self valueForSlot:_key]))
 
73
    return value;
 
74
  
 
75
  return [self->soSuperClass lookupKey:_key inContext:_ctx];
 
76
}
 
77
 
 
78
- (NSArray *)allKeys {
 
79
  SoClass *soClass;
 
80
  NSMutableSet *keys;
 
81
  
 
82
  keys = [NSMutableSet setWithCapacity:64];
 
83
  for (soClass = self; soClass != nil; soClass = [soClass soSuperClass])
 
84
    [keys addObjectsFromArray:[soClass slotNames]];
 
85
  return [keys allObjects];
 
86
}
 
87
 
 
88
/* slots (only works on the exact class) */
 
89
 
 
90
- (void)setValue:(id)_value forSlot:(NSString *)_key {
 
91
  if (debugOn)
 
92
    [self logWithFormat:@"set value for slot '%@': %@", _key, _value];
 
93
 
 
94
  if ([_key length] == 0) {
 
95
    [self logWithFormat:@"attempt to set value for invalid slot '%@'", _key];
 
96
    return;
 
97
  }
 
98
  [self->slots setObject:(_value ? _value : [NSNull null]) forKey:_key];
 
99
}
 
100
- (id)valueForSlot:(NSString *)_key {
 
101
  id value;
 
102
  
 
103
  value = [self->slots objectForKey:_key];
 
104
  if (debugOn)
 
105
    [self logWithFormat:@"queried value for slot '%@': %@", _key, value];
 
106
  return value;
 
107
}
 
108
- (NSArray *)slotNames {
 
109
  return self->slots ?  [self->slots allKeys] : [NSArray array];
 
110
}
 
111
 
 
112
/* security */
 
113
 
 
114
- (SoClassSecurityInfo *)soClassSecurityInfo {
 
115
  if (self->security == nil)
 
116
    self->security = [[SoClassSecurityInfo alloc] initWithSoClass:self];
 
117
  return self->security;
 
118
}
 
119
 
 
120
- (NSException *)validateKey:(NSString *)_key inContext:(id)_ctx {
 
121
  /* 
 
122
     nil means: access fully granted 
 
123
     
 
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) !
 
127
  */
 
128
  NSString *r;
 
129
  
 
130
  r = [NSString stringWithFormat:@"tried to access private key %@", _key];
 
131
  return [NSException exceptionWithName:@"KeyDenied" reason:r userInfo:nil];
 
132
}
 
133
 
 
134
/* factory */
 
135
 
 
136
- (id)instantiateObject {
 
137
  [self subclassResponsibility:_cmd];
 
138
  return nil;
 
139
}
 
140
 
 
141
- (NSClassDescription *)soClassDescription {
 
142
  return nil;
 
143
}
 
144
 
 
145
- (NSString *)className {
 
146
  return nil;
 
147
}
 
148
 
 
149
/* NSCopying */
 
150
 
 
151
- (id)copyWithZone:(NSZone *)_zone {
 
152
  /* 
 
153
    This is required on OSX because the class is used as a dict-key in
 
154
    OFSFactoryRegistry.
 
155
  */
 
156
  return [self retain];
 
157
}
 
158
 
 
159
/* description */
 
160
 
 
161
- (NSString *)description {
 
162
  NSMutableString *ms;
 
163
  
 
164
  ms = [NSMutableString stringWithCapacity:64];
 
165
  [ms appendFormat:@"<0x%08X[%@]:", self,
 
166
        NSStringFromClass((Class)*(void**)self)];
 
167
  
 
168
  if (self->soSuperClass)
 
169
    [ms appendFormat:@" super=0x%08X", self->soSuperClass];
 
170
  else
 
171
    [ms appendString:@" root"];
 
172
  
 
173
  if ([self->slots count] > 0) {
 
174
    [ms appendFormat:@" slots=%@", 
 
175
          [[self->slots allKeys] componentsJoinedByString:@","]];
 
176
  }
 
177
  
 
178
  [ms appendString:@">"];
 
179
  return ms;
 
180
}
 
181
 
 
182
@end /* SoClass */