/*
- Copyright (C) 2000-2003 SKYRIX Software AG
+ Copyright (C) 2003-2004 SKYRIX Software AG
- This file is part of OGo
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#include "NGRuleContext.h"
#include "NGRule.h"
/* processing */
- (id)inferredValueForKey:(NSString *)_key {
- NSArray *rules;
+ NSArray *rules;
unsigned i, count;
if (self->debugOn)
return nil;
}
+- (NSArray *)allPossibleValuesForKey:(NSString *)_key {
+ NSMutableArray *values;
+ NSArray *rules;
+ unsigned i, count;
+
+ if (self->debugOn)
+ [self debugWithFormat:@"calculate all values for key: '%@'", _key];
+
+ /* select candidates */
+ rules = [[self model] candidateRulesForKey:_key];
+ if (self->debugOn)
+ [self debugWithFormat:@" candidate rules: %@", rules];
+
+ values = [NSMutableArray arrayWithCapacity:16];
+
+ /* check qualifiers */
+ for (i = 0, count = [rules count]; i < count; i++) {
+ NGRule *rule;
+
+ rule = [rules objectAtIndex:i];
+ if ([(id<EOQualifierEvaluation>)[rule qualifier] evaluateWithObject:self]){
+ id v;
+
+ if (self->debugOn)
+ [self debugWithFormat:@" rule %i matches: %@", i, rule];
+
+ v = [[rule action] fireInContext:self];
+ [values addObject:(v ? v : [NSNull null])];
+ }
+ }
+ if (self->debugOn)
+ [self debugWithFormat:@" %d rules matched.", [values count]];
+ return values;
+}
+
- (id)valueForKey:(NSString *)_key {
id v;
+
+ // TODO: add rule cache?
/* look for constants */
- if ((v = [self->storedValues objectForKey:_key]))
+ if ((v = [self->storedValues objectForKey:_key]) != nil)
return v;
/* look into rule system */
- if ((v = [self inferredValueForKey:_key]))
+ if ((v = [self inferredValueForKey:_key]) != nil)
return v;
return nil;