[Rails] REST API's and querying a graph of objects

Thibaut Barrère thibaut.barrere at gmail.com
Fri Jan 20 23:30:52 GMT 2006


> Any Java projects doing this that spring to mind?

Hi Mike

I've been using JXPath ( http://jakarta.apache.org/commons/jxpath/ ) for
that purpose two years ago.

--Thibaut

=====================

The org.apache.commons.jxpath package defines a simple interpreter of an
expression language called XPath. JXPath applies *XPath* expressions to
graphs of objects of all kinds: JavaBeans, Maps, Servlet contexts, DOM etc,
including mixtures thereof.

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;
    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060120/6bd391c0/attachment.html


More information about the Rails mailing list