/*
- Copyright (C) 2003-2004 SKYRIX Software AG
+ Copyright (C) 2003-2006 SKYRIX Software AG
+ Copyright (C) 2006 Helge Hess
- This file is part of OpenGroupware.org.
+ 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.
*/
#include "NGRuleModel.h"
#include "NSObject+Logs.h"
#include "common.h"
-#include <EOControl/EOQualifier.h>
+#import <EOControl/EOQualifier.h>
@implementation NGRuleContext
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 != nil ? v : (id)[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;
[self takeValue:[_values objectAtIndex:i] forKeyPath:_valkp];
/* calculate the rule value */
- ruleValue = [self valueForKey:_kp];
- [results addObject:ruleValue ? ruleValue : [NSNull null]];
+ ruleValue = [self valueForKeyPath:_kp];
+ [results addObject:(ruleValue != nil ? ruleValue : (id)[NSNull null])];
}
return results;
}