Ada EL - The JSR-245 Unified Expression Language for Ada

By Stephane Carrez

Ada EL is a library that implements an expression language similar to JSP and JSF Unified Expression Languages (EL). EL is used to give access to Java bean components within a presentation page (JSP, XHTML). For JSF the expression language creates a bi-directional binding where the value can be obtained when displaying a page but also modified (after a POST). The Unified Expression Language is a component of the JavaServer Pages specification described in JSR-245.

The Ada EL is a library that implements the expression language and provides an Ada binding to use it. The example below shows a code extract to bind an Ada record Joe to the name user and evaluate the above expression.

Ctx    : EL.Contexts.Default.Default_Context;
E      : EL.Expressions.Expression;
Result : EL.Objects.Object;
E := Create_Expression("${user.firstName}",Ctx);
--  Bind the context to 'Joe' and evaluate
Ctx.Set_Variable ("user", Joe);
Result := E.Get_Value (Ctx);

Using Ada EL is fairly simple, see below.

Expression Context

The expression context defines the context for parsing and evaluating the expression. In short the expression context provides:

  • the definitions and access to functions,
  • the access to variables

The expression context is represented by the EL.Contexts.Context interface.

A default context implementation is provided and can be used as follows:

with EL.Contexts.Default;
   Ctx : EL.Contexts.Default.Default_Context;

Creating an expression

The expression must be parsed using Create_Expression and it is represented by an Expression object.

with EL.Expressions;

   E : EL.Expressions.Expression := 
Create_Expression("${user.firstName}", Ctx);

When parsing an expression, the context is used to resolve the functions used by the expression.

Evaluating an expression

Once parsed, the expression can be evaluated several times and on different expression contexts. The evaluation is done by invoking the Get_Value method which returns an EL.Objects.Object object. The Object record will contain the result either as a boolean, an integer, a floating point number, a string or something else.

with EL.Objects;

   Result : EL.Objects.Object := E.Get_Value (Ctx);

To access the value, several To_type functions are provided.

   Ada.Text_IO.Put_Line ("Result: "
        & EL.Objects.To_String (Result));

Learn More

Ada-El is a project hosted by Code Google under the name ada-el, you can get the sources which are distributed under the Apache License 2.0.

To learn more about Ada EL, read the Introduction page.

Add a comment

To add a comment, you must be connected. Login