01: package org.osbl.agent.logic;
02:
03: import org.osbl.agent.model.Rule;
04: import org.osbl.agent.model.RuleContext;
05:
06: /**
07: * RuntimeContext subclasses are used at Rule run-time to provide specific context-dependent
08: * functionality in this area. An instance of this class is responsible for two things:
09: * <ul>
10: * <li>Populating a RuleContext with all the relevant information needed for Rule run-time.</li>
11: * <li>Deciding if a given Rule is compatible with an target object candidate.</li>
12: * </ul>
13: * This latter aspect is useful in case a Rule wants to be applied to a list of objects whose type is not
14: * known in advance. It would guarantee that the Rule is only run on objects for which it makes sense.
15: * In some cases, the target object passed to populate the RuleContext might be a proxy object. The
16: * context-specific implementation should then retrieve the real target object corresponding to the proxy,
17: * and populate the RuleContext with this new object instead.
18: *
19: * @author Sebastian Nozzi.
20: */
21: public abstract class RuntimeContext {
22:
23: /**
24: * Tests the applicability of a given Rule can be tested on a target (or proxy) object.
25: *
26: * @param rule the Rule
27: * @param targetOrProxy the target (or proxy) object the Rule will potentially be run on.
28: *
29: * @return true, if successful
30: */
31: public abstract boolean ruleIsApplicable(Rule rule,
32: Object targetOrProxy);
33:
34: /**
35: * Populates ruleContext with at least the target object.
36: *
37: * In case the targetOrProxy object is not the final target, this method is expected
38: * to retrieve it.
39: *
40: * Any other information that is populated into the ruleContext is context-dependent.
41: *
42: * @param ruleContext the RuleContext to be populated.
43: * @param targetOrProxy the target (or proxy) object.
44: */
45: public abstract void populateRuleContext(RuleContext ruleContext,
46: Object targetOrProxy);
47:
48: }
|