org.drools.rule
Class Rule

java.lang.Object
  extended by org.drools.rule.Rule
All Implemented Interfaces:
Externalizable, Serializable, org.drools.definition.KnowledgeDefinition, org.drools.definition.rule.Query, org.drools.definition.rule.Rule, Dialectable, Wireable
Direct Known Subclasses:
Query

public class Rule
extends Object
implements Externalizable, Wireable, Dialectable, org.drools.definition.rule.Rule, org.drools.definition.rule.Query

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:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.drools.definition.KnowledgeDefinition
org.drools.definition.KnowledgeDefinition.KnowledgeType
 
Field Summary
protected  String activationListener
           
 
Constructor Summary
Rule()
           
Rule(String name)
           
Rule(String name, String agendaGroup)
          Construct a Rule with the given name for the specified pkg parent
Rule(String name, String pkg, String agendaGroup)
          Construct a Rule with the given name for the specified pkg parent
 
Method Summary
 void addMetaAttribute(String key, Object value)
           
 void addPattern(RuleConditionElement element)
          Add a pattern to the rule.
 boolean equals(Object obj)
           
 String getActivationGroup()
           
 String getActivationListener()
           
 String getAgendaGroup()
           
 boolean getAutoFocus()
           
 String[] getCalendars()
           
 Consequence getConsequence()
          Retrieve the Consequence associated with this Rule.
 Calendar getDateEffective()
           
 Calendar getDateExpires()
           
 Declaration getDeclaration(String identifier)
          Retrieve a parameter Declaration by identifier.
 Map<String,Declaration> getDeclarations()
          Retrieve the set of all root fact object parameter Declarations.
 String getDialect()
           
 Enabled getEnabled()
           
 String getId()
           
 org.drools.definition.KnowledgeDefinition.KnowledgeType getKnowledgeType()
           
 GroupElement getLhs()
          Retrieve the List of Conditions for this rule.
 long getLoadOrder()
           
 String getMetaAttribute(String identifier)
          Deprecated. 
 Map<String,Object> getMetaAttributes()
          Deprecated. 
 Map<String,Object> getMetaData()
           
static List getMethodBytecode(Class cls, String ruleClassName, String packageName, String methodName, String resource)
           
 String getName()
          Retrieve the name of this rule.
 Map<String,Consequence> getNamedConsequences()
           
 String getNamespace()
           
 String getPackage()
           
 String getPackageName()
           
 Rule getParent()
           
 String[] getRequiredDeclarations()
           
 org.drools.io.Resource getResource()
           
 String getRuleFlowGroup()
           
 int getRunLevel()
           
 Salience getSalience()
          Retrieve the Rule salience.
 int getSpecifity()
           
 Timer getTimer()
          Returns the Timer semantics for a rule.
 GroupElement[] 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 hasLogicalDependency()
          This field is updated at runtime, when the first logical assertion is done.
 boolean isEffective(Tuple tuple, RuleTerminalNode rtn, WorkingMemory workingMemory)
          This returns true is the rule is effective.
 boolean isEnabled(Tuple tuple, RuleTerminalNode rtn, WorkingMemory workingMemory)
           
 boolean isLockOnActive()
           
 boolean isNoLoop()
           
 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.
 Collection<String> listMetaAttributes()
          Deprecated. 
 void readExternal(ObjectInput in)
           
 void setActivationGroup(String activationGroup)
           
 void setActivationListener(String activationListener)
           
 void setAgendaGroup(String agendaGroup)
           
 void setAutoFocus(boolean autoFocus)
           
 void setCalendars(String[] calendars)
           
 void setConsequence(Consequence consequence)
          Set the Consequence that is associated with the successful match of this rule.
 void setDateEffective(Calendar effectiveDate)
          Sets the date from which this rule takes effect (can include time to the millisecond).
 void setDateExpires(Calendar expiresDate)
          Sets the date after which the rule will no longer apply (can include time to the millisecond).
 void setDialect(String dialect)
           
 void setEnabled(Enabled b)
          A rule is enabled by default.
 void setHasLogicalDependency(boolean hasLogicalDependency)
           
 void setLhs(GroupElement lhsRoot)
           
 void setLoadOrder(long loadOrder)
           
 void setLockOnActive(boolean lockOnActive)
           
 void setNoLoop(boolean noLoop)
           
 void setPackage(String pkg)
           
 void setParent(Rule parent)
           
 void setRequiredDeclarations(String[] requiredDeclarations)
           
 void setResource(org.drools.io.Resource resource)
           
 void setRuleFlowGroup(String ruleFlowGroup)
           
 void setRunLevel(int level)
           
 void setSalience(Salience salience)
          Set the Rule salience.
 void setSemanticallyValid(boolean valid)
           
 void setTimer(Timer timer)
          Sets the timer semantics for a rule.
 String toString()
           
 void wire(Object object)
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

activationListener

protected String activationListener
Constructor Detail

Rule

public Rule()

Rule

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

Parameters:
name - The name of this rule.

Rule

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

Parameters:
name - The name of this rule.

Rule

public Rule(String name)
Method Detail

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

getResource

public org.drools.io.Resource getResource()

setResource

public void setResource(org.drools.io.Resource resource)

getDialect

public String getDialect()
Specified by:
getDialect in interface Dialectable

setDialect

public void setDialect(String dialect)

getTimer

public Timer getTimer()
Returns the Timer semantics for a rule. Timer based rules are not added directly to the Agenda instead they are scheduled for Agenda addition, based on the timer.

Returns:

setTimer

public void setTimer(Timer timer)
Sets the timer semantics for a rule. Timer based rules are not added directly to the Agenda instead they are scheduled for Agenda addition, based on the timer.

Parameters:
timer -

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

setPackage

public void setPackage(String pkg)

getPackageName

public String getPackageName()
Specified by:
getPackageName in interface org.drools.definition.rule.Query
Specified by:
getPackageName in interface org.drools.definition.rule.Rule

getName

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

Specified by:
getName in interface org.drools.definition.rule.Query
Specified by:
getName in interface org.drools.definition.rule.Rule
Returns:
The name of this rule.

getSalience

public Salience getSalience()
Retrieve the Rule salience.

Returns:
The salience.

setSalience

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

Parameters:
salience - The salience.

getRunLevel

public int getRunLevel()

setRunLevel

public void setRunLevel(int level)

getAgendaGroup

public String getAgendaGroup()

setAgendaGroup

public void setAgendaGroup(String agendaGroup)

isNoLoop

public boolean isNoLoop()

isEffective

public boolean isEffective(Tuple tuple,
                           RuleTerminalNode rtn,
                           WorkingMemory workingMemory)
This returns true is the rule is effective. If the rule is not effective, it cannot activate. This uses the dateEffective, dateExpires and enabled flag to decide this.


setNoLoop

public void setNoLoop(boolean noLoop)

getAutoFocus

public boolean getAutoFocus()

setAutoFocus

public void setAutoFocus(boolean autoFocus)

getActivationGroup

public String getActivationGroup()

setActivationGroup

public void setActivationGroup(String activationGroup)

getRuleFlowGroup

public String getRuleFlowGroup()

setRuleFlowGroup

public void setRuleFlowGroup(String ruleFlowGroup)

getDeclaration

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

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

getRequiredDeclarations

public String[] getRequiredDeclarations()

setRequiredDeclarations

public void setRequiredDeclarations(String[] requiredDeclarations)

hasLogicalDependency

public boolean hasLogicalDependency()
This field is updated at runtime, when the first logical assertion is done. I'm currently not too happy about having this determine at runtime but its currently easier than trying to do this at compile time, although eventually this should be changed

Returns:

setHasLogicalDependency

public void setHasLogicalDependency(boolean hasLogicalDependency)

isLockOnActive

public boolean isLockOnActive()

setLockOnActive

public void setLockOnActive(boolean lockOnActive)

getDeclarations

public Map<String,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(RuleConditionElement element)
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

getLhs

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

Returns:
The List of Conditions.

setLhs

public void setLhs(GroupElement lhsRoot)

getTransformedLhs

public GroupElement[] 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()

wire

public void wire(Object object)
Specified by:
wire in interface Wireable

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.

getNamedConsequences

public Map<String,Consequence> getNamedConsequences()

getLoadOrder

public long getLoadOrder()

setLoadOrder

public void setLoadOrder(long loadOrder)

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class 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.


getCalendars

public String[] getCalendars()

setCalendars

public void setCalendars(String[] calendars)

setDateEffective

public void setDateEffective(Calendar effectiveDate)
Sets the date from which this rule takes effect (can include time to the millisecond).

Parameters:
effectiveDate -

setDateExpires

public void setDateExpires(Calendar expiresDate)
Sets the date after which the rule will no longer apply (can include time to the millisecond).

Parameters:
expiresDate -

getDateEffective

public Calendar getDateEffective()

getDateExpires

public Calendar getDateExpires()

setEnabled

public void setEnabled(Enabled b)
A rule is enabled by default. This can explicitly disable it in which case it will never activate.


getEnabled

public Enabled getEnabled()

isEnabled

public boolean isEnabled(Tuple tuple,
                         RuleTerminalNode rtn,
                         WorkingMemory workingMemory)

addMetaAttribute

public void addMetaAttribute(String key,
                             Object value)

getActivationListener

public String getActivationListener()

setActivationListener

public void setActivationListener(String activationListener)

getMetaData

public Map<String,Object> getMetaData()
Specified by:
getMetaData in interface org.drools.definition.rule.Query
Specified by:
getMetaData in interface org.drools.definition.rule.Rule

getMetaAttributes

@Deprecated
public Map<String,Object> getMetaAttributes()
Deprecated. 

Specified by:
getMetaAttributes in interface org.drools.definition.rule.Query
Specified by:
getMetaAttributes in interface org.drools.definition.rule.Rule

getMetaAttribute

@Deprecated
public String getMetaAttribute(String identifier)
Deprecated. 

Specified by:
getMetaAttribute in interface org.drools.definition.rule.Query
Specified by:
getMetaAttribute in interface org.drools.definition.rule.Rule

listMetaAttributes

@Deprecated
public Collection<String> listMetaAttributes()
Deprecated. 

Specified by:
listMetaAttributes in interface org.drools.definition.rule.Query
Specified by:
listMetaAttributes in interface org.drools.definition.rule.Rule

setParent

public void setParent(Rule parent)

getParent

public Rule getParent()

getMethodBytecode

public static List getMethodBytecode(Class cls,
                                     String ruleClassName,
                                     String packageName,
                                     String methodName,
                                     String resource)

getKnowledgeType

public org.drools.definition.KnowledgeDefinition.KnowledgeType getKnowledgeType()
Specified by:
getKnowledgeType in interface org.drools.definition.KnowledgeDefinition

getNamespace

public String getNamespace()
Specified by:
getNamespace in interface org.drools.definition.KnowledgeDefinition

getId

public String getId()
Specified by:
getId in interface org.drools.definition.KnowledgeDefinition


Copyright © 2001-2012 JBoss by Red Hat. All Rights Reserved.