org.drools.rule
Class Rule

java.lang.Object
  extended byorg.drools.rule.Rule
All Implemented Interfaces:
Serializable

public class Rule
extends Object
implements Serializable

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

Author:
bob mcwhirter , Simon Harris
See Also:
Condition, Consequence, Serialized Form

Constructor Summary
Rule(String name)
          Construct.
Rule(String name, RuleSet ruleSet)
          Construct.
 
Method Summary
 void addCondition(Condition condition)
          Add a Condition to this rule.
 Declaration addParameterDeclaration(String identifier, ObjectType objectType)
          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.
 String dump(String indent)
           
 Map getApplicationData()
           
 List getConditions()
          Retrieve the List of Conditions for this rule.
 int getConditionSize()
           
 Consequence getConsequence()
          Retrieve the Consequence associated with this Rule.
 String getDocumentation()
          Retrieve the documentation.
 Duration getDuration()
          Retrieve the truthness duration object.
 Set getImports()
           
 long getLoadOrder()
           
 String getName()
          Retrieve the name of this rule.
 boolean getNoLoop()
           
 Declaration getParameterDeclaration(String identifier)
          Retrieve a parameter Declaration by identifier.
 List getParameterDeclarations()
          Retrieve the set of all root fact object parameter Declarations.
 RuleSet getRule()
           
 int getSalience()
          Retrieve the Rule salience.
 boolean isValid()
          Determine if this rule is internally consistent and valid.
 void setApplicationData(Map applicationData)
           
 void setConsequence(Consequence consequence)
          Set the Consequence that is associated with the successful match of this rule.
 void setDocumentation(String documentation)
          Set the documentation.
 void setDuration(Duration duration)
          Set the truthness duration object.
 void setDuration(long seconds)
          Set the truthness duration.
 void setImports(Set imports)
           
(package private)  void setLoadOrder(long loadOrder)
           
 void setNoLoop(boolean noLoop)
           
 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
 

Constructor Detail

Rule

public Rule(String name,
            RuleSet ruleSet)
Construct.

Parameters:
name - The name of this rule.

Rule

public Rule(String name)
Construct.

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

setDocumentation

public void setDocumentation(String documentation)
Set the documentation.

Parameters:
documentation - The documentation.

getDocumentation

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

getRule

public RuleSet getRule()

getName

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

getNoLoop

public boolean getNoLoop()

setNoLoop

public void setNoLoop(boolean noLoop)

addParameterDeclaration

public Declaration addParameterDeclaration(String identifier,
                                           ObjectType objectType)
                                    throws InvalidRuleException
Add a root fact object parameter Declaration for this Rule.

Parameters:
identifier - The identifier.
objectType - The type.
Returns:
The declaration.
Throws:
InvalidRuleException

getParameterDeclaration

public Declaration getParameterDeclaration(String identifier)
Retrieve a parameter Declaration by identifier.

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

getParameterDeclarations

public List getParameterDeclarations()
Retrieve the set of all root fact object parameter Declarations.

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

addCondition

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

Parameters:
condition - The Condition to add.

getConditions

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

Returns:
The List of Conditions.

getConditionSize

public int getConditionSize()

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()

setLoadOrder

void setLoadOrder(long loadOrder)

setImports

public void setImports(Set imports)

getImports

public Set getImports()

setApplicationData

public void setApplicationData(Map applicationData)

getApplicationData

public Map getApplicationData()

dump

public String dump(String indent)


Copyright © 2001-2004 The Codehaus. All Rights Reserved.