Class RuleImpl

java.lang.Object
org.drools.base.definitions.rule.impl.RuleImpl
All Implemented Interfaces:
Externalizable, Serializable, Wireable, Dialectable, KieDefinition, Query, Rule, InternalRule
Direct Known Subclasses:
QueryImpl

public class RuleImpl extends Object implements Externalizable, Wireable, Dialectable, InternalRule, Query
See Also:
  • Field Details

    • DEFAULT_CONSEQUENCE_NAME

      public static final String DEFAULT_CONSEQUENCE_NAME
      See Also:
    • activationListener

      protected String activationListener
  • Constructor Details

    • RuleImpl

      public RuleImpl()
    • RuleImpl

      public RuleImpl(String name)
      Construct a Rule with the given name for the specified pkg parent
      Parameters:
      name - The name of this rule.
  • Method Details

    • 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
    • addUsedQuery

      public void addUsedQuery(QueryImpl query)
    • getDependingQueries

      public Collection<QueryImpl> getDependingQueries()
      Returns the lists of queries from which this rule (or query) depends on ordered by their relative dependencies, e.g. if R1 -> A -> B -> C (where the letter are queries) it will return [C, B, A]
    • collectDependingQueries

      protected Collection<QueryImpl> collectDependingQueries(Deque<QueryImpl> accumulator)
    • getResource

      public Resource getResource()
      Specified by:
      getResource in interface InternalRule
    • setResource

      public void setResource(Resource resource)
    • getDialect

      public String getDialect()
      Specified by:
      getDialect in interface Dialectable
      Specified by:
      getDialect in interface InternalRule
    • 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.
    • 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.
    • 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.

      Specified by:
      isValid in interface InternalRule
      Returns:
      true if this rule is valid, else false.
    • getPackage

      public String getPackage()
    • setPackage

      public RuleImpl setPackage(String pkg)
    • getPackageName

      public String getPackageName()
      Specified by:
      getPackageName in interface Query
      Specified by:
      getPackageName in interface Rule
    • getName

      public String getName()
      Retrieve the name of this rule.
      Specified by:
      getName in interface Query
      Specified by:
      getName in interface Rule
      Returns:
      The name of this rule.
    • getFullyQualifiedName

      public String getFullyQualifiedName()
      Specified by:
      getFullyQualifiedName in interface InternalRule
    • getSalience

      public Salience getSalience()
      Retrieve the Rule salience.
      Returns:
      The salience.
    • getSalienceValue

      public int getSalienceValue()
      Retrieve the Rule salience value.
      Specified by:
      getSalienceValue in interface InternalRule
      Returns:
      The salience value.
    • isSalienceDynamic

      public boolean isSalienceDynamic()
      Returns true if the rule uses dynamic salience, false otherwise.
      Specified by:
      isSalienceDynamic in interface InternalRule
      Returns:
      true if the rule uses dynamic salience, else false.
    • setSalience

      public void setSalience(Salience salience)
      Set the Rule salience.
      Parameters:
      salience - The salience.
    • getAgendaGroup

      public String getAgendaGroup()
      Specified by:
      getAgendaGroup in interface InternalRule
    • setAgendaGroup

      public RuleImpl setAgendaGroup(String agendaGroup)
    • isMainAgendaGroup

      public boolean isMainAgendaGroup()
      Specified by:
      isMainAgendaGroup in interface InternalRule
    • isNoLoop

      public boolean isNoLoop()
      Specified by:
      isNoLoop in interface InternalRule
    • isEffective

      public boolean isEffective(BaseTuple tuple, Declaration[] declarations, ValueResolver valueResolver)
      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()
      Specified by:
      getAutoFocus in interface InternalRule
    • setAutoFocus

      public void setAutoFocus(boolean autoFocus)
    • getActivationGroup

      public String getActivationGroup()
      Specified by:
      getActivationGroup in interface InternalRule
    • setActivationGroup

      public void setActivationGroup(String activationGroup)
    • getRuleFlowGroup

      public String getRuleFlowGroup()
      Specified by:
      getRuleFlowGroup in interface InternalRule
    • 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.
    • getRequiredDeclarationsForConsequence

      public String[] getRequiredDeclarationsForConsequence(String consequenceName)
    • setRequiredDeclarationsForConsequence

      public void setRequiredDeclarationsForConsequence(String consequenceName, 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()
      Specified by:
      isLockOnActive in interface InternalRule
    • 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:
      element - 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(LogicTransformer transformer, Map<String,Type> globals) 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
    • 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.
    • hasNamedConsequences

      public boolean hasNamedConsequences()
    • getNamedConsequence

      public Consequence getNamedConsequence(String consequenceName)
    • addNamedConsequence

      public void addNamedConsequence(String name, Consequence consequence)
    • getLoadOrder

      public int getLoadOrder()
      Specified by:
      getLoadOrder in interface Rule
    • setLoadOrder

      public void setLoadOrder(int loadOrder)
    • isEager

      public boolean isEager()
    • setEager

      public void setEager(boolean eager)
    • isDataDriven

      public boolean isDataDriven()
    • setDataDriven

      public void setDataDriven(boolean dataDriven)
    • isAllMatches

      public boolean isAllMatches()
    • setAllMatches

      public void setAllMatches(boolean allMatches)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toRuleNameAndPathString

      public String toRuleNameAndPathString()
    • 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.
    • hasCalendars

      public boolean hasCalendars()
    • 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()
      Specified by:
      getDateEffective in interface InternalRule
    • getDateExpires

      public Calendar getDateExpires()
      Specified by:
      getDateExpires in interface InternalRule
    • 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(BaseTuple tuple, Declaration[] enabledDeclarations, ValueResolver valueResolver)
    • 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 Query
      Specified by:
      getMetaData in interface Rule
    • getMetaData

      public Object getMetaData(String name)
    • setParent

      public void setParent(RuleImpl parent)
    • getParent

      public RuleImpl getParent()
    • addChild

      public void addChild(RuleImpl child)
    • removeChild

      public void removeChild(RuleImpl child)
    • getChildren

      public List<RuleImpl> getChildren()
    • hasChildren

      public boolean hasChildren()
    • isQuery

      public boolean isQuery()
    • getKnowledgeType

      public KieDefinition.KnowledgeType getKnowledgeType()
      Specified by:
      getKnowledgeType in interface KieDefinition
    • getNamespace

      public String getNamespace()
      Specified by:
      getNamespace in interface KieDefinition
    • getId

      public String getId()
      Specified by:
      getId in interface KieDefinition
    • getConsequenceMetaData

      public ConsequenceMetaData getConsequenceMetaData()
    • getRuleUnitClassName

      public String getRuleUnitClassName()
    • setRuleUnitClass

      public void setRuleUnitClass(Class<?> ruleUnit)
    • setRuleUnitClassName

      public void setRuleUnitClassName(String ruleUnitClassName)
    • findEnabledDeclarations

      public Declaration[] findEnabledDeclarations(Map<String,Declaration> decls)
    • findSalienceDeclarations

      public Declaration[] findSalienceDeclarations(Map<String,Declaration> decls)