* GSWeb/GSWAssociation.h

replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
* GSWeb/GSWAssociation.m
  replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
  respect GNUstep coding standard (curly brackets placement, etc.)
  implement -debugDescription
* GSWeb/GSWConstantValueAssociation.m
  replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
  fix -debugDescription
* GSWeb/GSWKeyValueAssociation.m
  replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
  simplify -description
* GSWeb/GSWKeyValueAssociation.h
  remove unneedded declarations
* GSWeb/GSWConstantValueAssociation.m
  remove unneedded declarations



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@37903 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Manuel Guesdon 2014-05-22 16:49:59 +00:00
parent 97e527ebed
commit 37ad587ea1
7 changed files with 222 additions and 210 deletions

View file

@ -1,3 +1,24 @@
2014-05-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb/GSWAssociation.h
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
* GSWeb/GSWAssociation.m
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
respect GNUstep coding standard (curly brackets placement, etc.)
implement -debugDescription
* GSWeb/GSWConstantValueAssociation.m
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
fix -debugDescription
* GSWeb/GSWKeyValueAssociation.m
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
simplify -description
* GSWeb/GSWKeyValueAssociation.h
remove unneedded declarations
* GSWeb/GSWConstantValueAssociation.m
remove unneedded declarations
2014-05-22 Manuel Guesdon <mguesdon@orange-concept.com> 2014-05-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb/GSWUtils.m * GSWeb/GSWUtils.m
fix rangeOfData:range: fix rangeOfData:range:

View file

@ -115,8 +115,11 @@ NEW FEATURE: negate. add a "!" in front of your key path and the result will be
inComponent:(GSWComponent*)component; inComponent:(GSWComponent*)component;
-(void)logSynchronizeParentToComponentForValue:(id)value -(void)logSynchronizeParentToComponentForValue:(id)value
inComponent:(GSWComponent*)component; inComponent:(GSWComponent*)component;
-(void)logTakeValue:(id)value;
-(void)logSetValue:(id)value; -(void)_logPullValue:(id)value
inComponent:(GSWComponent*) component;
-(void)_logPushValue:(id)value
inComponent:(GSWComponent*) component;
-(NSString*)debugDescription; -(NSString*)debugDescription;
-(void)setDebugEnabledForBinding:(NSString*)bindingName -(void)setDebugEnabledForBinding:(NSString*)bindingName

View file

@ -118,17 +118,6 @@ static Class NSStringClass = Nil;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// init
-(id)init
{
if ((self=[super init]))
{
}
_negate = NO;
return self;
}
-(void)dealloc -(void)dealloc
{ {
DESTROY(_bindingName); DESTROY(_bindingName);
@ -137,18 +126,20 @@ static Class NSStringClass = Nil;
[super dealloc]; [super dealloc];
} }
//--------------------------------------------------------------------
// YES if we negate the result before returnig it. // YES if we negate the result before returnig it.
-(BOOL)negate -(BOOL)negate
{ {
return _negate; return _negate;
} }
//--------------------------------------------------------------------
-(void) setNegate:(BOOL) yn -(void) setNegate:(BOOL) yn
{ {
_negate = yn; _negate = yn;
} }
//--------------------------------------------------------------------
- (BOOL)_hasBindingInParent:(GSWComponent*) parent - (BOOL)_hasBindingInParent:(GSWComponent*) parent
{ {
return YES; return YES;
@ -206,11 +197,13 @@ static Class NSStringClass = Nil;
return NO; return NO;
} }
//--------------------------------------------------------------------
- (BOOL) isValueSettableInComponent:(GSWComponent*) comp - (BOOL) isValueSettableInComponent:(GSWComponent*) comp
{ {
return [self isValueSettable]; return [self isValueSettable];
} }
//--------------------------------------------------------------------
- (BOOL) isValueConstantInComponent:(GSWComponent*) comp - (BOOL) isValueConstantInComponent:(GSWComponent*) comp
{ {
return [self isValueConstant]; return [self isValueConstant];
@ -219,7 +212,6 @@ static Class NSStringClass = Nil;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// setValue:inComponent: // setValue:inComponent:
-(void)setValue:(id)value -(void)setValue:(id)value
inComponent:(GSWComponent*)component inComponent:(GSWComponent*)component
{ {
@ -233,59 +225,66 @@ static Class NSStringClass = Nil;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// valueInComponent: // valueInComponent:
-(id)valueInComponent:(GSWComponent*)component; -(id)valueInComponent:(GSWComponent*)component;
{ {
return [self subclassResponsibility:_cmd]; return [self subclassResponsibility:_cmd];
} }
//--------------------------------------------------------------------
// added in WO5? // added in WO5?
// they call it booleanValueInComponent: // they call it booleanValueInComponent:
- (BOOL) boolValueInComponent:(GSWComponent*)component - (BOOL) boolValueInComponent:(GSWComponent*)component
{ {
id value = [self valueInComponent: component]; id value = [self valueInComponent: component];
int length = 0;
NSString * tmpStr = nil;
if (! value) { if (value==nil)
if (_negate) { {
return YES; if (_negate)
} return YES;
else
return NO;
}
if ([value isKindOfClass: NSNumberClass])
{
if (_negate)
return (![value boolValue]);
else
return [value boolValue];
}
else if ([value isKindOfClass: NSStringClass])
{
NSString* tmpStr = nil;
int length = [value length];
if (length >= 2 && length <= 5)
{
tmpStr = [value lowercaseString];
if ([tmpStr isEqual:@"no"]
|| [tmpStr isEqual:@"false"]
|| [tmpStr isEqual:@"nil"]
|| [tmpStr isEqual:@"null"])
{
if (_negate)
return YES;
else
return NO;
}
}
if ([tmpStr isEqual:@"0"])
{
if (_negate)
return YES;
else
return NO;
}
if (_negate)
return NO;
else
return YES;
}
if (_negate)
return NO; return NO;
} else
if ([value isKindOfClass: NSNumberClass]) {
if (_negate) {
return (! [value boolValue]);
}
return [value boolValue];
}
if ([value isKindOfClass: NSStringClass]) {
length = [value length];
if ((length >= 2) && (length <= 5)) {
tmpStr = [value lowercaseString];
if ([tmpStr isEqual:@"no"] || [tmpStr isEqual:@"false"] || [tmpStr isEqual:@"nil"] || [tmpStr isEqual:@"null"]) {
if (_negate) {
return YES;
}
return NO;
}
}
if ([tmpStr isEqual:@"0"]) {
if (_negate) {
return YES;
}
return NO;
}
if (_negate) {
return NO;
}
return YES; return YES;
}
if (_negate) {
return NO;
}
return YES;
} }
@ -473,31 +472,7 @@ static Class NSStringClass = Nil;
LoggedUnlock(associationsLock); LoggedUnlock(associationsLock);
} }
/*
//====================================================================
@implementation GSWAssociation (GSWAssociationOldFn)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// value
-(id)value
{
GSWContext* context=[[GSWApplication application] context];
[self valueInComponent:GSWContext_component(context)];
}
//--------------------------------------------------------------------
// setValue:inComponent:
//OldFn
-(void)setValue:(id)value
{
GSWContext* context=[[GSWApplication application] context];
[self setValue:(id)value
inComponent:GSWContext_component(context)];
}
@end
*/
//====================================================================
// returns the binding String as in the wod. // returns the binding String as in the wod.
// override in subclasses // override in subclasses
- (NSString*) bindingInComponent:(GSWComponent*) component - (NSString*) bindingInComponent:(GSWComponent*) component
@ -512,11 +487,9 @@ static Class NSStringClass = Nil;
return YES; return YES;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)keyPath -(NSString*)keyPath
{ {
//OK
[self subclassResponsibility:_cmd]; [self subclassResponsibility:_cmd];
return nil; return nil;
} }
@ -564,6 +537,28 @@ static Class NSStringClass = Nil;
} }
} }
//--------------------------------------------------------------------
-(void)_logPullValue:(id)value
inComponent:(GSWComponent*) component
{
[GSWApp logTakeValueForDeclarationNamed:_declarationName
type:_declarationType
bindingNamed:_bindingName
associationDescription:[self debugDescription]
value:value];
}
//--------------------------------------------------------------------
-(void)_logPushValue:(id)value
inComponent:(GSWComponent*) component
{
[GSWApp logSetValueForDeclarationNamed:_declarationName
type:_declarationType
bindingNamed:_bindingName
associationDescription:[self debugDescription]
value:value];
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(void)logTakeValue:(id)value -(void)logTakeValue:(id)value
{ {
@ -635,9 +630,7 @@ static Class NSStringClass = Nil;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)debugDescription -(NSString*)debugDescription
{ {
//OK return NSStringFromClass([self class]);
[self subclassResponsibility:_cmd];
return nil;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -659,34 +652,32 @@ static Class NSStringClass = Nil;
static id EONullNull=nil; static id EONullNull=nil;
//TODO MultiThread Protection ? //TODO MultiThread Protection ?
if (!EONullNull) if (!EONullNull)
{
EONullNull=[NSNull null]; EONullNull=[NSNull null];
}
id retValue=nil; id retValue=nil;
if (keyPath && object && object!=EONullNull) if (keyPath && object && object!=EONullNull)
{
NS_DURING
{ {
retValue=[object valueForKeyPath:keyPath]; NS_DURING
{
retValue=[object valueForKeyPath:keyPath];
}
NS_HANDLER
{
NSLog(@"Attempt to get %@ -%@ raised an exception (%@)",
[object class],
keyPath,
localException);
localException = [localException exceptionByAddingToUserInfoKey:@"Invalid Ivars/Methods"
format:@"-[%@ %@]",
[object class],
keyPath];
[localException raise];
}
NS_ENDHANDLER;
if (retValue==EONullNull)
retValue=nil;
} }
NS_HANDLER
{
NSLog(@"Attempt to get %@ -%@ raised an exception (%@)",
[object class],
keyPath,
localException);
localException = [localException exceptionByAddingToUserInfoKey:@"Invalid Ivars/Methods"
format:@"-[%@ %@]",
[object class],
keyPath];
[localException raise];
}
NS_ENDHANDLER;
if (retValue==EONullNull)
retValue=nil;
}
return retValue; return retValue;
} }
@ -697,56 +688,64 @@ static Class NSStringClass = Nil;
inComponent:(GSWComponent*)object inComponent:(GSWComponent*)object
forKeyPath:(NSString*)keyPath forKeyPath:(NSString*)keyPath
{ {
id tmpObject = nil; id tmpObject = nil;
NSString *tmpKey = nil; NSString *tmpKey = nil;
if (keyPath) { if (keyPath)
NSRange r = [keyPath rangeOfString: @"."];
if (r.length == 0) {
tmpObject = object;
tmpKey = keyPath;
} else {
NSString *key = [keyPath substringToIndex: r.location];
tmpObject = [object valueForKey: key];
tmpKey = [keyPath substringFromIndex: NSMaxRange(r)];
}
if (tmpObject) //&& [object isKindOfClass:[GSWComponent class]]
{ {
NSError * outError = nil; NSRange r = [keyPath rangeOfString: @"."];
BOOL ok = [tmpObject validateValue:&value forKey:tmpKey error:&outError]; if (r.length == 0)
if (ok == NO) {
{ tmpObject = object;
NSException * exception=nil; tmpKey = keyPath;
NSDictionary * uInfo; }
NSString * errorStr = @"unknown reason"; else
{
uInfo = [NSDictionary dictionaryWithObjectsAndKeys: NSString *key = [keyPath substringToIndex: r.location];
(value ? value : (id)@"nil"), @"EOValidatedObjectUserInfoKey", tmpObject = [object valueForKey: key];
keyPath, @"EOValidatedPropertyUserInfoKey", tmpKey = [keyPath substringFromIndex: NSMaxRange(r)];
nil]; }
if (tmpObject) //&& [object isKindOfClass:[GSWComponent class]]
if ((outError) && ([outError userInfo])) { {
errorStr = [[outError userInfo] valueForKey:NSLocalizedDescriptionKey]; NSError * outError = nil;
}
BOOL ok = [tmpObject validateValue:&value
exception=[NSException exceptionWithName:@"EOValidationException" forKey:tmpKey
reason:errorStr error:&outError];
userInfo:uInfo]; if (ok == NO)
{
[object validationFailedWithException:exception NSException * exception=nil;
value:value NSDictionary * uInfo;
keyPath:keyPath]; NSString * errorStr = @"unknown reason";
} else {
// all fine, set the value uInfo = [NSDictionary dictionaryWithObjectsAndKeys:
(value ? value : (id)@"nil"), @"EOValidatedObjectUserInfoKey",
[tmpObject setValue:value keyPath, @"EOValidatedPropertyUserInfoKey",
forKey:tmpKey]; nil];
}
if (outError
&& [outError userInfo])
{
errorStr = [[outError userInfo] valueForKey:NSLocalizedDescriptionKey];
}
exception=[NSException exceptionWithName:@"EOValidationException"
reason:errorStr
userInfo:uInfo];
[object validationFailedWithException:exception
value:value
keyPath:keyPath];
}
else
{
// all fine, set the value
[tmpObject setValue:value
forKey:tmpKey];
}
}
} }
}
} }

View file

@ -39,12 +39,5 @@
}; };
-(id)initWithValue:(id)aValue; -(id)initWithValue:(id)aValue;
-(NSString*)debugDescription;
-(BOOL)isValueConstant;
-(BOOL)isValueSettable;
-(id)valueInComponent:(GSWComponent*)component;
-(void)setValue:(id)aValue
inComponent:(GSWComponent*)component;
@end @end
#endif //GSWConstantValueAssociation #endif //GSWConstantValueAssociation

View file

@ -65,12 +65,7 @@ RCS_ID("$Id$")
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)debugDescription -(NSString*)debugDescription
{ {
NSString* dscr=[NSString stringWithFormat:@"<%s %p - value=%@ (class: %@)>", return NSStringFromClass([_value class]);
object_getClassName(self),
(void*)self,
_value,
[_value class]];
return dscr;
}; };
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -88,7 +83,11 @@ RCS_ID("$Id$")
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(id)valueInComponent:(GSWComponent*)object -(id)valueInComponent:(GSWComponent*)object
{ {
[self logTakeValue:_value]; if (_debugEnabled)
{
[self _logPullValue:_value
inComponent:object];
}
return _value; return _value;
}; };

View file

@ -40,15 +40,7 @@
} }
-(id)initWithKeyPath:(NSString*)aKeyPath; -(id)initWithKeyPath:(NSString*)aKeyPath;
-(id)valueInComponent:(GSWComponent*)component;
-(void)setValue:(id)aValue
inComponent:(GSWComponent*)component;
-(BOOL)isValueConstant;
-(BOOL)isValueSettable;
-(NSString*)keyPath; -(NSString*)keyPath;
-(NSString*)debugDescription;
@end @end
#endif //_GSWKeyValueAssociation_h__ #endif //_GSWKeyValueAssociation_h__

View file

@ -75,7 +75,11 @@ RCS_ID("$Id$")
// but we need: // but we need:
retValue=[GSWAssociation valueInComponent: component retValue=[GSWAssociation valueInComponent: component
forKeyPath:_keyPath]; forKeyPath:_keyPath];
if (_debugEnabled)
{
[self _logPullValue:retValue
inComponent:component];
}
return retValue; return retValue;
}; };
@ -86,31 +90,44 @@ RCS_ID("$Id$")
NSException *ex = nil; NSException *ex = nil;
if ([_keyPath length]==0) if ([_keyPath length]==0)
{ {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"No key path when setting value %@ in object of class %@ for association %@", format:@"No key path when setting value %@ in object of class %@ for association %@",
aValue,NSStringFromClass([component class]),self]; aValue,NSStringFromClass([component class]),self];
} }
NS_DURING { NS_DURING
[component validateTakeValue:aValue {
forKeyPath:_keyPath]; [component validateTakeValue:aValue
} NS_HANDLER { forKeyPath:_keyPath];
ex = localException; }
} NS_ENDHANDLER; NS_HANDLER
{
ex = localException;
}
NS_ENDHANDLER;
if (ex != nil) { if (_debugEnabled)
[component validationFailedWithException:ex {
value:aValue [self _logPushValue:aValue
keyPath:_keyPath]; inComponent:component];
} }
if (ex != nil)
{
[component validationFailedWithException:ex
value:aValue
keyPath:_keyPath];
}
} }
- (void) _setValueNoValidation:(id) aValue inComponent:(GSWComponent*) component - (void) _setValueNoValidation:(id) aValue
inComponent:(GSWComponent*) component
{ {
if (_isValueSettable) { if (_isValueSettable)
[component setValue:aValue forKeyPath:_keyPath]; {
} [component setValue:aValue
forKeyPath:_keyPath];
}
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -128,30 +145,18 @@ RCS_ID("$Id$")
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)description -(NSString*)description
{ {
NSString* dscr=nil; return [NSString stringWithFormat:@"<%s %p - keyPath=%@>",
object_getClassName(self),
dscr=[NSString stringWithFormat:@"<%s %p -", (void*)self,
object_getClassName(self), _keyPath];
(void*)self];
dscr=[dscr stringByAppendingFormat:@" keyPath=%@>",
_keyPath];
return dscr;
}; };
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)keyPath -(NSString*)keyPath
{ {
return _keyPath; return _keyPath;
}; };
//--------------------------------------------------------------------
-(NSString*)debugDescription
{
[self notImplemented: _cmd]; //TODOFN
return nil;
};
@end @end