2 Copyright (C) 2003-2004 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 "NGRuleAssignment.h"
25 @implementation NGRuleAssignment
27 + (id)assignmentWithKeyPath:(NSString *)_kp value:(id)_value {
28 return [[[self alloc] initWithKeyPath:_kp value:_value] autorelease];
30 - (id)initWithKeyPath:(NSString *)_kp value:(id)_value {
31 if ((self = [super init])) {
32 self->keyPath = [_kp copy];
33 self->value = [_value retain];
38 return [self initWithKeyPath:nil value:nil];
42 [self->keyPath release];
43 [self->value release];
49 - (void)setKeyPath:(NSString *)_kp {
50 ASSIGNCOPY(self->keyPath, _kp);
52 - (NSString *)keyPath {
56 - (void)setValue:(id)_value {
57 ASSIGN(self->value, _value);
65 - (BOOL)isCandidateForKey:(NSString *)_key {
66 if (_key == nil) return YES;
68 // TODO: perform a real keypath check
69 return [self->keyPath isEqualToString:_key];
72 - (id)fireInContext:(id)_ctx {
73 // TODO: shouldn't we apply the value on ctx ?
77 /* key/value archiving */
79 - (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver {
80 return [self initWithKeyPath:[_unarchiver decodeObjectForKey:@"keyPath"]
81 value:[_unarchiver decodeObjectForKey:@"value"]];
83 - (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)_archiver {
84 [_archiver encodeObject:[self keyPath] forKey:@"keyPath"];
85 [_archiver encodeObject:[self value] forKey:@"value"];
90 - (NSString *)valueStringValue {
91 return [self->value isKindOfClass:[NSNumber class]]
92 ? [self->value stringValue]
93 : [NSString stringWithFormat:@"\"%@\"", self->value];
96 - (NSString *)stringValue {
97 return [NSString stringWithFormat:@"%@ = %@",
99 [self valueStringValue]];
102 - (NSString *)description {
103 return [self stringValue];
106 @end /* NGRuleAssignment */
108 @implementation NGRuleKeyAssignment
112 - (id)fireInContext:(id)_ctx {
113 // TODO: shouldn't we apply the value on ctx ?
114 return [_ctx valueForKeyPath:[[self value] stringValue]];
119 - (NSString *)valueStringValue {
120 return [self->value stringValue];
123 @end /* NGRuleKeyAssignment */