站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss RULES 3.0.6 API 英文版文档

Rule - JBoss RULES 3.0.6 API 英文版文档


org.drools.rule
Class Rule

java.lang.Object
  extended by org.drools.rule.Rule
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Query

public class Rule
extends java.lang.Object
implements java.io.Serializable

A Rule contains a set of Tests and a Consequence.

The Tests describe the circumstances that representrepresent a match for this rule. The Consequence gets fired when the Conditions match.

See Also:
Eval, Consequence, Serialized Form

Constructor Summary
Rule(java.lang.String name)
           
Rule(java.lang.String name, java.lang.String agendaGroup)
          Construct a Rule with the given name for the specified pkg parent
Rule(java.lang.String name, java.lang.String pkg, java.lang.String agendaGroup)
          Construct a Rule with the given name for the specified pkg parent
 
Method Summary
 void addPattern(Column column)
           
 void addPattern(ConditionalElement ce)
          Add a pattern to the rule.
 boolean equals(java.lang.Object object)
           
 java.lang.String getActivationGroup()
           
 java.lang.String getAgendaGroup()
           
 boolean getAutoFocus()
           
 Consequence getConsequence()
          Retrieve the Consequence associated with this Rule.
 Declaration getDeclaration(java.lang.String identifier)
          Retrieve a parameter Declaration by identifier.
 Declaration[] getDeclarations()
          Retrieve the set of all root fact object parameter Declarations.
 Duration getDuration()
          Retrieve the truthness duration object.
 And getLhs()
          Retrieve the List of Conditions for this rule.
 long getLoadOrder()
           
 java.lang.String getName()
          Retrieve the name of this rule.
 boolean getNoLoop()
           
 java.lang.String getPackage()
           
 int getSalience()
          Retrieve the Rule salience.
 int getSpecifity()
           
 And[] getTransformedLhs()
          Uses the LogicTransformer to process the Rule patters - if no ORs are used this will return an array of a single AND element.
 int hashCode()
           
 boolean isSemanticallyValid()
          This will return if the semantic actions or predicates in the rules are valid.
 boolean isValid()
          Determine if this rule is internally consistent and valid.
 void setAgendaGroup(java.lang.String agendaGroup)
           
 void setAutoFocus(boolean autoFocus)
           
 void setConsequence(Consequence consequence)
          Set the Consequence that is associated with the successful match of this rule.
 void setDuration(Duration duration)
          Set the truthness duration object.
 void setDuration(long ms)
          Set the truthness duration.
 void setNoLoop(boolean noLoop)
           
 void setSalience(int salience)
          Set the Rule salience.
 void setSemanticallyValid(boolean valid)
           
 void setXorGroup(java.lang.String activationGroup)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rule

public Rule(java.lang.String name,
            java.lang.String pkg,
            java.lang.String agendaGroup)
Construct a Rule with the given name for the specified pkg parent

Parameters:
name - The name of this rule.

Rule

public Rule(java.lang.String name,
            java.lang.String agendaGroup)
Construct a Rule with the given name for the specified pkg parent

Parameters:
name - The name of this rule.

Rule

public Rule(java.lang.String name)
Method Detail

setDuration

public void setDuration(long ms)
Set the truthness duration. This causes a delay before the firing of the Consequence if the rule is still true at the end of the duration.

This is merely a convenience method for calling setDuration(Duration)with a FixedDuration.

Parameters:
seconds - - The number of seconds the rule must hold true in order to fire.
See Also:
setDuration(Duration), FixedDuration

setDuration

public void setDuration(Duration duration)
Set the truthness duration object. This causes a delay before the firing of the Consequence if the rule is still true at the end of the duration.

Parameters:
duration - The truth duration object.

getDuration

public Duration getDuration()
Retrieve the truthness duration object.

Returns:
The truthness duration object.

isValid

public boolean isValid()
Determine if this rule is internally consistent and valid. This will include checks to make sure the rules semantic components (actions and predicates) are valid. No exception is thrown.

A Rule must include at least one parameter declaration and one condition.

Returns:
true if this rule is valid, else false.

getPackage

public java.lang.String getPackage()

getName

public java.lang.String getName()
Retrieve the name of this rule.

Returns:
The name of this rule.

getSalience

public int getSalience()
Retrieve the Rule salience.

Returns:
The salience.

setSalience

public void setSalience(int salience)
Set the Rule salience.

Parameters:
salience - The salience.

getAgendaGroup

public java.lang.String getAgendaGroup()

setAgendaGroup

public void setAgendaGroup(java.lang.String agendaGroup)

getNoLoop

public boolean getNoLoop()

setNoLoop

public void setNoLoop(boolean noLoop)

getAutoFocus

public boolean getAutoFocus()

setAutoFocus

public void setAutoFocus(boolean autoFocus)

getActivationGroup

public java.lang.String getActivationGroup()

setXorGroup

public void setXorGroup(java.lang.String activationGroup)

getDeclaration

public Declaration getDeclaration(java.lang.String identifier)
Retrieve a parameter Declaration by identifier.

Parameters:
identifier - The identifier.
Returns:
The declaration or null if no declaration matches the identifier.

getDeclarations

public Declaration[] getDeclarations()
Retrieve the set of all root fact object parameter Declarations.

Returns:
The Set of Declarations in order which specify the root fact objects.

addPattern

public void addPattern(ConditionalElement ce)
Add a pattern to the rule. All patterns are searched for bindings which are then added to the rule as declarations

Parameters:
condition - The Test to add.
Throws:
InvalidRuleException

addPattern

public void addPattern(Column column)

getLhs

public And getLhs()
Retrieve the List of Conditions for this rule.

Returns:
The List of Conditions.

getTransformedLhs

public And[] getTransformedLhs()
                        throws InvalidPatternException
Uses the LogicTransformer to process the Rule patters - if no ORs are used this will return an array of a single AND element. If there are Ors it will return an And element for each possible logic branch. The processing uses as a clone of the Rule's patterns, so they are not changed.

Returns:
Throws:
InvalidPatternException

getSpecifity

public int getSpecifity()

setConsequence

public void setConsequence(Consequence consequence)
Set the Consequence that is associated with the successful match of this rule.

Parameters:
consequence - The Consequence to attach to this Rule.

getConsequence

public Consequence getConsequence()
Retrieve the Consequence associated with this Rule.

Returns:
The Consequence.

getLoadOrder

public long getLoadOrder()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

setSemanticallyValid

public void setSemanticallyValid(boolean valid)

isSemanticallyValid

public boolean isSemanticallyValid()
This will return if the semantic actions or predicates in the rules are valid. This is provided so that lists of rules can be provided even if their semantic actions do not "compile" etc.