Class RuleModel
- java.lang.Object
-
- org.drools.workbench.models.datamodel.rule.RuleModel
-
- All Implemented Interfaces:
org.kie.soup.project.datamodel.imports.HasImports,org.kie.soup.project.datamodel.packages.HasPackageName
public class RuleModel extends Object implements org.kie.soup.project.datamodel.imports.HasImports, org.kie.soup.project.datamodel.packages.HasPackageName
-
-
Field Summary
Fields Modifier and Type Field Description RuleAttribute[]attributesstatic StringDEFAULT_TYPEIPattern[]lhsRuleMetadata[]metadataListStringmodelVersionStringnameThis name is generally not used - the asset name or the file name is preferred (ie it could get out of sync with the name of the file it is in).StringparentNameIAction[]rhs
-
Constructor Summary
Constructors Constructor Description RuleModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(RuleAttribute attribute)voidaddLhsItem(IPattern pat)voidaddLhsItem(IPattern pat, boolean append)voidaddLhsItem(IPattern pat, int position)voidaddMetadata(RuleMetadata metadata)Add metaDatavoidaddRhsItem(IAction action)voidaddRhsItem(IAction action, boolean append)voidaddRhsItem(IAction action, int position)booleanequals(Object o)List<String>getAllLHSVariables()This will get a list of all LHS bound variables, including bound fields..List<String>getAllRHSVariables()This will get a list of all RHS bound variables.List<String>getAllVariables()This will get a list of all bound variables (LHS and RHS), including bound fields..List<String>getBoundVariablesInScope(BaseSingleFieldConstraint con)This uses a deceptively simple algorithm to determine what bound variables are in scope for a given constraint (including connectives).List<String>getFieldBinding(FieldConstraint f)StringgetFieldBinding(FieldConstraint fc, String var)org.kie.soup.project.datamodel.imports.ImportsgetImports()StringgetLHSBindingType(String var)Get the data-type associated with the bindingFactPatterngetLHSBoundFact(String var)This will return the FactPattern that a variable is bound Eto.List<String>getLHSBoundFacts()This will return a Listof all FactPattern bindings SingleFieldConstraintgetLHSBoundField(String var)This will return the FieldConstraint that a variable is bound to.FactPatterngetLHSParentFactPatternForBinding(String var)This will return the FactPattern that a variable is bound to.List<String>getLHSPatternVariables()This will get a list of all LHS bound variables, excluding bound fieldsList<String>getLHSVariables(boolean includePatterns, boolean includeFields)RuleMetadatagetMetaData(String attributeName)Locate metadata elementStringgetPackageName()ActionInsertFactgetRHSBoundFact(String var)This will return the ActionInsertFact that a variable is bound to.List<String>getRHSBoundFacts()This will return a Listof all ActionInsertFact bindings booleanhasDSLSentences()Returns true if any DSLSentences are used.inthashCode()booleanisBoundFactUsed(String binding)booleanisNegated()Is the Rule to be negated, i.e.booleanisVariableNameUsed(String s)Checks to see if a variable is used or not, includes fields as well as facts.voidmoveLhsItemDown(int itemIndex)voidmoveLhsItemUp(int itemIndex)voidmoveRhsItemDown(int itemIndex)voidmoveRhsItemUp(int itemIndex)voidremoveAttribute(int idx)booleanremoveLhsItem(int idx)voidremoveMetadata(int idx)voidremoveRhsItem(int idx)voidsetImports(org.kie.soup.project.datamodel.imports.Imports imports)voidsetNegated(boolean isNegated)Set whether the Rule is to be negatedvoidsetPackageName(String packageName)booleanupdateMetadata(RuleMetadata target)Update metaData element if it exists or add it otherwise
-
-
-
Field Detail
-
DEFAULT_TYPE
public static final String DEFAULT_TYPE
- See Also:
- Constant Field Values
-
name
public String name
This name is generally not used - the asset name or the file name is preferred (ie it could get out of sync with the name of the file it is in).
-
parentName
public String parentName
-
modelVersion
public String modelVersion
-
attributes
public RuleAttribute[] attributes
-
metadataList
public RuleMetadata[] metadataList
-
lhs
public IPattern[] lhs
-
rhs
public IAction[] rhs
-
-
Method Detail
-
getLHSBoundFacts
public List<String> getLHSBoundFacts()
This will return a Listof all FactPattern bindings - Returns:
- The bindings or an empty list if no bindings are found.
-
getLHSBoundFact
public FactPattern getLHSBoundFact(String var)
This will return the FactPattern that a variable is bound Eto.- Parameters:
var- The bound fact variable (NOT bound field).- Returns:
- null or the FactPattern found.
-
getLHSBoundField
public SingleFieldConstraint getLHSBoundField(String var)
This will return the FieldConstraint that a variable is bound to.- Parameters:
var- The bound field variable (NOT bound fact).- Returns:
- null or the FieldConstraint found.
-
getLHSBindingType
public String getLHSBindingType(String var)
Get the data-type associated with the binding- Parameters:
var-- Returns:
- The data-type, or null if the binding could not be found
-
getFieldBinding
public String getFieldBinding(FieldConstraint fc, String var)
-
getRHSBoundFacts
public List<String> getRHSBoundFacts()
This will return a Listof all ActionInsertFact bindings - Returns:
- The bindings or an empty list if no bindings are found.
-
getRHSBoundFact
public ActionInsertFact getRHSBoundFact(String var)
This will return the ActionInsertFact that a variable is bound to.- Parameters:
var- The bound fact variable (NOT bound field).- Returns:
- null or the ActionInsertFact found.
-
getLHSParentFactPatternForBinding
public FactPattern getLHSParentFactPatternForBinding(String var)
This will return the FactPattern that a variable is bound to. If the variable is bound to a FieldConstraint the parent FactPattern will be returned.- Parameters:
var- The variable binding- Returns:
- null or the FactPattern found.
-
getAllLHSVariables
public List<String> getAllLHSVariables()
This will get a list of all LHS bound variables, including bound fields..
-
getLHSPatternVariables
public List<String> getLHSPatternVariables()
This will get a list of all LHS bound variables, excluding bound fields
-
getLHSVariables
public List<String> getLHSVariables(boolean includePatterns, boolean includeFields)
-
getAllRHSVariables
public List<String> getAllRHSVariables()
This will get a list of all RHS bound variables.
-
getAllVariables
public List<String> getAllVariables()
This will get a list of all bound variables (LHS and RHS), including bound fields..
-
getFieldBinding
public List<String> getFieldBinding(FieldConstraint f)
-
removeLhsItem
public boolean removeLhsItem(int idx)
- Parameters:
idx- Remove this index from the LHS. returns false if it was NOT allowed to remove this item (ie it is used on the RHS).
-
isBoundFactUsed
public boolean isBoundFactUsed(String binding)
- Parameters:
binding- The name of the LHS fact binding.- Returns:
- Returns true if the specified binding is used on the RHS.
-
addLhsItem
public void addLhsItem(IPattern pat)
-
addLhsItem
public void addLhsItem(IPattern pat, boolean append)
-
addLhsItem
public void addLhsItem(IPattern pat, int position)
-
moveLhsItemDown
public void moveLhsItemDown(int itemIndex)
-
moveLhsItemUp
public void moveLhsItemUp(int itemIndex)
-
moveRhsItemDown
public void moveRhsItemDown(int itemIndex)
-
moveRhsItemUp
public void moveRhsItemUp(int itemIndex)
-
addRhsItem
public void addRhsItem(IAction action)
-
addRhsItem
public void addRhsItem(IAction action, boolean append)
-
addRhsItem
public void addRhsItem(IAction action, int position)
-
removeRhsItem
public void removeRhsItem(int idx)
-
addAttribute
public void addAttribute(RuleAttribute attribute)
-
removeAttribute
public void removeAttribute(int idx)
-
addMetadata
public void addMetadata(RuleMetadata metadata)
Add metaData- Parameters:
metadata-
-
removeMetadata
public void removeMetadata(int idx)
-
getMetaData
public RuleMetadata getMetaData(String attributeName)
Locate metadata element- Parameters:
attributeName- - value to look for- Returns:
- null if not found
-
updateMetadata
public boolean updateMetadata(RuleMetadata target)
Update metaData element if it exists or add it otherwise- Parameters:
target-- Returns:
- true on update of existing element false on added of element
-
getBoundVariablesInScope
public List<String> getBoundVariablesInScope(BaseSingleFieldConstraint con)
This uses a deceptively simple algorithm to determine what bound variables are in scope for a given constraint (including connectives). Does not take into account globals.
-
isVariableNameUsed
public boolean isVariableNameUsed(String s)
Checks to see if a variable is used or not, includes fields as well as facts.
-
hasDSLSentences
public boolean hasDSLSentences()
Returns true if any DSLSentences are used.
-
isNegated
public boolean isNegated()
Is the Rule to be negated, i.e. "not ( PatternX, PatternY... )"- Returns:
-
setNegated
public void setNegated(boolean isNegated)
Set whether the Rule is to be negated- Parameters:
isNegated-
-
getImports
public org.kie.soup.project.datamodel.imports.Imports getImports()
- Specified by:
getImportsin interfaceorg.kie.soup.project.datamodel.imports.HasImports
-
setImports
public void setImports(org.kie.soup.project.datamodel.imports.Imports imports)
- Specified by:
setImportsin interfaceorg.kie.soup.project.datamodel.imports.HasImports
-
getPackageName
public String getPackageName()
- Specified by:
getPackageNamein interfaceorg.kie.soup.project.datamodel.packages.HasPackageName
-
setPackageName
public void setPackageName(String packageName)
- Specified by:
setPackageNamein interfaceorg.kie.soup.project.datamodel.packages.HasPackageName
-
-