Class RuleImpl
- java.lang.Object
-
- org.drools.base.definitions.rule.impl.RuleImpl
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,Wireable,Dialectable,org.kie.api.definition.KieDefinition,org.kie.api.definition.rule.Query,org.kie.api.definition.rule.Rule,org.kie.internal.definition.rule.InternalRule
- Direct Known Subclasses:
QueryImpl
public class RuleImpl extends java.lang.Object implements java.io.Externalizable, Wireable, Dialectable, org.kie.internal.definition.rule.InternalRule, org.kie.api.definition.rule.Query
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.kie.api.definition.KieDefinition
org.kie.api.definition.KieDefinition.KnowledgeType
-
Nested classes/interfaces inherited from interface org.drools.base.rule.accessor.Wireable
Wireable.Immutable
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringactivationListenerstatic java.lang.StringDEFAULT_CONSEQUENCE_NAME
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(RuleImpl child)voidaddMetaAttribute(java.lang.String key, java.lang.Object value)voidaddNamedConsequence(java.lang.String name, Consequence consequence)voidaddPattern(RuleConditionElement element)Add a pattern to the rule.voidaddUsedQuery(QueryImpl query)protected java.util.Collection<QueryImpl>collectDependingQueries(java.util.Deque<QueryImpl> accumulator)booleanequals(java.lang.Object obj)Declaration[]findEnabledDeclarations(java.util.Map<java.lang.String,Declaration> decls)Declaration[]findSalienceDeclarations(java.util.Map<java.lang.String,Declaration> decls)java.lang.StringgetActivationGroup()java.lang.StringgetActivationListener()java.lang.StringgetAgendaGroup()booleangetAutoFocus()java.lang.String[]getCalendars()java.util.List<RuleImpl>getChildren()ConsequencegetConsequence()Retrieve theConsequenceassociated with thisRule.ConsequenceMetaDatagetConsequenceMetaData()java.util.CalendargetDateEffective()java.util.CalendargetDateExpires()DeclarationgetDeclaration(java.lang.String identifier)Retrieve a parameterDeclarationby identifier.java.util.Map<java.lang.String,Declaration>getDeclarations()Retrieve the set of all root fact object parameterDeclarations.java.util.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]java.lang.StringgetDialect()EnabledgetEnabled()java.lang.StringgetFullyQualifiedName()java.lang.StringgetId()org.kie.api.definition.KieDefinition.KnowledgeTypegetKnowledgeType()GroupElementgetLhs()Retrieve theListofConditionsfor this rule.intgetLoadOrder()java.util.Map<java.lang.String,java.lang.Object>getMetaData()java.lang.ObjectgetMetaData(java.lang.String name)java.lang.StringgetName()Retrieve the name of this rule.ConsequencegetNamedConsequence(java.lang.String consequenceName)java.lang.StringgetNamespace()java.lang.StringgetPackage()java.lang.StringgetPackageName()RuleImplgetParent()java.lang.String[]getRequiredDeclarationsForConsequence(java.lang.String consequenceName)org.kie.api.io.ResourcegetResource()java.lang.StringgetRuleFlowGroup()java.lang.StringgetRuleUnitClassName()SaliencegetSalience()Retrieve theRulesalience.intgetSalienceValue()Retrieve theRulesalience value.TimergetTimer()Returns the Timer semantics for a rule.GroupElement[]getTransformedLhs(LogicTransformer transformer, java.util.Map<java.lang.String,java.lang.reflect.Type> globals)Uses the LogicTransformer to process the Rule patters - if no ORs are used this will return an array of a single AND element.booleanhasCalendars()booleanhasChildren()inthashCode()booleanhasLogicalDependency()This field is updated at runtime, when the first logical assertion is done.booleanhasNamedConsequences()booleanisAllMatches()booleanisDataDriven()booleanisEager()booleanisEffective(BaseTuple tuple, Declaration[] declarations, ValueResolver valueResolver)This returns true is the rule is effective.booleanisEnabled(BaseTuple tuple, Declaration[] enabledDeclarations, ValueResolver valueResolver)booleanisLockOnActive()booleanisMainAgendaGroup()booleanisNoLoop()booleanisQuery()booleanisSalienceDynamic()Returnstrueif the rule uses dynamic salience,falseotherwise.booleanisSemanticallyValid()This will return if the semantic actions or predicates in the rules are valid.booleanisValid()Determine if this rule is internally consistent and valid.voidreadExternal(java.io.ObjectInput in)voidremoveChild(RuleImpl child)voidsetActivationGroup(java.lang.String activationGroup)voidsetActivationListener(java.lang.String activationListener)RuleImplsetAgendaGroup(java.lang.String agendaGroup)voidsetAllMatches(boolean allMatches)voidsetAutoFocus(boolean autoFocus)voidsetCalendars(java.lang.String[] calendars)voidsetConsequence(Consequence consequence)Set theConsequencethat is associated with the successful match of this rule.voidsetDataDriven(boolean dataDriven)voidsetDateEffective(java.util.Calendar effectiveDate)Sets the date from which this rule takes effect (can include time to the millisecond).voidsetDateExpires(java.util.Calendar expiresDate)Sets the date after which the rule will no longer apply (can include time to the millisecond).voidsetDialect(java.lang.String dialect)voidsetEager(boolean eager)voidsetEnabled(Enabled b)A rule is enabled by default.voidsetHasLogicalDependency(boolean hasLogicalDependency)voidsetLhs(GroupElement lhsRoot)voidsetLoadOrder(int loadOrder)voidsetLockOnActive(boolean lockOnActive)voidsetNoLoop(boolean noLoop)RuleImplsetPackage(java.lang.String pkg)voidsetParent(RuleImpl parent)voidsetRequiredDeclarationsForConsequence(java.lang.String consequenceName, java.lang.String[] requiredDeclarations)voidsetResource(org.kie.api.io.Resource resource)voidsetRuleFlowGroup(java.lang.String ruleFlowGroup)voidsetRuleUnitClass(java.lang.Class<?> ruleUnit)voidsetRuleUnitClassName(java.lang.String ruleUnitClassName)voidsetSalience(Salience salience)Set theRulesalience.voidsetSemanticallyValid(boolean valid)voidsetTimer(Timer timer)Sets the timer semantics for a rule.java.lang.StringtoRuleNameAndPathString()java.lang.StringtoString()voidwire(java.lang.Object object)voidwriteExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
DEFAULT_CONSEQUENCE_NAME
public static final java.lang.String DEFAULT_CONSEQUENCE_NAME
- See Also:
- Constant Field Values
-
activationListener
protected java.lang.String activationListener
-
-
Method Detail
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
addUsedQuery
public void addUsedQuery(QueryImpl query)
-
getDependingQueries
public java.util.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 java.util.Collection<QueryImpl> collectDependingQueries(java.util.Deque<QueryImpl> accumulator)
-
getResource
public org.kie.api.io.Resource getResource()
- Specified by:
getResourcein interfaceorg.kie.internal.definition.rule.InternalRule
-
setResource
public void setResource(org.kie.api.io.Resource resource)
-
getDialect
public java.lang.String getDialect()
- Specified by:
getDialectin interfaceDialectable- Specified by:
getDialectin interfaceorg.kie.internal.definition.rule.InternalRule
-
setDialect
public void setDialect(java.lang.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
Rulemust include at least one parameter declaration and one condition.- Specified by:
isValidin interfaceorg.kie.internal.definition.rule.InternalRule- Returns:
trueif this rule is valid, elsefalse.
-
getPackage
public java.lang.String getPackage()
-
setPackage
public RuleImpl setPackage(java.lang.String pkg)
-
getPackageName
public java.lang.String getPackageName()
- Specified by:
getPackageNamein interfaceorg.kie.api.definition.rule.Query- Specified by:
getPackageNamein interfaceorg.kie.api.definition.rule.Rule
-
getName
public java.lang.String getName()
Retrieve the name of this rule.- Specified by:
getNamein interfaceorg.kie.api.definition.rule.Query- Specified by:
getNamein interfaceorg.kie.api.definition.rule.Rule- Returns:
- The name of this rule.
-
getFullyQualifiedName
public java.lang.String getFullyQualifiedName()
- Specified by:
getFullyQualifiedNamein interfaceorg.kie.internal.definition.rule.InternalRule
-
getSalience
public Salience getSalience()
Retrieve theRulesalience.- Returns:
- The salience.
-
getSalienceValue
public int getSalienceValue()
Retrieve theRulesalience value.- Specified by:
getSalienceValuein interfaceorg.kie.internal.definition.rule.InternalRule- Returns:
- The salience value.
-
isSalienceDynamic
public boolean isSalienceDynamic()
Returnstrueif the rule uses dynamic salience,falseotherwise.- Specified by:
isSalienceDynamicin interfaceorg.kie.internal.definition.rule.InternalRule- Returns:
trueif the rule uses dynamic salience, elsefalse.
-
setSalience
public void setSalience(Salience salience)
Set theRulesalience.- Parameters:
salience- The salience.
-
getAgendaGroup
public java.lang.String getAgendaGroup()
- Specified by:
getAgendaGroupin interfaceorg.kie.internal.definition.rule.InternalRule
-
setAgendaGroup
public RuleImpl setAgendaGroup(java.lang.String agendaGroup)
-
isMainAgendaGroup
public boolean isMainAgendaGroup()
- Specified by:
isMainAgendaGroupin interfaceorg.kie.internal.definition.rule.InternalRule
-
isNoLoop
public boolean isNoLoop()
- Specified by:
isNoLoopin interfaceorg.kie.internal.definition.rule.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:
getAutoFocusin interfaceorg.kie.internal.definition.rule.InternalRule
-
setAutoFocus
public void setAutoFocus(boolean autoFocus)
-
getActivationGroup
public java.lang.String getActivationGroup()
- Specified by:
getActivationGroupin interfaceorg.kie.internal.definition.rule.InternalRule
-
setActivationGroup
public void setActivationGroup(java.lang.String activationGroup)
-
getRuleFlowGroup
public java.lang.String getRuleFlowGroup()
- Specified by:
getRuleFlowGroupin interfaceorg.kie.internal.definition.rule.InternalRule
-
setRuleFlowGroup
public void setRuleFlowGroup(java.lang.String ruleFlowGroup)
-
getDeclaration
public Declaration getDeclaration(java.lang.String identifier)
Retrieve a parameterDeclarationby identifier.- Parameters:
identifier- The identifier.- Returns:
- The declaration or
nullif no declaration matches theidentifier.
-
getRequiredDeclarationsForConsequence
public java.lang.String[] getRequiredDeclarationsForConsequence(java.lang.String consequenceName)
-
setRequiredDeclarationsForConsequence
public void setRequiredDeclarationsForConsequence(java.lang.String consequenceName, java.lang.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:
isLockOnActivein interfaceorg.kie.internal.definition.rule.InternalRule
-
setLockOnActive
public void setLockOnActive(boolean lockOnActive)
-
getDeclarations
public java.util.Map<java.lang.String,Declaration> getDeclarations()
Retrieve the set of all root fact object parameterDeclarations.- Returns:
- The Set of
Declarationsin 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- TheTestto add.- Throws:
InvalidRuleException
-
getLhs
public GroupElement getLhs()
Retrieve theListofConditionsfor this rule.- Returns:
- The
ListofConditions.
-
setLhs
public void setLhs(GroupElement lhsRoot)
-
getTransformedLhs
public GroupElement[] getTransformedLhs(LogicTransformer transformer, java.util.Map<java.lang.String,java.lang.reflect.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
-
setConsequence
public void setConsequence(Consequence consequence)
Set theConsequencethat is associated with the successful match of this rule.- Parameters:
consequence- TheConsequenceto attach to thisRule.
-
getConsequence
public Consequence getConsequence()
Retrieve theConsequenceassociated with thisRule.- Returns:
- The
Consequence.
-
hasNamedConsequences
public boolean hasNamedConsequences()
-
getNamedConsequence
public Consequence getNamedConsequence(java.lang.String consequenceName)
-
addNamedConsequence
public void addNamedConsequence(java.lang.String name, Consequence consequence)
-
getLoadOrder
public int getLoadOrder()
- Specified by:
getLoadOrderin interfaceorg.kie.api.definition.rule.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toRuleNameAndPathString
public java.lang.String toRuleNameAndPathString()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.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 java.lang.String[] getCalendars()
-
setCalendars
public void setCalendars(java.lang.String[] calendars)
-
setDateEffective
public void setDateEffective(java.util.Calendar effectiveDate)
Sets the date from which this rule takes effect (can include time to the millisecond).- Parameters:
effectiveDate-
-
setDateExpires
public void setDateExpires(java.util.Calendar expiresDate)
Sets the date after which the rule will no longer apply (can include time to the millisecond).- Parameters:
expiresDate-
-
getDateEffective
public java.util.Calendar getDateEffective()
- Specified by:
getDateEffectivein interfaceorg.kie.internal.definition.rule.InternalRule
-
getDateExpires
public java.util.Calendar getDateExpires()
- Specified by:
getDateExpiresin interfaceorg.kie.internal.definition.rule.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(java.lang.String key, java.lang.Object value)
-
getActivationListener
public java.lang.String getActivationListener()
-
setActivationListener
public void setActivationListener(java.lang.String activationListener)
-
getMetaData
public java.util.Map<java.lang.String,java.lang.Object> getMetaData()
- Specified by:
getMetaDatain interfaceorg.kie.api.definition.rule.Query- Specified by:
getMetaDatain interfaceorg.kie.api.definition.rule.Rule
-
getMetaData
public java.lang.Object getMetaData(java.lang.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 java.util.List<RuleImpl> getChildren()
-
hasChildren
public boolean hasChildren()
-
isQuery
public boolean isQuery()
-
getKnowledgeType
public org.kie.api.definition.KieDefinition.KnowledgeType getKnowledgeType()
- Specified by:
getKnowledgeTypein interfaceorg.kie.api.definition.KieDefinition
-
getNamespace
public java.lang.String getNamespace()
- Specified by:
getNamespacein interfaceorg.kie.api.definition.KieDefinition
-
getId
public java.lang.String getId()
- Specified by:
getIdin interfaceorg.kie.api.definition.KieDefinition
-
getConsequenceMetaData
public ConsequenceMetaData getConsequenceMetaData()
-
getRuleUnitClassName
public java.lang.String getRuleUnitClassName()
-
setRuleUnitClass
public void setRuleUnitClass(java.lang.Class<?> ruleUnit)
-
setRuleUnitClassName
public void setRuleUnitClassName(java.lang.String ruleUnitClassName)
-
findEnabledDeclarations
public Declaration[] findEnabledDeclarations(java.util.Map<java.lang.String,Declaration> decls)
-
findSalienceDeclarations
public Declaration[] findSalienceDeclarations(java.util.Map<java.lang.String,Declaration> decls)
-
-