org.drools.rule
Class Rule

java.lang.Object
  |
  +--org.drools.rule.Rule

public class Rule
extends java.lang.Object

A set of Conditions and a Consequence. The Conditions describe the circumstances that represent a match for this rule. The Consequence gets fired when the Conditions match.

Version:
$Id: Rule.java,v 1.25 2003/11/21 04:18:13 bob Exp $
Author:
bob mcwhirter
See Also:
Condition, Consequence

Field Summary
static Rule[] EMPTY_ARRAY
          Empty Rule array.
 
Constructor Summary
Rule(java.lang.String name)
          Construct.
 
Method Summary
 void addCondition(Condition condition)
          Add a Condition to this rule.
 void addDeclaration(Declaration declaration)
          Add a declaration.
 void addExtraction(Extraction extraction)
          Add a consistent Extraction to this rule.
 void addParameterDeclaration(Declaration declaration)
          Add a root fact object parameter Declaration for this Rule.
 void checkValidity()
          Check the validity of this rule, and throw exceptions if it fails validity tests.
 Declaration[] getAllDeclarations()
          Retrieve the array of all Declarations of this rule.
 Condition[] getConditions()
          Retrieve the Set of Conditions for this rule.
 Consequence getConsequence()
          Retrieve the Consequence associated with this Rule.
 Declaration getDeclaration(java.lang.String identifier)
          Retrieve a Declaration by identifier.
 java.lang.String getDocumentation()
          Retrieve the documentation.
 Duration getDuration()
          Retrieve the truthness duration object.
 Extraction[] getExtractions()
          Retrieve the Set of Extractions for this rule.
 Declaration[] getLocalDeclarations()
          Retrieve the set of all implied local Declarations.
 java.lang.String getName()
          Retrieve the name of this rule.
 Declaration getParameterDeclaration(java.lang.String identifier)
          Retrieve a parameter Declaration by identifier.
 Declaration[] getParameterDeclarations()
          Retrieve the set of all root fact object parameter Declarations.
 int getSalience()
          Retrieve the Rule salience.
 boolean isValid()
          Determine if this rule is internally consistent and valid.
 void setConsequence(Consequence consequence)
          Set the Consequence that is associated with the successful match of this rule.
 void setDocumentation(java.lang.String documentation)
          Set the documentation.
 void setDuration(Duration duration)
          Set the truthness duration object.
 void setDuration(long seconds)
          Set the truthness duration.
 void setSalience(int salience)
          Set the Rule salience.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final Rule[] EMPTY_ARRAY
Empty Rule array.

Constructor Detail

Rule

public Rule(java.lang.String name)
Construct.

Parameters:
name - The name of this rule.
Method Detail

setDocumentation

public void setDocumentation(java.lang.String documentation)
Set the documentation.

Parameters:
documentation - The documentation.

getDocumentation

public java.lang.String getDocumentation()
Retrieve the documentation.

Returns:
The documentation or null if none.

setDuration

public void setDuration(long seconds)
Set the truthness 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.

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.

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

checkValidity

public void checkValidity()
                   throws InvalidRuleException
Check the validity of this rule, and throw exceptions if it fails validity tests.

Possibly exceptions include:

      NoParameterDeclarationException
  

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

Throws:
InvalidRuleException - if this rule is in any way invalid.

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.

addParameterDeclaration

public void addParameterDeclaration(Declaration declaration)
Add a root fact object parameter Declaration for this Rule.

Parameters:
declaration - The root fact object Declaration to add.

addDeclaration

public void addDeclaration(Declaration declaration)
Add a declaration.

Parameters:
declaration - The declaration.

getParameterDeclaration

public Declaration getParameterDeclaration(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.

getDeclaration

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

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

getParameterDeclarations

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

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

getLocalDeclarations

public Declaration[] getLocalDeclarations()
Retrieve the set of all implied local Declarations.

Returns:
The Set of all implied Declarations which are implied by the conditions.

getAllDeclarations

public Declaration[] getAllDeclarations()
Retrieve the array of all Declarations of this rule.

Returns:
The array of declarations.

addCondition

public void addCondition(Condition condition)
Add a Condition to this rule.

Parameters:
condition - The Condition to add.

addExtraction

public void addExtraction(Extraction extraction)
Add a consistent Extraction to this rule.

Parameters:
extraction - the Extraction to add.

getConditions

public Condition[] getConditions()
Retrieve the Set of Conditions for this rule.

Returns:
The Set of Conditions.

getExtractions

public Extraction[] getExtractions()
Retrieve the Set of Extractions for this rule.

Returns:
The Set of Extractions.

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.