MVEL
| Company type | Software project |
|---|---|
| Industry | Software development |
MVFLEX Expression Language (MVEL) is an embeddable Expression Language and runtime environment for the Java Platform, combining dynamic and static typing features. Originally created as a utility scripting language for a specific application framework, MVEL has since evolved into a standalone project with independent maintenance.
Typically, MVEL is utilized to provide configurable logic access to both developers and end-users through configuration mechanisms like XML files or annotations. It also facilitates the evaluation of straightforward JavaBean expressions.
At runtime, MVEL offers flexibility by allowing expressions to be executed either interpretively or through just-in-time compilation into bytecode, which enhances performance by minimizing execution overhead.
MVEL’s syntax is designed to align closely with Java, making it intuitive for Java developers while introducing additional capabilities. For example, its type system permits class and method references to behave as variables, supporting the use of class pointers and static function references.
<syntaxhighlight lang="java"> millis = System.currentTimeMillis;
// Retrieve current milliseconds time = millis(); </syntaxhighlight>
Additionally, MVEL enables collection processing using a projection syntax reminiscent of Lisp's fold operations.
<syntaxhighlight lang="groovy"> namesOfParents = (parent.name in (children in employees)); </syntaxhighlight>
Hello world example
<syntaxhighlight lang="java"> System.out.println("Hello, world!"); </syntaxhighlight>
Although MVEL integrates with Java namespaces and classes, it does not support the creation of new namespaces or class declarations within its environment.
Quicksort example
The script below illustrates MVEL 2.0’s scripting capabilities by implementing the Quicksort sorting algorithm:
<syntaxhighlight lang="groovy"> import java.util.*;
// Quicksort implementation def quicksort(list) {
if (list.size() <= 1) {
list;
} else {
pivot = list[0];
concat(quicksort(($ in list if $ < pivot)), pivot, quicksort(($ in list if $ > pivot)));
}
}
// Method to concatenate lists def concat(list1, pivot, list2) {
concatList = new ArrayList(list1); concatList.add(pivot); concatList.addAll(list2); concatList;
}
// List to be sorted list = [5,2,4,1,18,10,15,1,0];
// Execute sorting quicksort(list); </syntaxhighlight>