diff --git a/ChangeLog b/ChangeLog index 9740866a3..29b2a5efe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2000-09-19 Richard Frith-Macdonald + + * Source/NSURLHandle.m: Implemented subclass registry. + 2000-09-19 Fred Kiefer * Headers/gnustep/base/Unicode.h: diff --git a/Source/NSURLHandle.m b/Source/NSURLHandle.m index 1c27c7649..5e79a48b7 100644 --- a/Source/NSURLHandle.m +++ b/Source/NSURLHandle.m @@ -39,28 +39,54 @@ how it should work... //============================================================================= @implementation NSURLHandle -//----------------------------------------------------------------------------- -+ (void) registerURLHandleClass: (Class)_urlHandleSubclass +static NSMutableArray *registry = nil; + ++ (void) initialize { - //FIXME - [self notImplemented: _cmd]; + if (self == [NSURLHandle class]) + { + registry = [NSMutableArray new]; + } } -//----------------------------------------------------------------------------- -+ (Class)URLHandleClassForURL: (NSURL*)_url ++ (void) registerURLHandleClass: (Class)_urlHandleSubclass { - //FIXME - [self notImplemented: _cmd]; + if ([registry indexOfObjectIdenticalTo: _urlHandleSubclass] != NSNotFound) + { + [registry addObject: _urlHandleSubclass]; + } +} + ++ (Class) URLHandleClassForURL: (NSURL*)_url +{ + unsigned count = [registry count]; + + while (count-- > 0) + { + id found = [registry objectAtIndex: count]; + + if ([found canInitWithURL: _url] == YES) + { + return (Class)found; + } + } return 0; } -//----------------------------------------------------------------------------- - (id) initWithURL: (NSURL*)_url - cached: (BOOL)_cached + cached: (BOOL)_cached { - //FIXME - [self notImplemented: _cmd]; - return nil; + Class concreteSubclass = [NSURLHandle URLHandleClassForURL: _url]; + NSURLHandle *instance; + + if (concreteSubclass == 0) + { + NSLog(@"Attempt to init NSURLHandle with unsupported URL schema"); + RELEASE(self); + } + RELEASE(self); + instance = [concreteSubclass alloc]; + return [instance initWithURL: _url cached: _cached]; } //-----------------------------------------------------------------------------