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:
Manuel Guesdon 2004-04-06 11:11:43 +00:00
parent 94eccc5e54
commit 864cbfbab0

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