2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <NGObjWeb/WODynamicElement.h>
24 @interface WEComponentValue : WODynamicElement
27 WOAssociation *boolValue;
28 WOAssociation *stringValue;
29 WOAssociation *intValue;
30 WOAssociation *unsignedIntValue;
37 @implementation WEComponentValue
39 - (id)initWithName:(NSString *)_name
40 associations:(NSDictionary *)_config
41 template:(WOElement *)_tmp
43 if ((self = [super initWithName:_name associations:_config template:_tmp])) {
46 self->value = WOExtGetProperty(_config, @"value");
47 self->boolValue = WOExtGetProperty(_config, @"boolValue");
48 self->stringValue = WOExtGetProperty(_config, @"stringValue");
49 self->intValue = WOExtGetProperty(_config, @"intValue");
50 self->unsignedIntValue = WOExtGetProperty(_config, @"unsignedIntValue");
51 self->key = WOExtGetProperty(_config, @"key");
53 if (self->value) cnt++;
54 if (self->boolValue) cnt++;
55 if (self->stringValue) cnt++;
56 if (self->intValue) cnt++;
57 if (self->unsignedIntValue) cnt++;
60 NSLog(@"Warning: WEComponentValue neither 'value', 'boolValue',"
61 @" 'stringValue', 'intValue' nor 'unsignedIntValue' is set");
63 NSLog(@"Warning: WEComponentValue more than one '*Value' is set");
68 #if !LIB_FOUNDATION_BOEHM_GC
71 RELEASE(self->boolValue);
72 RELEASE(self->stringValue);
73 RELEASE(self->intValue);
74 RELEASE(self->unsignedIntValue);
80 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
86 comp = [_ctx component];
87 k = [self->key stringValueInComponent:comp];
91 sel = NSSelectorFromString([k stringByAppendingString:@":"]);
92 sel = ([comp respondsToSelector:sel]) ? sel : NULL;
94 #define _assign(_v_, _k_) \
97 [comp performSelector:sel withObject:_v_]; \
99 [comp takeValue:_v_ forKey:_k_]; \
102 if ((v = [self->value valueInComponent:comp])) {
105 else if (self->boolValue) {
106 v = [NSNumber numberWithBool:[self->boolValue boolValueInComponent:comp]];
109 else if ((v = [self->stringValue stringValueInComponent:comp])) {
112 else if (self->intValue) {
113 v = [NSNumber numberWithInt:[self->intValue intValueInComponent:comp]];
116 else if (self->unsignedIntValue) {
117 v = [NSNumber numberWithUnsignedInt:
118 [self->unsignedIntValue unsignedIntValueInComponent:comp]];
125 @end /* WEComponentValue */