Skip to content.

Manageability

Sections
Personal tools
You are here: Home » blog » archive » The Proliferation of Expression Languages
Views
  • State: published

The Proliferation of Expression Languages

Document Actions
20020924223750

Looks like there's a proliferation of Expression Languages (i.e. EL) in the Java world. An EL (according to me) is a mini language that helps express navigation through an object graph. So this doesn't include regex's which navigate strings and xpath which navigate XML. For starters there's JSTL and there's Jexl which adds a few more conveniences like support for invocation of methods. Why this isn't included in JSTL is beyond me!. There is Webwork EL which does supports method invocation, furthermore it's got an eval() like capability which can prove to be pretty useful.

There's Joda which leverages Jaxen and JXPath, both are languages based on XPath. XPath based EL's are more expressive and powerful than the JSTL variants. With XPath based languages you don't have to specify the exact path to an object, you can choose to ignore objects in the path. There's also OGNL supports a variant of lamda functions, although I don't think it's as powerfull as the XPath based ones.

Just to get you a feel of why EL's are useful, here's some motivation from the JXPath intro.
Consider this example:

Address address = (Address)JXPathContext.newContext(vendor).
         getValue("locations[address/zipCode='90210']/address");

This XPath expression is equvalent to the following Java code:

Address address = null;
Collection locations = vendor.getLocations();
Iterator it = locations.iterator();
while (it.hasNext()){
    Location location = (Location)it.next();
    String zipCode = location.getAddress().getZipCode();
    if (zipCode.equals("90210")){
      address = location.getAddress();
      break;
    }
}

Stuff like this makes C# foreach construct look downright primitive!

The term "Expression Language" may have been coined since the language only allows for single expression as opposed to groups of expressions sometimes known as statements. To make it clearer lets look at the Java Grammar. Statements are blocks, if-then-else, while, for, switch, do, throws, try, assignment and a couple more. If you look at section 19.12 for Expression, you find the usual infix based expressions and the field access, method invocation and array access expression.


Last modified 2003-07-30 04:16 PM
 

Powered by Plone

This site conforms to the following standards: