diff --git a/ChangeLog b/ChangeLog index fbdf74e..9ab76a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2014-05-22 Manuel Guesdon + * 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 * GSWeb/GSWUtils.m fix rangeOfData:range: diff --git a/GSWeb/GSWAssociation.h b/GSWeb/GSWAssociation.h index 75bd46a..560eba9 100644 --- a/GSWeb/GSWAssociation.h +++ b/GSWeb/GSWAssociation.h @@ -115,8 +115,11 @@ NEW FEATURE: negate. add a "!" in front of your key path and the result will be inComponent:(GSWComponent*)component; -(void)logSynchronizeParentToComponentForValue:(id)value 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; -(void)setDebugEnabledForBinding:(NSString*)bindingName diff --git a/GSWeb/GSWAssociation.m b/GSWeb/GSWAssociation.m index de67e78..47bbecd 100644 --- a/GSWeb/GSWAssociation.m +++ b/GSWeb/GSWAssociation.m @@ -118,17 +118,6 @@ static Class NSStringClass = Nil; } //-------------------------------------------------------------------- -// init --(id)init -{ - if ((self=[super init])) - { - } - _negate = NO; - - return self; -} - -(void)dealloc { DESTROY(_bindingName); @@ -137,18 +126,20 @@ static Class NSStringClass = Nil; [super dealloc]; } - +//-------------------------------------------------------------------- // YES if we negate the result before returnig it. -(BOOL)negate { return _negate; } +//-------------------------------------------------------------------- -(void) setNegate:(BOOL) yn { _negate = yn; } +//-------------------------------------------------------------------- - (BOOL)_hasBindingInParent:(GSWComponent*) parent { return YES; @@ -206,11 +197,13 @@ static Class NSStringClass = Nil; return NO; } +//-------------------------------------------------------------------- - (BOOL) isValueSettableInComponent:(GSWComponent*) comp { return [self isValueSettable]; } +//-------------------------------------------------------------------- - (BOOL) isValueConstantInComponent:(GSWComponent*) comp { return [self isValueConstant]; @@ -219,7 +212,6 @@ static Class NSStringClass = Nil; //-------------------------------------------------------------------- // setValue:inComponent: - -(void)setValue:(id)value inComponent:(GSWComponent*)component { @@ -233,59 +225,66 @@ static Class NSStringClass = Nil; //-------------------------------------------------------------------- // valueInComponent: - -(id)valueInComponent:(GSWComponent*)component; { return [self subclassResponsibility:_cmd]; } +//-------------------------------------------------------------------- // added in WO5? // they call it booleanValueInComponent: - (BOOL) boolValueInComponent:(GSWComponent*)component { id value = [self valueInComponent: component]; - int length = 0; - NSString * tmpStr = nil; - if (! value) { - if (_negate) { - return YES; - } + if (value==nil) + { + 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; - } - 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; - } + else return YES; - } - if (_negate) { - return NO; - } - - return YES; } @@ -473,31 +472,7 @@ static Class NSStringClass = Nil; 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. // override in subclasses - (NSString*) bindingInComponent:(GSWComponent*) component @@ -512,11 +487,9 @@ static Class NSStringClass = Nil; return YES; } - //-------------------------------------------------------------------- -(NSString*)keyPath { - //OK [self subclassResponsibility:_cmd]; 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 { @@ -635,9 +630,7 @@ static Class NSStringClass = Nil; //-------------------------------------------------------------------- -(NSString*)debugDescription { - //OK - [self subclassResponsibility:_cmd]; - return nil; + return NSStringFromClass([self class]); } //-------------------------------------------------------------------- @@ -659,34 +652,32 @@ static Class NSStringClass = Nil; static id EONullNull=nil; //TODO MultiThread Protection ? if (!EONullNull) - { EONullNull=[NSNull null]; - } id retValue=nil; 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; } @@ -697,56 +688,64 @@ static Class NSStringClass = Nil; inComponent:(GSWComponent*)object forKeyPath:(NSString*)keyPath { - id tmpObject = nil; NSString *tmpKey = nil; - 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]] + if (keyPath) { - NSError * outError = nil; - - BOOL ok = [tmpObject validateValue:&value forKey:tmpKey error:&outError]; - if (ok == NO) - { - NSException * exception=nil; - NSDictionary * uInfo; - NSString * errorStr = @"unknown reason"; - - uInfo = [NSDictionary dictionaryWithObjectsAndKeys: - (value ? value : (id)@"nil"), @"EOValidatedObjectUserInfoKey", - keyPath, @"EOValidatedPropertyUserInfoKey", - 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]; - } + 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; + + BOOL ok = [tmpObject validateValue:&value + forKey:tmpKey + error:&outError]; + if (ok == NO) + { + NSException * exception=nil; + NSDictionary * uInfo; + NSString * errorStr = @"unknown reason"; + + uInfo = [NSDictionary dictionaryWithObjectsAndKeys: + (value ? value : (id)@"nil"), @"EOValidatedObjectUserInfoKey", + keyPath, @"EOValidatedPropertyUserInfoKey", + 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]; + } + } } - } } diff --git a/GSWeb/GSWConstantValueAssociation.h b/GSWeb/GSWConstantValueAssociation.h index 18ed8ea..772dea0 100644 --- a/GSWeb/GSWConstantValueAssociation.h +++ b/GSWeb/GSWConstantValueAssociation.h @@ -39,12 +39,5 @@ }; -(id)initWithValue:(id)aValue; --(NSString*)debugDescription; --(BOOL)isValueConstant; --(BOOL)isValueSettable; --(id)valueInComponent:(GSWComponent*)component; --(void)setValue:(id)aValue - inComponent:(GSWComponent*)component; - @end #endif //GSWConstantValueAssociation diff --git a/GSWeb/GSWConstantValueAssociation.m b/GSWeb/GSWConstantValueAssociation.m index 9556a9d..10f266a 100644 --- a/GSWeb/GSWConstantValueAssociation.m +++ b/GSWeb/GSWConstantValueAssociation.m @@ -65,12 +65,7 @@ RCS_ID("$Id$") //-------------------------------------------------------------------- -(NSString*)debugDescription { - NSString* dscr=[NSString stringWithFormat:@"<%s %p - value=%@ (class: %@)>", - object_getClassName(self), - (void*)self, - _value, - [_value class]]; - return dscr; + return NSStringFromClass([_value class]); }; //-------------------------------------------------------------------- @@ -88,7 +83,11 @@ RCS_ID("$Id$") //-------------------------------------------------------------------- -(id)valueInComponent:(GSWComponent*)object { - [self logTakeValue:_value]; + if (_debugEnabled) + { + [self _logPullValue:_value + inComponent:object]; + } return _value; }; diff --git a/GSWeb/GSWKeyValueAssociation.h b/GSWeb/GSWKeyValueAssociation.h index c8cfbcf..73b9814 100644 --- a/GSWeb/GSWKeyValueAssociation.h +++ b/GSWeb/GSWKeyValueAssociation.h @@ -40,15 +40,7 @@ } -(id)initWithKeyPath:(NSString*)aKeyPath; - --(id)valueInComponent:(GSWComponent*)component; --(void)setValue:(id)aValue - inComponent:(GSWComponent*)component; --(BOOL)isValueConstant; --(BOOL)isValueSettable; - -(NSString*)keyPath; --(NSString*)debugDescription; @end #endif //_GSWKeyValueAssociation_h__ diff --git a/GSWeb/GSWKeyValueAssociation.m b/GSWeb/GSWKeyValueAssociation.m index c4c4f6b..466460e 100644 --- a/GSWeb/GSWKeyValueAssociation.m +++ b/GSWeb/GSWKeyValueAssociation.m @@ -75,7 +75,11 @@ RCS_ID("$Id$") // but we need: retValue=[GSWAssociation valueInComponent: component forKeyPath:_keyPath]; - + if (_debugEnabled) + { + [self _logPullValue:retValue + inComponent:component]; + } return retValue; }; @@ -86,31 +90,44 @@ RCS_ID("$Id$") NSException *ex = nil; if ([_keyPath length]==0) - { - [NSException raise:NSInvalidArgumentException - format:@"No key path when setting value %@ in object of class %@ for association %@", - aValue,NSStringFromClass([component class]),self]; - } + { + [NSException raise:NSInvalidArgumentException + format:@"No key path when setting value %@ in object of class %@ for association %@", + aValue,NSStringFromClass([component class]),self]; + } - NS_DURING { - [component validateTakeValue:aValue - forKeyPath:_keyPath]; - } NS_HANDLER { - ex = localException; - } NS_ENDHANDLER; + NS_DURING + { + [component validateTakeValue:aValue + forKeyPath:_keyPath]; + } + NS_HANDLER + { + ex = localException; + } + NS_ENDHANDLER; - if (ex != nil) { - [component validationFailedWithException:ex - value:aValue - keyPath:_keyPath]; - } + if (_debugEnabled) + { + [self _logPushValue:aValue + 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) { - [component setValue:aValue forKeyPath:_keyPath]; - } + if (_isValueSettable) + { + [component setValue:aValue + forKeyPath:_keyPath]; + } } //-------------------------------------------------------------------- @@ -128,30 +145,18 @@ RCS_ID("$Id$") //-------------------------------------------------------------------- -(NSString*)description { - NSString* dscr=nil; - - dscr=[NSString stringWithFormat:@"<%s %p -", - object_getClassName(self), - (void*)self]; - dscr=[dscr stringByAppendingFormat:@" keyPath=%@>", - _keyPath]; - return dscr; + return [NSString stringWithFormat:@"<%s %p - keyPath=%@>", + object_getClassName(self), + (void*)self, + _keyPath]; }; - //-------------------------------------------------------------------- -(NSString*)keyPath { return _keyPath; }; -//-------------------------------------------------------------------- --(NSString*)debugDescription -{ - [self notImplemented: _cmd]; //TODOFN - return nil; -}; - @end