MVEL
Encyclopedia
MVFLEX Expression Language (MVEL) is a hybrid dynamic/statically typed, embeddable Expression Language
Expression Language
Expression Language is a scripting language which allows access to Java components through JSP. Since JSP 2.0, it has been used inside JSP tags to separate Java code from JSP, and to allow easier access to Java components ....

 and runtime
Run-time system
A run-time system is a software component designed to support the execution of computer programs written in some computer language...

 for the Java Platform. Originally started as a utility language for an application framework, the project is now developed completely independently.

MVEL is typically used for exposing basic logic to end-users and programmers through configuration such as XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 files or annotations. It may also be used to parse simple JavaBean expressions.

The runtime allows MVEL expressions to be executed either interpretively, or through a pre-compilation process with support for runtime bytecode
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

 generation to remove overhead.

Since MVEL is meant to augment Java-based software, it borrows most of its syntax directly from the Java programming language with some minor differences and additional capabilities. For example: as a side effect of MVEL's typing model, which treats class and method references as regular variables, it is possible to use both class and function pointers (but only for static methods).


millis = System.currentTimeMillis;

// get millis
time = millis;


MVEL also allows collections to be represented as folds (or projections) in a Lisp-like syntax.


namesOfParents = (parent.name in (children in employees));

Hello world example


System.out.println("Hello, world!");


MVEL relies on Java namespaces and classes, but does not possess the ability to declare namespaces or classes.

Quicksort Example

Here is an example of the Quicksort algorithm implemented in MVEL 2.0, demonstrating the scripting capabilities of the language.


import java.util.*;

// the main quicksort algorithm
def quicksort(list) {
if (list.size <= 1) {
list;
}
else {
pivot = list[0];
concat(quicksort(($ in list if $ < pivot)), pivot, quicksort(($ in list if $ > pivot)));
}
}

// define method to concatenate lists.
def concat(list1, pivot, list2) {
concatList = new ArrayList(list1);
concatList.add(pivot);
concatList.addAll(list2);
concatList;
}

// create a list to sort
list = [5,2,4,1,18,10,15,1,0];

// sort it!
quicksort(list);

See also

  • Java
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

  • OGNL
    OGNL
    Object-Graph Navigation Language , created by OGNL Technology, is an open-source Expression Language for Java, which, while using simpler expressions than the full range of those supported by the Java language, allows getting and setting properties , and execution of methods of Java classes...

  • Expression Language
    Expression Language
    Expression Language is a scripting language which allows access to Java components through JSP. Since JSP 2.0, it has been used inside JSP tags to separate Java code from JSP, and to allow easier access to Java components ....


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK