commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hughes" <ahhug...@gmail.com>
Subject JXPath and LazyDynaBeans
Date Thu, 20 Nov 2008 00:10:18 GMT
Hi All,

There are so many options here, I'm not sure which one is the easiest/best
solution. I've got a data structure which I am using to populate (a
hierarchy of)  LazyDynaBean's so that we can run JXPath across it. It's
working perfectly, until I try and introduce duplicate key entries (i.e. a
node can have >1 children of the same name).

My example heirarchy I wish to build is this...

/
/car='Ferrari'
/car='Porsche'
/car=Lamborghini'


In xml it might look like...

<root>
    <car>Ferrari</car>
    <car>Porsche</car>
    <car>Lamborghini</car>
</root>


Anyway, to cut to the chase. I have multiple 'car' property entries and I am
trying to run the follwing code:

     LazyDynaBean lazyDynaBean = new LazyDynaBean();
     JXPathContext jxPathContext = JXPathContext.newContext(lazyDynaBean);
     lazyDynaBean.set("car",0, "Ferrari");
     lazyDynaBean.set("car",1, "Porsche");
     lazyDynaBean.set("car",2, "Lamborghini");
     Iterator i = jxPathContext.iteratePointers("car");
     while(i.hasNext()){
     System.out.println("Got pointer: "+i.next().toString());
     }


The error is:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at
org.apache.commons.jxpath.ri.model.dynabeans.DynaBeanPropertyPointer.getPropertyNames(DynaBeanPropertyPointer.java:84)
at
org.apache.commons.jxpath.ri.model.beans.PropertyIterator.prepareForIndividualProperty(PropertyIterator.java:270)
at
org.apache.commons.jxpath.ri.model.beans.PropertyIterator.setPositionIndividualProperty(PropertyIterator.java:154)
at
org.apache.commons.jxpath.ri.model.beans.PropertyIterator.setPosition(PropertyIterator.java:139)
at
org.apache.commons.jxpath.ri.axes.ChildContext.setPosition(ChildContext.java:101)
at
org.apache.commons.jxpath.ri.axes.ChildContext.nextNode(ChildContext.java:87)
at
org.apache.commons.jxpath.ri.EvalContext.performIteratorStep(EvalContext.java:155)
at org.apache.commons.jxpath.ri.EvalContext.hasNext(EvalContext.java:115)
at rnd.JXPathRND.App.main(App.java:24)


How am I supposed to populate the DynaBean so that it can contain more than
one 'car' property?
Also, I would prefer not to have to specify the index 0,1,2 if that is at
all possible.

Thanks in advance.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message