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.14 2002/08/22 19:21:58 bob Exp $
Author:
bob mcwhirter
See Also:
Condition, Consequence

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 failed validity tests.
 java.util.Set 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.
 Declaration[] getDeclarationsArray()
          Retrieve the array of all Declarations of this rule.
 long getDuration(Tuple tuple)
          Retrieve the truthness duration.
 java.util.Set getExtractions()
          Retrieve the Set of Extractions for this rule.
 java.util.Set 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.
 java.util.Set getParameterDeclarations()
          Retrieve the set of all root fact object parameter Declarations.
 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 setDuration(Duration duration)
          Set the truthness duration.
 void setDuration(long seconds)
          Set the truthness duration.
 java.lang.String toString()
          Produce a debug string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rule

public Rule(java.lang.String name)
Construct.
Parameters:
name - The name of this rule.
Method Detail

setDuration

public void setDuration(long seconds)
Set the truthness duration.
Parameters:
seconds - The number of seconds the rule must hold true in order to fire.

setDuration

public void setDuration(Duration duration)
Set the truthness duration.
Parameters:
duration - The truth duration.

getDuration

public long getDuration(Tuple tuple)
Retrieve the truthness duration.
Parameters:
tuple - The tuple.
Returns:
The number of seconds the rule must hold true in order to fire.

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 failed 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.

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 java.util.Set getParameterDeclarations()
Retrieve the set of all root fact object parameter Declarations.
Returns:
The Set of Declarations which specify the root fact objects.

getLocalDeclarations

public java.util.Set getLocalDeclarations()
Retrieve the set of all implied local Declarations.
Returns:
The Set of all implied Declarations which are implied by the conditions.

getDeclarationsArray

public Declaration[] getDeclarationsArray()
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 java.util.Set getConditions()
Retrieve the Set of Conditions for this rule.
Returns:
The Set of Conditions.

getExtractions

public java.util.Set 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.

toString

public java.lang.String toString()
Produce a debug string.
Overrides:
toString in class java.lang.Object
Returns:
The debug string.


Copyright © 2001-2002 The Werken Company. All Rights Reserved.