+2005-08-04 Helge Hess <helge.hess@opengroupware.org>
+
+ * 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 <helge.hess@opengroupware.org>
* EOQualifier.h: fixed prototypes of -isLike/-isCaseInsensitiveLike:
NSMutableSet *awakeObjects;
id parent;
- id delegate; // non-retained
+ id delegate; // non-retained (eg a WOComponent)
}
- (id)initWithDictionary:(NSDictionary *)_dict;
/* 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;
@interface NSObject(EOKeyValueArchivingAwakeMethods)
-- (void)finishInitializationWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_una;
+- (void)finishInitializationWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_un;
- (void)awakeFromKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver;
@end
[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 {
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 {