commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Horman" <>
Subject [jxpath] Selection Handler
Date Tue, 29 Jul 2003 14:40:19 GMT
The built in support for maps, collections and beans in JXPath gets one very far
in the traversal of object graphs. I am interested though in custom traversals.
An example would be traversal of a RDBMS database. For example, I would like the


To translate into:

emps = getCompany().getEmployees()
rows ="select fname from employees where id = 10")
for (row in rows) {
    // collect results

Where employees is obviously some custom db wrapper.

I looked through the reference implementation and I don't see an easy way to
accomplish this. Creating my own NodePointer factory, and NodePointer classes
only allow me to handle the current context, or simple iteration from the
current context. They don't allow me to take over the rest of the xpath
expression, or even access the xpath expression, from a certain point.

What would be very cool is if I could just have one of my objects implement a
simple interface that tells JXPath that I will handle the rest of the path or
certain pieces of the path. Example:

// psuedocode
class MyClass implements JXPathContextHandler {
    public Object, Expression getValue(Object parent, Expression expression) {
        // handle the path request

        // this would be here "here is the object found, and i finished
        // the path traversal"
        return [foundObject, null]

        // this would be "here is the object found, and i finished paths
        // 0 and 1, continue the expression from there"
        return [foundObject, expression[2:]]

The other context methods, iterate, remove, setValue would also be part of the
JXPathContextHandler interface. It seems like this might be a simple way to
extend JXPath beyond its current support for Collections and Maps.

It does look like the Container interface could be a decent place to add this

If there is already an existing way of providing this functionality, short of
rewriting the ReferenceImpl, please let me know.

-jason horman

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message