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
23 #include "SoObjCClass.h"
24 #include "SoSelectorInvocation.h"
25 #include <NGExtensions/NGObjCRuntime.h>
26 #include <NGExtensions/NSString+Ext.h>
29 @implementation SoObjCClass
31 - (id)initWithSoSuperClass:(SoClass *)_soClass class:(Class)_clazz {
32 NSAssert(_clazz, @"missing ObjC class parameter !");
33 if ((self = [super initWithSoSuperClass:_soClass])) {
38 - (id)initWithSoSuperClass:(SoClass *)_soClass {
39 return [self initWithSoSuperClass:_soClass class:nil];
43 NSMutableDictionary *prefixMap;
47 prefixMap = [[NSMutableDictionary alloc] initWithCapacity:32];
49 [self debugWithFormat:@"scanning ObjC class %@ for SoObject methods ...",
50 NSStringFromClass(self->clazz)];
51 e = [self->clazz methodNameEnumerator];
52 while ((methodName = [e nextObject])) {
53 SoSelectorInvocation *invocation;
54 NSString *methodPrefix;
58 if ((len = [methodName length]) < 6)
61 r = [methodName rangeOfString:@"Action"];
62 if (r.length == 0) continue;
64 methodPrefix = [methodName substringToIndex:(r.location + r.length)];
66 if ((r.location + r.length) > len) {
67 /* something is beyond the xxxAction, *must* be followed by a colon */
68 if ([methodName characterAtIndex:(r.location + r.length)] != ':')
72 [self debugWithFormat:@" found an action: %@", methodName];
74 if ((invocation = [prefixMap objectForKey:methodPrefix]) == nil) {
75 invocation = [[SoSelectorInvocation alloc] init];
76 [prefixMap setObject:invocation forKey:methodPrefix];
79 [invocation addSelectorNamed:methodName];
82 e = [prefixMap keyEnumerator];
83 while ((methodName = [e nextObject])) {
84 SoSelectorInvocation *inv;
87 slotName = [methodName hasSuffix:@"Action"]
88 ? [methodName substringToIndex:([methodName length] - 6)]
90 inv = [prefixMap objectForKey:methodName];
91 [self setValue:inv forSlot:slotName];
97 - (id)instantiateObject {
98 return [[[self->clazz alloc] init] autorelease];
101 - (NSClassDescription *)soClassDescription {
102 return [NSClassDescription classDescriptionForClass:self->clazz];
105 - (NSString *)className {
106 return NSStringFromClass(self->clazz);
114 - (NSString *)description {
117 ms = [NSMutableString stringWithCapacity:64];
118 [ms appendFormat:@"<0x%08X[%@]:", self,
119 NSStringFromClass((Class)*(void**)self)];
121 if (self->soSuperClass)
122 [ms appendFormat:@" super=0x%08X", self->soSuperClass];
124 [ms appendString:@" root"];
127 [ms appendFormat:@" objc=%@", NSStringFromClass(self->clazz)];
129 [ms appendString:@" <no-objc-class>"];
131 if ([self->slots count] > 0) {
132 [ms appendFormat:@" slots=%@",
133 [[self->slots allKeys] componentsJoinedByString:@","]];
136 [ms appendString:@">"];
142 - (NSString *)loggingPrefix {
143 return [NSString stringWithFormat:@"[so-objc-class:%@]",
144 NSStringFromClass(self->clazz)];
146 - (BOOL)isDebuggingEnabled {
147 static int debugOn = -1;
149 debugOn = [[NSUserDefaults standardUserDefaults]
150 boolForKey:@"SoObjCClassDebugEnabled"] ? 1 : 0;
152 return debugOn ? YES : NO;
155 @end /* SoObjCClass */