2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "WOKeyPathAssociation.h"
24 #include <NGObjWeb/WOComponent.h>
25 #include "NSObject+WO.h"
29 WOKeyPathAssociationSystemKVC
31 This is an WOKeyPathAssociation subclass which uses the KVC methods
32 provided in the Foundation library. This is much less performant, but
33 much more compatible with WebObjects.
35 This could be further optimized by doing method caching, using shared
36 objects, etc. Yet if you need speed, you should use the default association.
39 @interface WOKeyPathAssociationSystemKVC : WOKeyPathAssociation
41 NSString *keyPathString;
47 @implementation WOKeyPathAssociationSystemKVC
49 static NSNumber *yesNum = nil;
50 static NSNumber *noNum = nil;
53 return [super version] + 0; /* v2 */
56 if (yesNum == nil) yesNum = [[NSNumber numberWithBool:YES] retain];
57 if (noNum == nil) noNum = [[NSNumber numberWithBool:NO] retain];
60 - (id)initWithKeyPath:(NSString *)_keyPath {
61 if ((self = [super initWithKeyPath:_keyPath])) {
62 self->hasCaretPrefix =
63 (([_keyPath length] > 1) && [_keyPath hasPrefix:@"^"]) ? YES : NO;
65 if (self->hasCaretPrefix)
66 self->keyPathString = [[_keyPath substringFromIndex:1] copy];
68 self->keyPathString = [_keyPath copy];
74 [self->keyPathString release];
80 - (NSString *)keyPath {
81 return self->keyPathString;
86 - (void)setValue:(id)_value inComponent:(WOComponent *)_component {
87 if (self->hasCaretPrefix)
88 [_component setValue:_value forBinding:self->keyPathString];
90 [_component takeValue:_value forKeyPath:self->keyPathString];
92 - (id)valueInComponent:(WOComponent *)_component {
93 return (self->hasCaretPrefix)
94 ? [_component valueForBinding:self->keyPathString]
95 : [_component valueForKeyPath:self->keyPathString];
98 - (BOOL)isValueConstant {
101 - (BOOL)isValueSettable {
107 - (void)setUnsignedIntValue:(unsigned int)_v inComponent:(WOComponent *)_wo {
108 [self setValue:[NSNumber numberWithUnsignedInt:_v] inComponent:_wo];
110 - (unsigned int)unsignedIntValueInComponent:(WOComponent *)_component {
111 return [[self valueInComponent:_component] unsignedIntValue];
114 - (void)setIntValue:(int)_value inComponent:(WOComponent *)_wo {
115 [self setValue:[NSNumber numberWithInt:_value] inComponent:_wo];
117 - (int)intValueInComponent:(WOComponent *)_component {
118 return [[self valueInComponent:_component] intValue];
121 - (void)setBoolValue:(BOOL)_value inComponent:(WOComponent *)_wo {
122 [self setValue:(_value ? yesNum : noNum) inComponent:_wo];
124 - (BOOL)boolValueInComponent:(WOComponent *)_component {
125 /* some optimizations, very likely that same objects are used for YES|NO */
128 if ((o = [self valueInComponent:_component]) == nil)
130 if (o == yesNum) return YES;
131 if (o == noNum) return NO;
132 return [o boolValue];
135 - (void)setStringValue:(NSString *)_value inComponent:(WOComponent *)_wo {
136 [self setValue:_value inComponent:_wo];
138 - (NSString *)stringValueInComponent:(WOComponent *)_component {
139 return [[self valueInComponent:_component] stringValue];
142 @end /* WOKeyPathAssociationSystemKVC */