On Mon, May 16, 2011 at 3:01 PM, Romain Rouvoy <[email protected]> wrote:
> On 16 mai 2011, at 21:38, Matt Benson wrote:
>> On Mon, May 16, 2011 at 2:16 PM, Romain Rouvoy <[email protected]> wrote:
>>> On 16 mai 2011, at 16:06, Matt Benson wrote:
>>>> On Mon, May 16, 2011 at 4:51 AM, Romain Rouvoy <[email protected]> 
>>>> wrote:
>>>>> I'm using JXPath to query a graph of beans, which are heavily using 
>>>>> lists, e.g.:
>>>>>> public class A {
>>>>>>       List<B> getB() {...}
>>>>>> }
>>>>>>
>>>>>> public class B {
>>>>>>       String getName() {...}
>>>>>>       List<C> getC() {...}
>>>>>> }
>>>>>>
>>>>>> public class C {
>>>>>>       String getName() {...}
>>>>>> }
>>>>>
>>>>> However, when I'm querying this graph of beans, the following request 
>>>>> does not match any elements (while it should return several elements):
>>>>>> org.apache.commons.jxpath.JXPathContext.newContext(new A());
>>>>>> context.getValue("b[@name='foo']/c/name");
>>>>> Any idea? Does JXPath support navigation within lists?
>>>> What should happen is that getValue(expr) returns the first value 
>>>> specified by your expression, while iterate(expr) would be the way you 
>>>> would retrieve multiple results.  If you can distill your problem down to 
>>>> a failing JUnit test, please feel free to attach this to a JIRA issue.
>>>
>>> Thanks Matt, actually I use Scala to develop my application:
>>>> import scala.reflect.BeanProperty
>>>>
>>>> case class B(@BeanProperty val name:String)
>>>>
>>>> object a {
>>>>     @BeanProperty val b = List[B](new B("FOOs"), new B("BARs"))
>>>> }
>>>
>>> The annotation @BeanProperty is used to generate getters at compile-time.
>>>
>>>
>>>> scala> val context = org.apache.commons.jxpath.JXPathContext.newContext(a)
>>>> context: org.apache.commons.jxpath.JXPathContext = 
>>>> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl@132bb617
>>>>
>>>> scala> context.getValue("b")
>>>> res27: java.lang.Object = List(B(FOOs), B(BARs))
>>>
>>> This is an expected behavior...
>>>
>>>
>>>> scala> context.getValue("b/name")
>>>> org.apache.commons.jxpath.JXPathNotFoundException: No value for xpath: 
>>>> b/name
>>>>       at 
>>>> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:383)
>>>>       at 
>>>> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:313)
>>>>       at .<init>(<console>:29)
>>>>       at .<clinit>(<console>)
>>>>       at RequestResult$.<init>(<console>:9)
>>>>       at RequestResult$.<clinit>(<console>)
>>>>       at RequestResult$scala_repl_result(<console>)
>>>>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>       at 
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>       at 
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>       at java.lang.reflect.Method.invoke(Method.java:597)
>>>>       at scala.tools.nsc.Interpreter$Request$$a...
>>>
>>> According to your answer, I should get a String ("FOOs") and not an 
>>> exception...
>>> Ideally, I would have expected a collection of String containing "FOOs" and 
>>> "BARs"... :)
>>>
>>>
>>>> scala> val i = context.iterate("b/name")
>>>> i: java.util.Iterator[_] = 
>>>> org.apache.commons.jxpath.ri.compiler.Expression$ValueIterator@3b29642c
>>>>
>>>> scala> i.hasNext
>>>> res30: Boolean = false
>>>
>>> And even when using the context.iterate method, the returned iterator is 
>>> empty...
>>>
>>> Is that ok if I submit my Scala code except within JIRA?
>>
>> It'd probably be best to first verify whether your example (or something 
>> mostly like it) works in Java before proceeding on to figuring out what, if 
>> anything, fails when doing the same thing in Scala.  I personally don't have 
>> any experience with Scala, although I've been interested to get my feet wet 
>> in that regard.
>
> Well, the equivalent program in Java works perfectly with JXPath... Thus, it 
> sounds like the problems is due to the fact that JXPath cannot navigate 
> through Scala lists (which are not inheriting from the Java collection 
> framework).
> Do you think that such a support for the Scala collection library can be 
> easily integrated within JXPath? I can try to contribute if you help me to 
> get in :)
>

It would be nice if it were possible to make the two work together,
but... is nothing available that can wrap your Scala list for better
Java compatibility?

Matt

> Romain
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to