From: helge Date: Thu, 4 Aug 2005 01:06:08 +0000 (+0000) Subject: map Java-like class names X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=381da14933a28f8732203ced28dac88082a34894;p=sope map Java-like class names compile EOCoreData on OSX git-svn-id: http://svn.opengroupware.org/SOPE/trunk@965 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/EOControl/ChangeLog b/sope-core/EOControl/ChangeLog index 94bb6f7b..dcfcc871 100644 --- a/sope-core/EOControl/ChangeLog +++ b/sope-core/EOControl/ChangeLog @@ -1,3 +1,9 @@ +2005-08-04 Helge Hess + + * EOKeyValueArchiver.m: process class names containing a dot by + first looking up the class using the last dot-component and then + by trying to map some known prefixes (eg D2W) (v4.5.54) + 2005-05-03 Helge Hess * EOQualifier.h: fixed prototypes of -isLike/-isCaseInsensitiveLike: diff --git a/sope-core/EOControl/EOKeyValueArchiver.h b/sope-core/EOControl/EOKeyValueArchiver.h index 4be58465..e451fc9e 100644 --- a/sope-core/EOControl/EOKeyValueArchiver.h +++ b/sope-core/EOControl/EOKeyValueArchiver.h @@ -56,7 +56,7 @@ NSMutableSet *awakeObjects; id parent; - id delegate; // non-retained + id delegate; // non-retained (eg a WOComponent) } - (id)initWithDictionary:(NSDictionary *)_dict; @@ -64,7 +64,7 @@ /* decoding */ - (id)decodeObjectForKey:(NSString *)_key; -- (id)decodeObjectReferenceForKey:(NSString *)_key; +- (id)decodeObjectReferenceForKey:(NSString *)_key; /* ask delegate for obj */ - (BOOL)decodeBoolForKey:(NSString *)_key; - (int)decodeIntForKey:(NSString *)_key; @@ -91,7 +91,7 @@ @interface NSObject(EOKeyValueArchivingAwakeMethods) -- (void)finishInitializationWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_una; +- (void)finishInitializationWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_un; - (void)awakeFromKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver; @end diff --git a/sope-core/EOControl/EOKeyValueArchiver.m b/sope-core/EOControl/EOKeyValueArchiver.m index ec932804..6ef7cb28 100644 --- a/sope-core/EOControl/EOKeyValueArchiver.m +++ b/sope-core/EOControl/EOKeyValueArchiver.m @@ -132,6 +132,54 @@ static BOOL isPListObject(id _obj) { [super dealloc]; } +/* class handling */ + +- (Class)classForName:(NSString *)_name { + /* + This method maps class names. It is intended for archives which are + written by the Java bridge and therefore use fully qualified Java + package names. + + The mapping is hardcoded for now, this could be extended to use a + dictionary if considered necessary. + */ + NSString *lastComponent = nil; + Class clazz; + NSRange r; + + if (_name == nil) + return nil; + + if ((clazz = NSClassFromString(_name)) != Nil) + return clazz; + + /* check for Java like . names (eg com.webobjects.directtoweb.Assignment) */ + + r = [_name rangeOfString:@"." options:NSBackwardsSearch]; + if (r.length > 0) { + lastComponent = [_name substringFromIndex:(r.location + r.length)]; + + /* first check whether the last name directly matches a class */ + if ((clazz = NSClassFromString(lastComponent)) != Nil) + return clazz; + + /* then check some hardcoded prefixes */ + + if ([_name hasPrefix:@"com.webobjects.directtoweb"]) { + NSString *s; + + s = [@"D2W" stringByAppendingString:lastComponent]; + if ((clazz = NSClassFromString(lastComponent)) != Nil) + return clazz; + } + + NSLog(@"WARNING(%s): could not map Java class in unarchiver: '%@'", + __PRETTY_FUNCTION__, _name); + } + + return Nil; +} + /* decoding */ - (id)decodeObjectForKey:(NSString *)_key { @@ -147,10 +195,15 @@ static BOOL isPListObject(id _obj) { obj = [[self->plist copy] autorelease]; } else if ((className = [self->plist objectForKey:@"class"]) != nil) { - obj = [NSClassFromString(className) alloc]; + obj = [[self classForName:className] alloc]; obj = [obj initWithKeyValueUnarchiver:self]; - [self->unarchivedObjects addObject:obj]; + if (obj != nil) + [self->unarchivedObjects addObject:obj]; + else { + NSLog(@"WARNING(%s): could not unarchive object %@", + __PRETTY_FUNCTION__, self->plist); + } [obj release]; } else { diff --git a/sope-core/EOControl/Version b/sope-core/EOControl/Version index d124b50f..5a9103fb 100644 --- a/sope-core/EOControl/Version +++ b/sope-core/EOControl/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=53 +SUBMINOR_VERSION:=54 diff --git a/sope-core/GNUmakefile b/sope-core/GNUmakefile index 085c6f22..1f0416a7 100644 --- a/sope-core/GNUmakefile +++ b/sope-core/GNUmakefile @@ -6,9 +6,14 @@ include $(GNUSTEP_MAKEFILES)/common.make PACKAGE_NAME=sope-core VERSION=4.5.0 -SUBPROJECTS = \ +SUBPROJECTS += \ EOControl \ NGExtensions \ - NGStreams \ + NGStreams + +# compile EOCoreData if we are on Tiger +ifeq ($(findstring darwin8, $(GNUSTEP_TARGET_OS)), darwin8) +SUBPROJECTS += EOCoreData +endif include $(GNUSTEP_MAKEFILES)/aggregate.make