commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Raess <>
Subject [jxpath] Custom NodePointer implementation
Date Thu, 17 Jun 2004 21:32:01 GMT

I hope to get some ideas how to implement the following:

Let's say I have a class Foo that can contain several Bar instances. 
The Bar instances are accessed by a key, let's say a Language object. 
So I have the following methods in Foo:

public Bar getBar(Language l);
public Set getLanguages();

In the model of my application I don't want to have an absolute 
ordering of Bar objects, that is I don't want to expose a method like

public Bar getBar(int index);

or similar. My idea is to have an external object impose an ordering on 
the Bar objects (that is an ordering on languages). The point is, that 
the ordering may change at runtime. What that basically means is, that 
I'll have a mapping from a int key to a Language. For example the 
mapping would contain:

Language   int key
de         0
fr         1
en         2

So my idea is to create a custom NodePointer that receives such a 
mapping definition (so it knows about the ordering of languages). The 
following xpath expression (with the above mapping definition) should 
return the text with language fr:


This should be translated (by the custom NodePointer) to a call to:

int index = ...;
Foo foo = ...;
List mapping = ...;
Language lang = (Language)mapping.get(index);
Bar fr_bar = foo.getBar(lang);

The following xpath


should probably be converted to something like

List list = foo.getBar();

I'm still unconfident about the jxpath internals, so could please 
somebody give me some pointers how I could achieve that? I'm I on the 
right tracks? Which methods from NodePointer class must I override 
(except the abstract ones, of course)? Is there a simple example that 
shows how to implement a NodePointer for objects without using any 
reflection, introspection, ...? Is there anything else I should 
consider? Please ask me if I missed some important information!

best regards

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

View raw message