Drools DRL Syntax - What makes a DRL file - Java @ Desk

Wednesday, April 16, 2014

Drools DRL Syntax - What makes a DRL file

Drools DRL Syntax - What makes a DRL file

A rule file in drools is created with an extension .drl. A DRL file consists of following :
1) package name
2) import
3) globals (if required)
4) functions (if required)
5) rule (one or many)

The ordering is not important in a DRL file. The only thing at first place should be a package name.

A typical rule in a DRL file looks like

rule "<Rule_Name>"
<List_Of_Attributes>
    when
        LHS
    then
        RHS
end


Basics to keep in mind while writing a rule
1) can be written without ""
2) can be none or more
3) LHS can be empty
4) LHS each and every condition must evaluate to a Boolean 5) RHS can be empty

Following is the list of attributes that can be used :
lock-on-active
no-loop
auto-focus
activation-group
agenda-group
ruleflow-group
dialect
salience

Below is the same rule file

package com.sample


// This rule will check the size of an ArrayList Object
rule "Rule Name"
salience 100
    when
        eval(true)
    then
        System.out.println("This is the rule");
end






No comments:

Post a Comment