Class RuleImpl
- java.lang.Object
-
- org.drools.core.definitions.rule.impl.RuleImpl
-
- All Implemented Interfaces:
Externalizable
,Serializable
,Dialectable
,Wireable
,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 Object implements Externalizable, Wireable, Dialectable, org.kie.internal.definition.rule.InternalRule, org.kie.api.definition.rule.Query
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RuleImpl.SafeEnabled
static class
RuleImpl.SafeSalience
-
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.core.spi.Wireable
Wireable.Immutable
-
-
Field Summary
Fields Modifier and Type Field Description protected String
activationListener
static String
DEFAULT_CONSEQUENCE_NAME
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(RuleImpl child)
void
addMetaAttribute(String key, Object value)
void
addNamedConsequence(String name, Consequence consequence)
void
addPattern(RuleConditionElement element)
Add a pattern to the rule.void
addUsedQuery(QueryImpl query)
protected Collection<QueryImpl>
collectDependingQueries(Deque<QueryImpl> accumulator)
boolean
equals(Object obj)
Declaration[]
findEnabledDeclarations(Map<String,Declaration> decls)
Declaration[]
findSalienceDeclarations(Map<String,Declaration> decls)
String
getActivationGroup()
String
getActivationListener()
String
getAgendaGroup()
boolean
getAutoFocus()
String[]
getCalendars()
List<RuleImpl>
getChildren()
Consequence
getConsequence()
Retrieve theConsequence
associated with thisRule
.ConsequenceMetaData
getConsequenceMetaData()
Calendar
getDateEffective()
Calendar
getDateExpires()
Declaration
getDeclaration(String identifier)
Retrieve a parameterDeclaration
by identifier.Map<String,Declaration>
getDeclarations()
Retrieve the set of all root fact object parameterDeclarations
.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]String
getDialect()
Enabled
getEnabled()
String
getFullyQualifiedName()
String
getId()
org.kie.api.definition.KieDefinition.KnowledgeType
getKnowledgeType()
GroupElement
getLhs()
Retrieve theList
ofConditions
for this rule.int
getLoadOrder()
Map<String,Object>
getMetaData()
Object
getMetaData(String name)
String
getName()
Retrieve the name of this rule.Consequence
getNamedConsequence(String consequenceName)
String
getNamespace()
String
getPackage()
String
getPackageName()
RuleImpl
getParent()
String[]
getRequiredDeclarationsForConsequence(String consequenceName)
org.kie.api.io.Resource
getResource()
String
getRuleFlowGroup()
String
getRuleUnitClassName()
Salience
getSalience()
Retrieve theRule
salience.int
getSalienceValue()
Retrieve theRule
salience value.Timer
getTimer()
Returns the Timer semantics for a rule.GroupElement[]
getTransformedLhs(LogicTransformer transformer, Map<String,Class<?>> globals)
Uses the LogicTransformer to process the Rule patters - if no ORs are used this will return an array of a single AND element.boolean
hasCalendars()
boolean
hasChildren()
int
hashCode()
boolean
hasLogicalDependency()
This field is updated at runtime, when the first logical assertion is done.boolean
hasNamedConsequences()
boolean
hasRuleUnit()
boolean
isAllMatches()
boolean
isDataDriven()
boolean
isEager()
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
isMainAgendaGroup()
boolean
isNoLoop()
boolean
isQuery()
boolean
isSalienceDynamic()
Returnstrue
if the rule uses dynamic salience,false
otherwise.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.void
readExternal(ObjectInput in)
void
removeChild(RuleImpl child)
void
setActivationGroup(String activationGroup)
void
setActivationListener(String activationListener)
RuleImpl
setAgendaGroup(String agendaGroup)
void
setAllMatches(boolean allMatches)
void
setAutoFocus(boolean autoFocus)
void
setCalendars(String[] calendars)
void
setConsequence(Consequence consequence)
Set theConsequence
that is associated with the successful match of this rule.void
setDataDriven(boolean dataDriven)
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
setEager(boolean eager)
void
setEnabled(Enabled b)
A rule is enabled by default.void
setHasLogicalDependency(boolean hasLogicalDependency)
void
setLhs(GroupElement lhsRoot)
void
setLoadOrder(int loadOrder)
void
setLockOnActive(boolean lockOnActive)
void
setNoLoop(boolean noLoop)
RuleImpl
setPackage(String pkg)
void
setParent(RuleImpl parent)
void
setRequiredDeclarationsForConsequence(String consequenceName, String[] requiredDeclarations)
void
setResource(org.kie.api.io.Resource resource)
void
setRuleFlowGroup(String ruleFlowGroup)
void
setRuleUnitClass(Class<?> ruleUnit)
void
setRuleUnitClassName(String ruleUnitClassName)
void
setSalience(Salience salience)
Set theRule
salience.
void
setSemanticallyValid(boolean valid)
void
setTimer(Timer timer)
Sets the timer semantics for a rule.String
toRuleNameAndPathString()
String
toString()
void
wire(Object object)
void
writeExternal(ObjectOutput out)
-
-
-
Field Detail
-
DEFAULT_CONSEQUENCE_NAME
public static final String DEFAULT_CONSEQUENCE_NAME
- See Also:
- Constant Field Values
-
activationListener
protected String activationListener
-
-
Constructor Detail
-
RuleImpl
public RuleImpl()
-
RuleImpl
public RuleImpl(String name)
Construct aRule
with the given name for the specified pkg parent
- Parameters:
name
- The name of this rule.
-
-
Method Detail
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- 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 org.kie.api.io.Resource getResource()
- Specified by:
getResource
in interfaceorg.kie.internal.definition.rule.InternalRule
-
setResource
public void setResource(org.kie.api.io.Resource resource)
-
getDialect
public String getDialect()
- Specified by:
getDialect
in interfaceDialectable
- Specified by:
getDialect
in interfaceorg.kie.internal.definition.rule.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 interfaceorg.kie.internal.definition.rule.InternalRule
- Returns:
true
if this rule is valid, elsefalse
.
-
getPackage
public String getPackage()
-
getPackageName
public String getPackageName()
- Specified by:
getPackageName
in interfaceorg.kie.api.definition.rule.Query
- Specified by:
getPackageName
in interfaceorg.kie.api.definition.rule.Rule
-
getName
public String getName()
Retrieve the name of this rule.- Specified by:
getName
in interfaceorg.kie.api.definition.rule.Query
- Specified by:
getName
in interfaceorg.kie.api.definition.rule.Rule
- Returns:
- The name of this rule.
-
getFullyQualifiedName
public String getFullyQualifiedName()
- Specified by:
getFullyQualifiedName
in interfaceorg.kie.internal.definition.rule.InternalRule
-
getSalience
public Salience getSalience()
Retrieve theRule
salience.- Returns:
- The salience.
-
getSalienceValue
public int getSalienceValue()
Retrieve theRule
salience value.- Specified by:
getSalienceValue
in interfaceorg.kie.internal.definition.rule.InternalRule
- Returns:
- The salience value.
-
isSalienceDynamic
public boolean isSalienceDynamic()
Returnstrue
if the rule uses dynamic salience,false
otherwise.- Specified by:
isSalienceDynamic
in interfaceorg.kie.internal.definition.rule.InternalRule
- Returns:
true
if the rule uses dynamic salience, elsefalse
.
-
setSalience
public void setSalience(Salience salience)
Set theRule
salience.
- Parameters:
salience
- The salience.
-
getAgendaGroup
public String getAgendaGroup()
- Specified by:
getAgendaGroup
in interfaceorg.kie.internal.definition.rule.InternalRule
-
isMainAgendaGroup
public boolean isMainAgendaGroup()
- Specified by:
isMainAgendaGroup
in interfaceorg.kie.internal.definition.rule.InternalRule
-
isNoLoop
public boolean isNoLoop()
- Specified by:
isNoLoop
in interfaceorg.kie.internal.definition.rule.InternalRule
-
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()
- Specified by:
getAutoFocus
in interfaceorg.kie.internal.definition.rule.InternalRule
-
setAutoFocus
public void setAutoFocus(boolean autoFocus)
-
getActivationGroup
public String getActivationGroup()
- Specified by:
getActivationGroup
in interfaceorg.kie.internal.definition.rule.InternalRule
-
setActivationGroup
public void setActivationGroup(String activationGroup)
-
getRuleFlowGroup
public String getRuleFlowGroup()
- Specified by:
getRuleFlowGroup
in interfaceorg.kie.internal.definition.rule.InternalRule
-
setRuleFlowGroup
public void setRuleFlowGroup(String ruleFlowGroup)
-
getDeclaration
public Declaration getDeclaration(String identifier)
Retrieve a parameterDeclaration
by identifier.- Parameters:
identifier
- The identifier.- Returns:
- The declaration or
null
if no declaration matches theidentifier
.
-
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 interfaceorg.kie.internal.definition.rule.InternalRule
-
setLockOnActive
public void setLockOnActive(boolean lockOnActive)
-
getDeclarations
public Map<String,Declaration> getDeclarations()
Retrieve the set of all root fact object parameterDeclarations
.- 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
- TheTest
to add.- Throws:
InvalidRuleException
-
getLhs
public GroupElement getLhs()
Retrieve theList
ofConditions
for this rule.- Returns:
- The
List
ofConditions
.
-
setLhs
public void setLhs(GroupElement lhsRoot)
-
getTransformedLhs
public GroupElement[] getTransformedLhs(LogicTransformer transformer, Map<String,Class<?>> 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 theConsequence
that is associated with the successful match of this rule.- Parameters:
consequence
- TheConsequence
to attach to thisRule
.
-
getConsequence
public Consequence getConsequence()
Retrieve theConsequence
associated with thisRule
.- 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()
-
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)
-
toRuleNameAndPathString
public String toRuleNameAndPathString()
-
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 interfaceorg.kie.internal.definition.rule.InternalRule
-
getDateExpires
public Calendar getDateExpires()
- Specified by:
getDateExpires
in 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(Tuple tuple, RuleTerminalNode rtn, WorkingMemory workingMemory)
-
getActivationListener
public String getActivationListener()
-
setActivationListener
public void setActivationListener(String activationListener)
-
getMetaData
public Map<String,Object> getMetaData()
- Specified by:
getMetaData
in interfaceorg.kie.api.definition.rule.Query
- Specified by:
getMetaData
in interfaceorg.kie.api.definition.rule.Rule
-
setParent
public void setParent(RuleImpl parent)
-
getParent
public RuleImpl getParent()
-
addChild
public void addChild(RuleImpl child)
-
removeChild
public void removeChild(RuleImpl child)
-
hasChildren
public boolean hasChildren()
-
isQuery
public boolean isQuery()
-
getKnowledgeType
public org.kie.api.definition.KieDefinition.KnowledgeType getKnowledgeType()
- Specified by:
getKnowledgeType
in interfaceorg.kie.api.definition.KieDefinition
-
getNamespace
public String getNamespace()
- Specified by:
getNamespace
in interfaceorg.kie.api.definition.KieDefinition
-
getId
public String getId()
- Specified by:
getId
in interfaceorg.kie.api.definition.KieDefinition
-
getConsequenceMetaData
public ConsequenceMetaData getConsequenceMetaData()
-
getRuleUnitClassName
public String getRuleUnitClassName()
-
setRuleUnitClass
public void setRuleUnitClass(Class<?> ruleUnit)
-
setRuleUnitClassName
public void setRuleUnitClassName(String ruleUnitClassName)
-
hasRuleUnit
public boolean hasRuleUnit()
-
findEnabledDeclarations
public Declaration[] findEnabledDeclarations(Map<String,Declaration> decls)
-
findSalienceDeclarations
public Declaration[] findSalienceDeclarations(Map<String,Declaration> decls)
-
-