commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: JXPath and LazyDynaBeans
Date Fri, 21 Nov 2008 18:45:31 GMT
On Thu, Nov 20, 2008 at 12:10 AM, Andrew Hughes <ahhughes@gmail.com> wrote:
> 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?

I would have expected the lazy DynaBean to contain a list of Strings -
I would check if it does. If it does then the issue is in JXPath.

Niall

> Also, I would prefer not to have to specify the index 0,1,2 if that is at
> all possible.
>
> Thanks in advance.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message