Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 088256F00 for ; Mon, 16 May 2011 19:38:54 +0000 (UTC) Received: (qmail 86104 invoked by uid 500); 16 May 2011 19:38:52 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 86031 invoked by uid 500); 16 May 2011 19:38:52 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 86020 invoked by uid 99); 16 May 2011 19:38:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 May 2011 19:38:52 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gudnabrsam@gmail.com designates 74.125.83.43 as permitted sender) Received: from [74.125.83.43] (HELO mail-gw0-f43.google.com) (74.125.83.43) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 May 2011 19:38:47 +0000 Received: by gwj21 with SMTP id 21so1835377gwj.30 for ; Mon, 16 May 2011 12:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=eYx6A4fJg9CpuOhVL44rEHrZYLVtif3miAPcgnMsKvY=; b=cFKojHtu0hFn2SJQbS90HML5NR291YlGrn0y2qRYTWK6Zt+STevQfFxQePqBgXSlX7 jyTHGBiy0L1xTfdtUau4lyfagU/6qAzdjsYOkc3kHafBqUDt/XXTJj8IHu7+ENdc62yZ rFXskVP1FWoeMlTOvhSNaGbRXEipbfQM/bWxM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; b=uz+JrYVCMG0xVLOaxsgyxSc0Vm1bWuPkdlexzH39lm+ir1yfgTRTJuDSs3fi7tNMgq BBtShNcqTjboDtLmXa/jBFMMptRMtXYHqihg+PhdDS6ig8ITbrYqKuJwoR3LX913CTH5 2Cdniy0kQDh9y3wOZqcUIVZEo/m9PY7rJoA6A= MIME-Version: 1.0 Received: by 10.236.178.98 with SMTP id e62mr1080392yhm.319.1305574706884; Mon, 16 May 2011 12:38:26 -0700 (PDT) Received: by 10.146.82.1 with HTTP; Mon, 16 May 2011 12:38:26 -0700 (PDT) Reply-To: gudnabrsam@gmail.com In-Reply-To: <4B357BC0-F268-4F96-8D46-40A51953CFC6@lifl.fr> References: <4B357BC0-F268-4F96-8D46-40A51953CFC6@lifl.fr> Date: Mon, 16 May 2011 14:38:26 -0500 Message-ID: Subject: Re: [jxpath] Navigating across Lists From: Matt Benson To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, May 16, 2011 at 2:16 PM, Romain Rouvoy wrot= e: > On 16 mai 2011, at 16:06, Matt Benson wrote: >> On Mon, May 16, 2011 at 4:51 AM, Romain Rouvoy w= rote: >>> I'm using JXPath to query a graph of beans, which are heavily using lis= ts, e.g.: >>>> public class A { >>>> =A0 =A0 =A0 List getB() {...} >>>> } >>>> >>>> public class B { >>>> =A0 =A0 =A0 String getName() {...} >>>> =A0 =A0 =A0 List getC() {...} >>>> } >>>> >>>> public class C { >>>> =A0 =A0 =A0 String getName() {...} >>>> } >>> >>> However, when I'm querying this graph of beans, the following request d= oes not match any elements (while it should return several elements): >>>> org.apache.commons.jxpath.JXPathContext.newContext(new A()); >>>> context.getValue("b[@name=3D'foo']/c/name"); >>> Any idea? Does JXPath support navigation within lists? >> What should happen is that getValue(expr) returns the first value specif= ied by your expression, while iterate(expr) would be the way you would retr= ieve multiple results. =A0If 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 { >> =A0 =A0 @BeanProperty val b =3D List[B](new B("FOOs"), new B("BARs")) >> } > > The annotation @BeanProperty is used to generate getters at compile-time. > > >> scala> val context =3D org.apache.commons.jxpath.JXPathContext.newContex= t(a) >> context: org.apache.commons.jxpath.JXPathContext =3D org.apache.commons.= jxpath.ri.JXPathContextReferenceImpl@132bb617 >> >> scala> context.getValue("b") >> res27: java.lang.Object =3D 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 >> =A0 =A0 =A0 at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.g= etValue(JXPathContextReferenceImpl.java:383) >> =A0 =A0 =A0 at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.g= etValue(JXPathContextReferenceImpl.java:313) >> =A0 =A0 =A0 at .(:29) >> =A0 =A0 =A0 at .() >> =A0 =A0 =A0 at RequestResult$.(:9) >> =A0 =A0 =A0 at RequestResult$.() >> =A0 =A0 =A0 at RequestResult$scala_repl_result() >> =A0 =A0 =A0 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Metho= d) >> =A0 =A0 =A0 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodA= ccessorImpl.java:39) >> =A0 =A0 =A0 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Delegatin= gMethodAccessorImpl.java:25) >> =A0 =A0 =A0 at java.lang.reflect.Method.invoke(Method.java:597) >> =A0 =A0 =A0 at scala.tools.nsc.Interpreter$Request$$a... > > According to your answer, I should get a String ("FOOs") and not an excep= tion... > Ideally, I would have expected a collection of String containing "FOOs" a= nd "BARs"... :) > > >> scala> val i =3D context.iterate("b/name") >> i: java.util.Iterator[_] =3D org.apache.commons.jxpath.ri.compiler.Expre= ssion$ValueIterator@3b29642c >> >> scala> i.hasNext >> res30: Boolean =3D 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. Matt > Romain > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org