From 5648d97c5ac2e2a836e66a9b9773fedd44afafe8 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 19 Sep 2000 08:31:40 +0000 Subject: [PATCH] Implemented registry. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7547 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 ++++ Source/NSURLHandle.m | 52 +++++++++++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 13 deletions(-) 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]; } //-----------------------------------------------------------------------------