Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Mvel dialect in Drools?

Tags:

drools

mvel

I am new to Drools. I am creating a rule but I get a compile time error

"field is not visible'.

I've tried to check with Jboss examples, where they use dialect "mvel". It compiled. I didn't understand about dialect. So what is dialect=mvel?

like image 565
tech2504 Avatar asked Jun 23 '13 09:06

tech2504


People also ask

What is DRL file in drools?

DRL (Drools Rule Language) rules are business rules that you define directly in . drl text files. These DRL files are the source in which all other rule assets in Business Central are ultimately rendered.


2 Answers

mvel, or the MVFLEX Expression Language has a rich syntax, many of which allow for more concise and expressive code (and less imperative) than java, e.g.

  • Shorthand for get()ters / set()ters (e.g. encapsulating private fields) to be accessed in an alternative property style syntax (similar to VB or C# properties in .Net)

ie. instead of

myObject.setSomeField("SomeValue");
int x = myObject.getSomeIntField();

You can use the syntax (note the subtle capitalization switch as well):

myObject.someField = "SomeValue"
x = myObject.someIntField // Type inferrence
  • The return statement is optional (a convention found in many functional languages like Scala), as is the semi-colon, unless you have multiple statements per line:

x  // i.e. return x;
  • Shorthand array creation and indexing by ordinal

foos = {2, 4, 6, 8, 10}
foos[3] // foos.get(3)
  • Similarly for Maps (Dictionaries)

bars = ["a" : "Apple", "b" : "Basket"] // Hashmap, with put
bars["a"]
bars.a // Similar to dynamically typed object e.g. in javascript, if key is a string.
  • Null Safe navigation operator (like the null-conditional operator in Rosyln)

foo.?bar.baz // if (foo.bar != null) { return foo.bar.baz; } else { return null; }
like image 98
StuartLC Avatar answered Sep 27 '22 23:09

StuartLC


Based on

Drools JBoss Rules 5.0 Developer's Guide

Dialect is used to specify the syntax in any code expression that is in a condition or consequence. The default value is Java. Drools currently supports one more dialect called mvel.

Specifically mvel is an expression language for Java-based applications. And it's based on Java syntax. more info about mvel

like image 43
gadon Avatar answered Sep 27 '22 23:09

gadon