4 Copyright (C) 1996 Free Software Foundation, Inc.
6 Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
9 This file is part of the GNUstep Database Library.
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
21 You should have received a copy of the GNU Library General Public
22 License along with this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 // $Id: EOFaultHandler.m 1 2004-08-20 10:38:46Z znek $
28 #include "EOFaultHandler.h"
33 # if !defined(METHOD_NULL)
34 # define METHOD_NULL NULL
38 @implementation EOFaultHandler
40 - (void)setTargetClass:(Class)_class extraData:(void *)_extraData {
41 self->targetClass = _class;
42 self->extraData = _extraData;
45 - (Class)targetClass; {
46 return self->targetClass;
49 return self->extraData;
54 - (BOOL)shouldPerformInvocation:(NSInvocation *)_invocation {
58 - (void)faultWillFire:(EOFault *)_fault {
61 - (void)completeInitializationOfObject:(id)_object {
62 [self doesNotRecognizeSelector:_cmd];
65 /* fault reflection */
67 - (Class)classForFault:(EOFault *)_fault {
69 return (object_is_instance(_fault))
73 # warning TODO: add complete implementation for Apple/NeXT runtime!
74 return [self targetClass];
78 - (BOOL)respondsToSelector:(SEL)_selector forFault:(EOFault *)_fault {
81 /* first check whether fault itself responds to selector */
83 if (class_get_instance_method(*(Class *)_fault, _selector) != METHOD_NULL)
86 # warning TODO: add implementation for NeXT/Apple runtime!
89 /* then check whether the target class does */
90 class = [self targetClass];
92 return (class_get_instance_method(class, _selector) != NULL) ? YES : NO;
94 # warning TODO: use NeXT/Apple runtime function
95 return [(NSObject *)class methodForSelector:_selector] ? YES : NO;
99 - (BOOL)conformsToProtocol:(Protocol *)_protocol forFault:(EOFault *)_fault {
103 struct objc_protocol_list* protos;
106 class = object_is_instance(_fault) ? [self targetClass] : (Class)_fault;
107 for (protos = class->protocols; protos; protos = protos->next) {
108 for (i = 0; i < protos->count; i++) {
109 if ([protos->list[i] conformsTo:_protocol])
114 # warning TODO: implement on NeXT/Apple runtime!
115 class = [self targetClass];
118 return ((sClass = [class superclass]))
119 ? [sClass conformsToProtocol:_protocol]
123 - (BOOL)isKindOfClass:(Class)_class forFault:(EOFault *)_fault {
127 class = object_is_instance(_fault) ? [self targetClass] : (Class)_fault;
128 for (; class != Nil; class = class_get_super_class(class)) {
133 # warning TODO: add implementation for NeXT/Apple runtime!
134 class = [self targetClass];
139 - (BOOL)isMemberOfClass:(Class)_class forFault:(EOFault *)_fault {
142 class = object_is_instance(_fault) ? [self targetClass] : (Class)_fault;
144 # warning TODO: add implementation for NeXT/Apple runtime!
145 class = [self targetClass];
147 return class == _class ? YES : NO;
150 - (NSMethodSignature *)methodSignatureForSelector:(SEL)_selector
151 forFault:(EOFault *)_fault
153 #if NeXT_Foundation_LIBRARY
154 // probably incorrect
155 return [_fault methodSignatureForSelector:_selector];
157 register const char *types = NULL;
159 if (_selector == NULL) // invalid selector
163 // GNU runtime selectors may be typed, a lookup may not be necessary
164 types = aSelector->sel_types;
167 /* first check for EOFault's own methods */
170 // lookup method for selector
171 struct objc_method *mth;
172 mth = class_get_instance_method(*(Class *)_fault, _selector);
173 if (mth) types = mth->method_types;
176 /* then check in target class methods */
179 // lookup method for selector
180 struct objc_method *mth;
181 mth = class_get_instance_method([self targetClass], _selector);
182 if (mth) types = mth->method_types;
186 // GNU runtime selectors may be typed, a lookup may not be necessary
188 types = _selector->sel_types;
193 return [NSMethodSignature signatureWithObjCTypes:types];
199 - (NSString *)descriptionForObject:(id)_fault {
200 return [NSString stringWithFormat:@"<%@[0x%08X]: on=%@>",
201 NSStringFromClass(*(Class *)_fault),
203 NSStringFromClass([self targetClass])];
206 @end /* EOFaultHandler */