March 12, 2003

JXPath and TMTOWDTI

Commons JXPath - The announcement on TSS is the first I’ve heard of this. It’s kind of like the JSTL EL but in code. From one of their examples, this JXPath expression:

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

is equivalent to this 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;
    }
}

Very perlish, don't you think?

It's interesting how a number of the Jakarta Commons projects are implementing these sorts of shortcuts to make verbose Java more succinct -- some of the classes in the Commons Collections package library are trying to fold functional idioms (like map) into Java, which is most welcome.

Next: Free worship
Previous: Car troubles update