public class Rule extends Object implements Comparable<Rule>
Engine contains a list of rules. The engine
can then be asked to provide the outcome of the Action associated with the best
matching rule (see Engine.executeBestAction(String, Object, java.util.Collection)),
or to provide a list of matching rules (see Engine.getMatchingRules(String, Object)).
Each rule is "evaluated"
by using the expression supplied in the constructor
Rule(String, String, String, int, String).
The expression must be valid expression language. During evaludation,
the input object passed to the engine is mapped to the name "input", which can be
used in the rules. For example, consider the following rule:input.person1.name == "ant" && input.person1.gender == "male"IAction executed, it must evaluate to "true". The rule in the
example above requires an input object which conforms to the bean specification, and
which is composed of an object named "person1", which has attributes"name"
and "gender". If an input object is supplied to the engine such that this rule
evaluates to true, then it is a candidate to have its action run, either by
the engine, when Engine.executeBestAction(String, Object, java.util.Collection) is called,
or by the application, when Engine.getMatchingRules(String, Object)
returns the rule and the application decides to run the action.SubRules and when they are composed in that manner,
rules refer to subrules by their names.SubRule| Constructor and Description |
|---|
Rule(String name,
String expression,
String outcome,
int priority,
String namespace)
See
Rule(String, String, String, int, String, String), just without a description. |
Rule(String name,
String expression,
String outcome,
int priority,
String namespace,
String description) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Rule r) |
boolean |
equals(Object obj) |
String |
getDescription() |
String |
getExpression() |
String |
getFullyQualifiedName() |
String |
getName() |
String |
getNamespace() |
String |
getOutcome() |
int |
getPriority() |
int |
hashCode() |
String |
toString() |
public Rule(String name, String expression, String outcome, int priority, String namespace, String description)
name - The name of the rule. Should be unique within the namespace (tested when adding rules to the Engine).expression - the rule expressed in expression language. all variables must come from the bean called "input". The rule MUST evaluate to "true" if it is to be a candidate for execution.outcome - The name of an action to run, if this rule is the winner.priority - The priority, used in determining which rule to run, if many evaluate true. The higher the value, the higher the priority.namespace - A namespace, used for filtering rules. The engine is passed a regular expression which is compared to this value. Only matches are evaluated.description - A description to help manage rules.public Rule(String name, String expression, String outcome, int priority, String namespace)
Rule(String, String, String, int, String, String), just without a description.public int compareTo(Rule r)
compareTo in interface Comparable<Rule>public String getFullyQualifiedName()
public String getName()
public String getExpression()
public String getOutcome()
public int getPriority()
public String getNamespace()
public String getDescription()
Copyright © 2017 Ant Kutschera. All rights reserved.