2 Copyright (C) 2003-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 "NGRuleAssignment.h"
24 #include "NGRuleParser.h"
26 #include <EOControl/EOQualifier.h>
28 @implementation NGRule
30 + (id)ruleWithQualifier:(EOQualifier *)_q action:(id)_action priority:(int)_p {
31 return [[[self alloc] initWithQualifier:_q action:_action priority:_p]
34 + (id)ruleWithQualifier:(EOQualifier *)_q action:(id)_action {
35 return [self ruleWithQualifier:_q action:_action priority:0];
38 - (id)initWithString:(NSString *)_s {
40 return [[[NGRuleParser sharedRuleParser] parseRuleFromString:_s] retain];
42 - (id)initWithPropertyList:(id)_plist {
44 return [[[NGRuleParser sharedRuleParser]
45 parseRuleFromPropertyList:_plist] retain];
48 - (id)initWithQualifier:(EOQualifier *)_q action:(id)_action priority:(int)_p {
49 if ((self = [super init])) {
50 self->qualifier = [_q retain];
51 self->action = [_action retain];
57 return [self initWithQualifier:nil action:nil priority:0];
61 [self->qualifier release];
62 [self->action release];
68 - (void)setQualifier:(EOQualifier *)_q {
69 ASSIGN(self->qualifier, _q);
71 - (EOQualifier *)qualifier {
72 return self->qualifier;
75 - (void)setAction:(id)_action {
76 ASSIGN(self->action, _action);
82 - (void)setPriority:(int)_pri {
83 self->priority = _pri;
86 return self->priority;
91 - (BOOL)isCandidateForKey:(NSString *)_key {
93 if (_key == nil) return YES;
96 if ([o respondsToSelector:@selector(isCandidateForKey:)])
97 return [o isCandidateForKey:_key];
99 return NO; /* action is not an assignment ! */
102 - (id)fireInContext:(id)_ctx {
103 return [self->action fireInContext:_ctx];
106 /* representations */
108 - (NSString *)stringValue {
111 sq = [[self qualifier] description];
112 sa = [[self action] description];
113 return [NSString stringWithFormat:@"%@ => %@ ; %i",
114 sq, sa, [self priority]];
117 - (NSString *)description {
118 return [self stringValue];
121 @end /* NGRule(Parsing) */