Class MVELRule

  • All Implemented Interfaces:
    java.lang.Comparable<Rule>, Rule

    public class MVELRule
    extends BasicRule
    A Rule implementation that uses MVEL to evaluate and execute the rule.
    • Constructor Detail

      • MVELRule

        public MVELRule()
        Create a new MVEL rule.
      • MVELRule

        public MVELRule​(org.mvel2.ParserContext parserContext)
        Create a new MVEL rule.
        Parameters:
        parserContext - used to parse condition/action expressions
    • Method Detail

      • description

        public MVELRule description​(java.lang.String description)
        Set rule description.
        Parameters:
        description - of the rule
        Returns:
        this rule
      • evaluate

        public boolean evaluate​(Facts facts)
        Description copied from class: BasicRule
        This method implements the rule's condition(s). Implementations should handle any runtime exception and return true/false accordingly
        Specified by:
        evaluate in interface Rule
        Overrides:
        evaluate in class BasicRule
        Returns:
        true if the rule should be applied given the provided facts, false otherwise
      • execute

        public void execute​(Facts facts)
                     throws java.lang.Exception
        Description copied from class: BasicRule
        This method implements the rule's action(s).
        Specified by:
        execute in interface Rule
        Overrides:
        execute in class BasicRule
        Throws:
        java.lang.Exception - thrown if an exception occurs when performing action(s)
      • name

        public MVELRule name​(java.lang.String name)
        Set rule name.
        Parameters:
        name - of the rule
        Returns:
        this rule
      • priority

        public MVELRule priority​(int priority)
        Set rule priority.
        Parameters:
        priority - of the rule
        Returns:
        this rule
      • then

        public MVELRule then​(java.lang.String action)
        Add an action specified as an MVEL expression to the rule.
        Parameters:
        action - to add to the rule
        Returns:
        this rule
      • when

        public MVELRule when​(java.lang.String condition)
        Specify the rule's condition as MVEL expression.
        Parameters:
        condition - of the rule
        Returns:
        this rule