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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.kie.api.definition.KieDefinition
KieDefinition.KnowledgeTypeNested classes/interfaces inherited from interface org.drools.base.rule.accessor.Wireable
Wireable.Immutable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddMetaAttribute(String key, Object value) voidaddNamedConsequence(String name, Consequence consequence) voidaddPattern(RuleConditionElement element) Add a pattern to the rule.voidaddUsedQuery(QueryImpl query) protected Collection<QueryImpl>collectDependingQueries(Deque<QueryImpl> accumulator) booleanfindEnabledDeclarations(Map<String, Declaration> decls) findSalienceDeclarations(Map<String, Declaration> decls) booleanString[]Retrieve theConsequenceassociated with thisRule.getDeclaration(String identifier) Retrieve a parameterDeclarationby identifier.Retrieve the set of all root fact object parameterDeclarations.Returns the lists of queries from which this rule (or query) depends on ordered by their relative dependencies, e.g.getId()getLhs()Retrieve theListofConditionsfor this rule.intgetMetaData(String name) getName()Retrieve the name of this rule.getNamedConsequence(String consequenceName) String[]getRequiredDeclarationsForConsequence(String consequenceName) Retrieve theRulesalience.intRetrieve theRulesalience value.getTimer()Returns the Timer semantics for a rule.getTransformedLhs(LogicTransformer transformer, Map<String, 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.booleanbooleaninthashCode()booleanThis field is updated at runtime, when the first logical assertion is done.booleanbooleanbooleanbooleanisEager()booleanisEffective(BaseTuple tuple, Declaration[] declarations, ValueResolver valueResolver) This returns true is the rule is effective.booleanisEnabled(BaseTuple tuple, Declaration[] enabledDeclarations, ValueResolver valueResolver) booleanbooleanbooleanisNoLoop()booleanisQuery()booleanReturnstrueif the rule uses dynamic salience,falseotherwise.booleanThis will return if the semantic actions or predicates in the rules are valid.booleanisValid()Determine if this rule is internally consistent and valid.voidvoidremoveChild(RuleImpl child) voidsetActivationGroup(String activationGroup) voidsetActivationListener(String activationListener) setAgendaGroup(String agendaGroup) voidsetAllMatches(boolean allMatches) voidsetAutoFocus(boolean autoFocus) voidsetCalendars(String[] calendars) voidsetConsequence(Consequence consequence) Set theConsequencethat is associated with the successful match of this rule.voidsetDataDriven(boolean dataDriven) voidsetDateEffective(Calendar effectiveDate) Sets the date from which this rule takes effect (can include time to the millisecond).voidsetDateExpires(Calendar expiresDate) Sets the date after which the rule will no longer apply (can include time to the millisecond).voidsetDialect(String dialect) voidsetEager(boolean eager) voidA rule is enabled by default.voidsetHasLogicalDependency(boolean hasLogicalDependency) voidsetLhs(GroupElement lhsRoot) voidsetLoadOrder(int loadOrder) voidsetLockOnActive(boolean lockOnActive) voidsetNoLoop(boolean noLoop) setPackage(String pkg) voidvoidsetRequiredDeclarationsForConsequence(String consequenceName, String[] requiredDeclarations) voidsetResource(Resource resource) voidsetRuleFlowGroup(String ruleFlowGroup) voidsetRuleUnitClass(Class<?> ruleUnit) voidsetRuleUnitClassName(String ruleUnitClassName) voidsetSalience(Salience salience) Set theRulesalience.voidsetSemanticallyValid(boolean valid) voidSets the timer semantics for a rule.toString()voidvoid
-
Field Details
-
DEFAULT_CONSEQUENCE_NAME
- See Also:
-
activationListener
-
-
Constructor Details
-
RuleImpl
public RuleImpl() -
RuleImpl
Construct aRulewith the given name for the specified pkg parent- Parameters:
name- The name of this rule.
-
-
Method Details
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
addUsedQuery
-
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
-
getResource
- Specified by:
getResourcein interfaceInternalRule
-
setResource
-
getDialect
- Specified by:
getDialectin interfaceDialectable- Specified by:
getDialectin interfaceInternalRule
-
setDialect
-
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
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 interfaceInternalRule- Returns:
trueif this rule is valid, elsefalse.
-
getPackage
-
setPackage
-
getPackageName
- Specified by:
getPackageNamein interfaceQuery- Specified by:
getPackageNamein interfaceRule
-
getName
Retrieve the name of this rule. -
getFullyQualifiedName
- Specified by:
getFullyQualifiedNamein interfaceInternalRule
-
getSalience
Retrieve theRulesalience.- Returns:
- The salience.
-
getSalienceValue
public int getSalienceValue()Retrieve theRulesalience value.- Specified by:
getSalienceValuein interfaceInternalRule- Returns:
- The salience value.
-
isSalienceDynamic
public boolean isSalienceDynamic()Returnstrueif the rule uses dynamic salience,falseotherwise.- Specified by:
isSalienceDynamicin interfaceInternalRule- Returns:
trueif the rule uses dynamic salience, elsefalse.
-
setSalience
Set theRulesalience.- Parameters:
salience- The salience.
-
getAgendaGroup
- Specified by:
getAgendaGroupin interfaceInternalRule
-
setAgendaGroup
-
isMainAgendaGroup
public boolean isMainAgendaGroup()- Specified by:
isMainAgendaGroupin interfaceInternalRule
-
isNoLoop
public boolean isNoLoop()- Specified by:
isNoLoopin interfaceInternalRule
-
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 interfaceInternalRule
-
setAutoFocus
public void setAutoFocus(boolean autoFocus) -
getActivationGroup
- Specified by:
getActivationGroupin interfaceInternalRule
-
setActivationGroup
-
getRuleFlowGroup
- Specified by:
getRuleFlowGroupin interfaceInternalRule
-
setRuleFlowGroup
-
getDeclaration
Retrieve a parameterDeclarationby identifier.- Parameters:
identifier- The identifier.- Returns:
- The declaration or
nullif no declaration matches theidentifier.
-
getRequiredDeclarationsForConsequence
-
setRequiredDeclarationsForConsequence
-
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 interfaceInternalRule
-
setLockOnActive
public void setLockOnActive(boolean lockOnActive) -
getDeclarations
Retrieve the set of all root fact object parameterDeclarations.- Returns:
- The Set of
Declarationsin order which specify the root fact objects.
-
addPattern
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
Retrieve theListofConditionsfor this rule.- Returns:
- The
ListofConditions.
-
setLhs
-
getTransformedLhs
public GroupElement[] getTransformedLhs(LogicTransformer transformer, Map<String, Type> globals) throws InvalidPatternExceptionUses 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
-
setConsequence
Set theConsequencethat is associated with the successful match of this rule.- Parameters:
consequence- TheConsequenceto attach to thisRule.
-
getConsequence
Retrieve theConsequenceassociated with thisRule.- Returns:
- The
Consequence.
-
hasNamedConsequences
public boolean hasNamedConsequences() -
getNamedConsequence
-
addNamedConsequence
-
getLoadOrder
public int getLoadOrder()- Specified by:
getLoadOrderin interfaceRule
-
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
-
toRuleNameAndPathString
-
hashCode
public int hashCode() -
equals
-
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
-
setCalendars
-
setDateEffective
Sets the date from which this rule takes effect (can include time to the millisecond).- Parameters:
effectiveDate-
-
setDateExpires
Sets the date after which the rule will no longer apply (can include time to the millisecond).- Parameters:
expiresDate-
-
getDateEffective
- Specified by:
getDateEffectivein interfaceInternalRule
-
getDateExpires
- Specified by:
getDateExpiresin interfaceInternalRule
-
setEnabled
A rule is enabled by default. This can explicitly disable it in which case it will never activate. -
getEnabled
-
isEnabled
public boolean isEnabled(BaseTuple tuple, Declaration[] enabledDeclarations, ValueResolver valueResolver) -
addMetaAttribute
-
getActivationListener
-
setActivationListener
-
getMetaData
- Specified by:
getMetaDatain interfaceQuery- Specified by:
getMetaDatain interfaceRule
-
getMetaData
-
setParent
-
getParent
-
addChild
-
removeChild
-
getChildren
-
hasChildren
public boolean hasChildren() -
isQuery
public boolean isQuery() -
getKnowledgeType
- Specified by:
getKnowledgeTypein interfaceKieDefinition
-
getNamespace
- Specified by:
getNamespacein interfaceKieDefinition
-
getId
- Specified by:
getIdin interfaceKieDefinition
-
getConsequenceMetaData
-
getRuleUnitClassName
-
setRuleUnitClass
-
setRuleUnitClassName
-
findEnabledDeclarations
-
findSalienceDeclarations
-