o raise exception if empty keyPath in +setValue:inObject:forKeyPath:

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@19041 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mguesdon 2004-04-06 11:11:43 +00:00
parent 9796174a8c
commit 30120bc203

View file

@ -195,7 +195,6 @@ static NSMutableArray* associationsLogsHandlerClasses=nil;
-(void)setValue:(id)value -(void)setValue:(id)value
inComponent:(GSWComponent*)component inComponent:(GSWComponent*)component
{ {
//OK
[self setValue:value [self setValue:value
inObject:component]; inObject:component];
}; };
@ -875,118 +874,118 @@ static NSMutableArray* associationsLogsHandlerClasses=nil;
NSStringFromClass([object class]), NSStringFromClass([object class]),
NSStringFromClass([object superclass])); NSStringFromClass([object superclass]));
NSDebugMLLog(@"associations",@"GSWAssociation: keyPath:%@",keyPath); NSDebugMLLog(@"associations",@"GSWAssociation: keyPath:%@",keyPath);
if (keyPath) if ([keyPath length]==0)
{ {
#if HAVE_GDL2 [NSException raise:NSInvalidArgumentException
[object smartTakeValue:value format:@"No key path when setting value %@ in object of class %@",
forKeyPath:keyPath]; value,NSStringFromClass(object)];
#else // no GDL2 };
NSMutableArray* keys=[[keyPath componentsSeparatedByString:@"."] mutableCopy];
id part=nil;
id tmpObject=object;
Class handlerClass=Nil;
NSAssert(tmpObject,@"No Object");
while(tmpObject && [keys count]>0)
{
part=[keys objectAtIndex:0];
[keys removeObjectAtIndex:0];
NSDebugMLLog(@"associations",@"part=%@",part);
NSDebugMLLog(@"associations",@"part class=%@",NSStringFromClass([part class]));
if ([part hasPrefix:@"\""])
{
part=[part stringByDeletingPrefix:@"\""];
while([keys count]>0)
{
id tmpPart=[keys objectAtIndex:0];
[keys removeObjectAtIndex:0];
if ([tmpPart hasSuffix:@"\""])
{
tmpPart=[tmpPart stringByDeletingSuffix:@"\""];
part=[part stringByAppendingFormat:@".%@",tmpPart];
break;
}
else
part=[part stringByAppendingFormat:@".%@",tmpPart];
}
}
NSDebugMLLog(@"associations",@"part=%@",part);
handlerClass=[associationsHandlerClasses objectForKey:part]; #if HAVE_GDL2
NSDebugMLLog(@"associations",@"handlerClass=%@",handlerClass); [object smartTakeValue:value
if (handlerClass) forKeyPath:keyPath];
#else // no GDL2
NSMutableArray* keys=[[keyPath componentsSeparatedByString:@"."] mutableCopy];
id part=nil;
id tmpObject=object;
Class handlerClass=Nil;
NSAssert(tmpObject,@"No Object");
while(tmpObject && [keys count]>0)
{
part=[keys objectAtIndex:0];
[keys removeObjectAtIndex:0];
NSDebugMLLog(@"associations",@"part=%@",part);
NSDebugMLLog(@"associations",@"part class=%@",NSStringFromClass([part class]));
if ([part hasPrefix:@"\""])
{
part=[part stringByDeletingPrefix:@"\""];
while([keys count]>0)
{ {
tmpObject=[handlerClass processSetValue:value id tmpPart=[keys objectAtIndex:0];
inObject:tmpObject [keys removeObjectAtIndex:0];
forHandler:part if ([tmpPart hasSuffix:@"\""])
forKeyPath:keys];
}
else
{
if ([keys count]>0)
{ {
if ([part isEqualToString:GSASK_Class]) tmpPart=[tmpPart stringByDeletingSuffix:@"\""];
{ part=[part stringByAppendingFormat:@".%@",tmpPart];
Class class=Nil; break;
NSAssert2([keys count]>0,@"No class name for handler %@ in %@", }
GSASK_Class, else
keyPath); part=[part stringByAppendingFormat:@".%@",tmpPart];
part=[keys objectAtIndex:0]; }
[keys removeObjectAtIndex:0]; }
NSDebugMLLog(@"associations",@"part=%@",part); NSDebugMLLog(@"associations",@"part=%@",part);
class=NSClassFromString(part);
NSAssert3(class>0,@"No class named %@ for handler %@ in %@", handlerClass=[associationsHandlerClasses objectForKey:part];
part, NSDebugMLLog(@"associations",@"handlerClass=%@",handlerClass);
GSASK_Class, if (handlerClass)
keyPath); {
if (class) tmpObject=[handlerClass processSetValue:value
tmpObject=class; inObject:tmpObject
else forHandler:part
tmpObject=nil; forKeyPath:keys];
} }
else
{
if ([keys count]>0)
{
if ([part isEqualToString:GSASK_Class])
{
Class class=Nil;
NSAssert2([keys count]>0,@"No class name for handler %@ in %@",
GSASK_Class,
keyPath);
part=[keys objectAtIndex:0];
[keys removeObjectAtIndex:0];
NSDebugMLLog(@"associations",@"part=%@",part);
class=NSClassFromString(part);
NSAssert3(class>0,@"No class named %@ for handler %@ in %@",
part,
GSASK_Class,
keyPath);
if (class)
tmpObject=class;
else else
{ tmpObject=nil;
tmpObject=[tmpObject valueForKey:part];
}
} }
else else
{ {
GSWLogAssertGood(tmpObject); tmpObject=[tmpObject valueForKey:part];
[tmpObject takeValue:value }
forKey:part]; }
else
{
GSWLogAssertGood(tmpObject);
[tmpObject takeValue:value
forKey:part];
#ifdef HAVE_GDL2 #ifdef HAVE_GDL2
NSDebugMLLog(@"associations",@"object class=%@",[object class]); NSDebugMLLog(@"associations",@"object class=%@",[object class]);
NSDebugMLLog(@"associations",@"tmpObject class=%@",[tmpObject class]); NSDebugMLLog(@"associations",@"tmpObject class=%@",[tmpObject class]);
// Turbocat // Turbocat
if (tmpObject && [tmpObject isKindOfClass:[GSWComponent class]]) if (tmpObject && [tmpObject isKindOfClass:[GSWComponent class]])
{
NSException* exp = [tmpObject validateValue:&value
forKey:part];
if (exp)
{ {
NSException* exp = [tmpObject validateValue:&value NSException* exception=nil;
forKey:part]; exception=[NSException exceptionWithName:@"EOValidationException"
if (exp) reason:[exp reason]
{ userInfo:[NSDictionary
NSException* exception=nil; dictionaryWithObjectsAndKeys:
exception=[NSException exceptionWithName:@"EOValidationException" (value ? value : @"nil"),@"EOValidatedObjectUserInfoKey",
reason:[exp reason] keyPath,@"EOValidatedPropertyUserInfoKey",
userInfo:[NSDictionary nil,nil]];
dictionaryWithObjectsAndKeys: [object validationFailedWithException:exception
(value ? value : @"nil"),@"EOValidatedObjectUserInfoKey", value:value
keyPath,@"EOValidatedPropertyUserInfoKey", keyPath:keyPath];
nil,nil]];
[object validationFailedWithException:exception
value:value
keyPath:keyPath];
}
} }
}
#endif #endif
tmpObject=nil; tmpObject=nil;
};
}; };
}; };
#endif
}
else
{
NSDebugMLLog(@"associations",@"GSWAssociation: setValue:%@ : NoKeyPath",value);
}; };
#endif
LOGClassFnStop(); LOGClassFnStop();
}; };