Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 7093 invoked from network); 23 Feb 2009 20:49:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Feb 2009 20:49:50 -0000 Received: (qmail 67332 invoked by uid 500); 23 Feb 2009 20:49:46 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 67287 invoked by uid 500); 23 Feb 2009 20:49:46 -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 67275 invoked by uid 99); 23 Feb 2009 20:49:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 12:49:46 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [206.190.58.151] (HELO web55102.mail.re4.yahoo.com) (206.190.58.151) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 23 Feb 2009 20:49:37 +0000 Received: (qmail 27282 invoked by uid 60001); 23 Feb 2009 20:49:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1235422153; bh=rjjBa3v3s1AkTpUcHoU9Vz+L4diu29X+cP26ZZKIDv8=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=HKBI0kdfU92il9SyfcCkJTmXVov3Odb+srjQPJHD5y9HLn2KZEkxVaaso7+N2DlToc5F5MQISHpcifMS1n15i1rx+g9oLFXvieS4tz62/q4GccfomCXlyJvfTCc6J7Nl5jrqEiiPlW+w4UPJGunn4t6LGmSVYFGQmlo0SMUfof8= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=cWxA1kd7FDl7Xs6pM+ecBPacSLkvKeFrNKdzxbmfiDU8hpixWK0LkeBHhpzXUbEI2tsiUkTFFm+DI+boTPPicr2NF5yR1XGedCo1imNPZhEiorpn0blqI1LlbD2AthU1PVfUZv6Hcf1Bi3o1cAk1gAAWD+eS0nmKIxy4446FEiY=; Message-ID: <711054.26019.qm@web55102.mail.re4.yahoo.com> X-YMail-OSG: baXTM0sVM1khWsAd_Z0gWQwDdmWHfQZkAf2G5Tupy9iTbkLu4r2XIomCYIAGlforOnXbRwt2aqeq3MTYIF8IkNYR3ESLCHgVQnHbIGwQbvkuEA6zWHJ44br8EUSOqjXuKmIZbajnzDhxPy0QhCuMbqEXH_VIXfvI2ZVI5kacNWbEWe4BABo2ZZ7BOREfjBRqX4h1XQWKf_GWnQqZb_qUNzcqECOu5fSymDzykA-- Received: from [67.142.130.26] by web55102.mail.re4.yahoo.com via HTTP; Mon, 23 Feb 2009 12:49:13 PST X-Mailer: YahooMailClassic/5.1.18 YahooMailWebService/0.7.289.1 Date: Mon, 23 Feb 2009 12:49:13 -0800 (PST) From: Matt Benson Subject: Re: JXPath over Generic Collection, How? To: Commons Users List MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Andrew: I still don't have tons of time, but I did use your original code to see = what I could see to start with. Firstly, you blow away TIGER-TWO in your e= xample code by repeating index 1 when you set TIGER-THREE. Next, for some = reason the [@name=3D'foo'] syntax isn't working, but [name=3D'foo'] is work= ing for me. I will try to make some time to research the combination of at= tributes and dynabeans to see if I can tell you why it shouldn't work, or f= ix it if it turns out that it should in fact work. HTH, Matt --- On Mon, 2/23/09, Matt Benson wrote: > From: Matt Benson > Subject: Re: JXPath over Generic Collection, How? > To: "Commons Users List" > Date: Monday, February 23, 2009, 12:27 PM >=20 > Andrew, > =A0 I've been meaning to look into this but haven't > yet.=A0 If you have any ready-to-run code you can send to > the list, that wouldn't hurt... >=20 > -Matt >=20 > --- On Mon, 2/23/09, Andrew Hughes > wrote: >=20 > > From: Andrew Hughes > > Subject: Re: JXPath over Generic Collection, > How? > > To: "Commons Users List" > > Date: Monday, February 23, 2009, 5:42 AM > > OK, email #19 to the list. I'm both > > incredibly patient and skeptical that > > this will ever work. I might try and run this in a > debugger > > and track down > > "how" JXPath traverses the DynaBean.... but given the > > reflection involved > > that might be a painful task. > > --AH > >=20 > >=20 > > On Tue, Feb 17, 2009 at 1:11 PM, Andrew Hughes > > wrote: > >=20 > > > Ping... if anyone can help with this JXPath > & > > DynaBeans problem I'd be > > > REALLY THANKFUL :) > > > > > > > > > On Fri, Feb 13, 2009 at 1:55 PM, Andrew Hughes > > > wrote: > > > > > >> Howdy, > > >> I've taken Matt's suggestion onboard and I > have > > investigated DynaBeans. > > >> These look pretty good for all intestive > purposes > > and there's a code > > >> examples below how to build the data > structure: > > >> > > >> + root [@name=3D"ROOT"] > > >>=A0 =A0=A0=A0+ animal [@name=3D"ANIMAL"] > > >>=A0 =A0 =A0 =A0=A0=A0+ dog > > [@name=3D"DOG"] > > >>=A0 =A0 =A0 =A0 =A0 > > =A0=A0=A0+ boxer [@name=3D"BOXER"] > > >>=A0 =A0 =A0 =A0 =A0 > > =A0=A0=A0+ labrador [@name=3D"LABRADOR"] > > >>=A0 =A0 =A0 =A0=A0=A0+ cat > > [@name=3D"CAT"] > > >>=A0 =A0 =A0 =A0 =A0 > > =A0=A0=A0+ tiger [@name=3D"TIGER-ONE"] > > >>=A0 =A0 =A0 =A0 =A0 > > =A0=A0=A0+ tiger [@name=3D"TIGER-TWO"] > > >>=A0 =A0 =A0 =A0 =A0 > > =A0=A0=A0+ tiger [@name=3D"TIGER-THREE"] > > >>=A0 =A0 =A0 =A0 =A0 > > =A0=A0=A0+ lion [@name=3D"LION"] > > >> > > >> > > >> And the code looks like... > > >> > > >>=A0 LazyDynaBean lazyDynaBean =3D new > > LazyDynaBean(); //the transparent root. > > >>=A0 LazyDynaBean root =3D new LazyDynaBean(); > > >> LazyDynaBean animal =3D new LazyDynaBean(); > > >>=A0 LazyDynaBean dog =3D new LazyDynaBean(); > > >> LazyDynaBean cat =3D new LazyDynaBean(); > > >>=A0 LazyDynaBean boxer =3D new LazyDynaBean(); > > >> LazyDynaBean labrador =3D new LazyDynaBean(); > > >>=A0 LazyDynaBean tiger1 =3D new LazyDynaBean(); > > >> LazyDynaBean tiger2 =3D new LazyDynaBean(); > > >>=A0 LazyDynaBean tiger3 =3D new LazyDynaBean(); > > >> LazyDynaBean lion =3D new LazyDynaBean(); > > >>=A0 //set the @name property of each bean, > user > > UPPER to make them distinct > > >> for examples. > > >> root.set("name","ROOT"); > > >>=A0 animal.set("name","ANIMAL"); > > >> dog.set("name","DOG"); > > >>=A0 cat.set("name","CAT"); > > >> boxer.set("name","BOXER"); > > >>=A0 labrador.set("name","LABRADOR"); > > >> tiger1.set("name","TIGER-ONE"); > > >>=A0 tiger2.set("name","TIGER-TWO"); > > >> tiger3.set("name","TIGER-THREE"); > > >>=A0 lion.set("name","LION"); > > >> //build the bean hierarchy. > > >>=A0 lazyDynaBean.set("root",0, root); > > >> root.set("animal",0, animal); > > >>=A0 animal.set("dog",0,dog); > > >> animal.set("cat",0,cat); > > >> dog.set("labrador",0,labrador); > > >>=A0 dog.set("boxer",0, boxer); > > >> cat.set("tiger",0,tiger1);//duplicate > > >>=A0 cat.set("tiger",1,tiger2);//duplicate > > >> cat.set("tiger",1,tiger3);//duplicate > > >>=A0 cat.set("lion",0,lion); > > >>=A0 =A0 =A0 > > =A0=A0=A0JXPathContext context =3D > > JXPathContext.newContext(lazyDynaBean); > > >>=A0 =A0 =A0 =A0=A0=A0String query > > =3D "/root/animal/cat/tiger"; > > >>=A0 =A0 =A0 =A0=A0=A0Object value > > =3D context.getValue(query); > > >> > > >> > > >> But there's a problem with JXPath querying > this > > also. Absolute Paths like > > >>=A0 '/root/animal/cat/tiger' or > > '/root/animal/cat/tiger'[2]' work perfectly. > > >> But I don't have anyluck doing "deep" > searches. > > For examples the following > > >> just won't work. > > >> '//cat' > > >> //*[@name=3D'LION'] > > >> /root/animal/cat/tiger[@name=3D'TIGER-TWO'] > > >> > > >> Things are looking up, but is this behavior > to be > > expected? > > >> > > >>=A0 Cheers, > > >> --AH > > >> > > >> > > >> On Thu, Feb 12, 2009 at 6:43 AM, Matt Benson > > wrote: > > >> > > >>> > > >>> > > >>> > > >>> > > >>> --- On Wed, 2/11/09, Andrew Hughes > > wrote: > > >>> > > >>> > From: Andrew Hughes > > >>> > Subject: Re: JXPath over Generic > > Collection, How? > > >>> > To: "Commons Users List" > > >>> > Date: Wednesday, February 11, 2009, > 4:19 > > AM > > >>> > Still No Luck, I have removed > recursive > > generic collections > > >>> > and have tried > > >>> > the following code... this is > becoming a > > marathon effort > > >>> > :'( > > >>> > > > >>> > public class Thing { > > >>> > > > >>> >=A0 =A0=A0=A0public > > Thing(String name) { > > >>> >=A0 =A0 =A0 > > =A0=A0=A0this.name =3D name; > > >>> >=A0 =A0=A0=A0} > > >>> >=A0 =A0=A0=A0private String > > name =3D ""; > > >>> > > > >>> >=A0 =A0=A0=A0public String > > getName() { > > >>> >=A0 =A0 =A0 > > =A0=A0=A0return name; > > >>> >=A0 =A0=A0=A0} > > >>> >=A0 =A0=A0=A0private > > ArrayList children =3D new > > >>> > ArrayList(); > > >>> > > > >>> >=A0 =A0=A0=A0public > > ArrayList getChildren() { > > >>> >=A0 =A0 =A0 > > =A0=A0=A0return children; > > >>> >=A0 =A0=A0=A0} > > >>> > > > >>> > } > > >>> > > > >>> > > > >>> >=A0 =A0=A0=A0public static > > void main(String[] args) { > > >>> >=A0 =A0 =A0 > > =A0=A0=A0//get some same data > > >>> >=A0 =A0 =A0 > > =A0=A0=A0Thing animal =3D new Thing("Animal"); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0//Animal.Dog.* > > >>> >=A0 =A0 =A0 > > =A0=A0=A0Thing dog =3D new Thing("Dog"); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0dog.getChildren().add(new > > >>> > Thing("Labrador")); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0dog.getChildren().add(new > > >>> > Thing("Boxer")); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0animal.getChildren().add(dog); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0//Animal.Cat.* > > >>> >=A0 =A0 =A0 > > =A0=A0=A0Thing cat =3D new Thing("Cat"); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0cat.getChildren().add(new Thing("Lion")); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0cat.getChildren().add(new > > >>> > Thing("Tiger")); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0animal.getChildren().add(cat); > > >>> > > > >>> >=A0 =A0 =A0 > > =A0=A0=A0//run a query on it > > >>> >=A0 =A0 =A0 > > =A0=A0=A0JXPathContext context =3D > > >>> > JXPathContext.newContext(animal); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0String query =3D "/Animal"; > > >>> >=A0 =A0 =A0 > > =A0=A0=A0Thing result =3D (Thing) > > context.getValue(query); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0String path =3D > > context.getPointer(query).asPath(); > > >>> >=A0 =A0 =A0 > > =A0=A0=A0System.out.println("Ran '" + query + > > >>> > "' and got '" + > > >>> > result.getName() + "' on path '" + > path > > + > > >>> > "'."); > > >>> >=A0 =A0=A0=A0} > > >>> > > > >>> > > >>> What would you be trying to select?=A0 If > > you want to know how to look for > > >>> a given Thing in this graph, I can > probably > > help.=A0 If you want to know what > > >>> graph will allow you to use a > preconceived > > notion of the xpath you want to > > >>> use, that will be harder.=A0 You might > use > > [beanutils] dynabeans in > > >>> conjunction with [jxpath] to try and > achieve > > the latter. > > >>> > > >>> -Matt > > >>> > > >>> > > > >>> > > > >>> > > > >>> > On Wed, Feb 11, 2009 at 3:08 PM, > Andrew > > Hughes > > >>> > > > wrote: > > >>> > > > >>> > > Yeah, that makes sense. The > part > > that was confusing me > > >>> > is that if I > > >>> > > have... > > >>> > > > > >>> > > public class Thing { > > >>> > > > > >>> > >=A0 =A0 private > > List children; > > >>> > > > > >>> > > } > > >>> > > > > >>> > > I was assuming I would need to > > prefix all of my > > >>> > expressions "steps" with > > >>> > > '/children'. From what you > said > > earlier this > > >>> > is not the case as collections > > >>> > > are "auto traversed/loaded". > > >>> > > > > >>> > > Thanks again matt! I won't get > to > > test this out > > >>> > til later tonight be look > > >>> > > foward to seeing it working!!! > > >>> > > > > >>> > > Andrew > > >>> > > > > >>> > > > > >>> > > On Wed, Feb 11, 2009 at 2:57 > PM, > > Matt Benson > > >>> > > > wrote: > > >>> > > > > >>> > >> > > >>> > >> It should be as simple as > Thing > > _containing_ a > > >>> > List rather than > > >>> > >> _being_ a > > List.=A0 Composition over > > >>> > inheritance, do you see? > > >>> > >> > > >>> > >> HTH, > > >>> > >> Matt > > >>> > >> > > >>> > >> > > >>> > >> --- On Tue, 2/10/09, > Andrew > > Hughes > > >>> > > > wrote: > > >>> > >> > > >>> > >> > From: Andrew Hughes > > >>> > > > >>> > >> > Subject: Re: JXPath > over > > Generic > > >>> > Collection, How? > > >>> > >> > To: "Commons Users > List" > > >>> > , > > >>> > >> gudnabrsam@yahoo.com > > >>> > >> > Date: Tuesday, > February 10, > > 2009, 7:06 PM > > >>> > >> > Matt, Thank You. > > >>> > >> > > > >>> > >> > Is there any other > data > > structure I can use > > >>> > that would work > > >>> > >> > with JXPath? My > > >>> > >> > requirement is that... > a > > "Thing" > > >>> > can have contain > > >>> > >> > multiple child > "Thing(s)" > > >>> > >> > (and the children are > > allowed to be > > >>> > non-unique). > > >>> > >> > This is equivalent to > an > > XML element as it > > >>> > can contain > > >>> > >> > multiple child > > >>> > >> > elements, how do > these > > guy's handle it I > > >>> > wonder? > > >>> > >> > > > >>> > >> > --Andrew > > >>> > >> > > > >>> > >> > > > >>> > >> > On Wed, Feb 11, 2009 > at > > 9:09 AM, Matt Benson > > >>> > >> > > > wrote: > > >>> > >> > > > >>> > >> > > > > >>> > >> > > I admit I hadn't > > looked at this with > > >>> > a highly > > >>> > >> > critical eye, but > this > > >>> > >> > > business of > Thing > > extending > > >>> > ArrayList > > >>> > >> > seems quite strange to > me. > > >>> > >> > >=A0 JXPath > basically > > functions by > > >>> > "opening up" > > >>> > >> > collections > automatically, > > so > > >>> > >> > > the very fact > that > > Thing is itself a > > >>> > Collection > > >>> > >> > implies that a Thing > will > > be > > >>> > >> > > opened up, and > its > > children will be > > >>> > searched... but in > > >>> > >> > this example, either > > >>> > >> > > there are no > children, > > at the leaves, or > > >>> > the children > > >>> > >> > themselves are > > >>> > >> > > (possibly empty) > > collections.=A0 It looks > > >>> > as though > > >>> > >> > you're trying to > represent > > >>> > >> > > a tree > > structure.=A0 This may be a good > > >>> > example of a > > >>> > >> > reason for the idea > of > > >>> > >> > > composition over > > inheritance.=A0 I > > >>> > don't think > > >>> > >> > you're going to get > any > > >>> > >> > > traction using > JXPath > > with this object > > >>> > model. > > >>> > >> > > > > >>> > >> > > Sorry for the > bad > > news, > > >>> > >> > > Matt > > >>> > >> > > > > >>> > >> > > > > >>> > >> > > --- On Tue, > 2/10/09, > > Andrew Hughes > > >>> > >> > > > wrote: > > >>> > >> > > > > >>> > >> > > > From: > Andrew > > Hughes > > >>> > > > >>> > >> > > > Subject: > Re: > > JXPath over Generic > > >>> > >> > Collection, > How? > > >>> > >> > > > To: > "Commons > > Users List" > > >>> > >> > > > >>> > >> > > > Date: > Tuesday, > > February 10, 2009, > > >>> > 7:16 AM > > >>> > >> > > > Still > busted. > > Example is now > > >>> > simplified. As soon > > >>> > >> > as a > > >>> > >> > > > generic > > Collection > > >>> > >> > > > becomes > involved > > BOOM! > > >>> > >> > > > > > >>> > >> > > > The Main > Method > > to exec: > > >>> > >> > > > public class > App > > { > > >>> > >> > > >=A0 > > =A0=A0=A0public static void main( > > >>> > String[] args ){ > > >>> > >> > > >=A0 =A0 > > =A0 =A0=A0=A0JXPathContext context =3D > > >>> > >> > > > > > JXPathContext.newContext(new > > >>> > ThingRoot()); > > >>> > >> > > > > > >>> > >> > > > > > >>> > >> > > > >>> > > > > System.out.println(((Thing)context.getValue("/root")).getName()); > > >>> > >> > > >=A0 > > =A0=A0=A0} > > >>> > >> > > > } > > >>> > >> > > > > > >>> > >> > > > The > (populated) > > context root I am > > >>> > using, where > > >>> > >> > root is a > > >>> > >> > > > single > object > > >>> > >> > > > holding a > List of > > Thing's. > > >>> > >> > > > package > > jxpathresearch; > > >>> > >> > > > > > >>> > >> > > > import > > java.util.ArrayList; > > >>> > >> > > > import > > java.util.List; > > >>> > >> > > > > > >>> > >> > > > public > class > > ThingRoot { > > >>> > >> > > >=A0 > > =A0=A0=A0private List root > > >>> > new > > >>> > >> > ArrayList(); //this > > >>> > >> > > > will serve > as the > > root. > > >>> > >> > > >=A0 > > =A0=A0=A0public ThingRoot() { > > >>> > >> > > >=A0 =A0 > > =A0 =A0=A0=A0Thing animal =3D new > > >>> > >> > Thing("Animal"); > > >>> > >> > > >=A0 =A0 > > =A0 =A0=A0=A0root.add(animal);//Animal > > >>> > >> > > >=A0 =A0 > > =A0 =A0=A0=A0Thing dog =3D new > > >>> > Thing("Dog"); > > >>> > >> > > > > > >>> > animal.add(dog);//Animal.Dog > > >>> > >> > > >=A0 =A0 > > =A0 =A0=A0=A0dog.add(new > > >>> > >> > > > > > >>> > >> > > > >>> > > Thing("Labrador"));//Animal.Dog.Labrador > > >>> > >> > > >=A0 =A0 > > =A0 =A0=A0=A0dog.add(new > > >>> > >> > > > > > >>> > Thing("Boxer"));//Animal.Dog.Boxer > > >>> > >> > > >=A0 > > =A0=A0=A0} > > >>> > >> > > >=A0 > > =A0=A0=A0public List > > >>> > getRoot() { return > > >>> > >> > root; } > > >>> > >> > > > } > > >>> > >> > > > > > >>> > >> > > > Finally > here's a > > very simple > > >>> > 'Thing' > > >>> > >> > that > > >>> > >> > > > contains a > List > > of Thing(s): > > >>> > >> > > > public > class > > Thing extends > > >>> > ArrayList > > >>> > >> > { > > >>> > >> > > >=A0 > > =A0=A0=A0public Thing(String > > >>> > name){this.name =3D name;} > > >>> > >> > > >=A0 > > =A0=A0=A0private String name =3D > > >>> > ""; > > >>> > >> > > >=A0 > > =A0=A0=A0public String getName() {return > > >>> > name;} > > >>> > >> > > > } > > >>> > >> > > > > > >>> > >> > > > I can't > query > > anything beyond > > >>> > /root, it > > >>> > >> > doesn't > > >>> > >> > > > seem to ever > get > > traversed. > > >>> > >> > > > I would > expect > > results for //Thing > > >>> > and > > >>> > >> > > > > > //Thing[@name=3D'Labrador'] > > >>> > etc but I > > >>> > >> > > > get no > results > > only exceptions. > > >>> > >> > > > > > >>> > >> > > > > > >>> > >> > > > My brain is > > hurting. > > >>> > >> > > > > > >>> > >> > > > > > >>> > >> > > > > > >>> > >> > > > On Tue, Feb > 10, > > 2009 at 12:22 AM, > > >>> > Andrew Hughes > > >>> > >> > > > > > wrote: > > >>> > >> > > > > > >>> > >> > > > > I've > noew > > tested a whole > > >>> > heap of > > >>> > >> > expressions even > > >>> > >> > > > > //name=3D'Tiger' > > nothing > > >>> > >> > > > > works. > > >>> > >> > > > > > > >>> > >> > > > > On Tue, > Feb > > 10, 2009 at 12:01 > > >>> > AM, Andrew > > >>> > >> > Hughes > > >>> > >> > > > wrote: > > >>> > >> > > > > > > >>> > >> > > > >> I > got > > cracking on testing > > >>> > this out... no > > >>> > >> > luck > > >>> > >> > > > (yet). > Here's my > > testing > > >>> > >> > > > >> > code if > > some kind person > > >>> > could please > > >>> > >> > take a > > >>> > >> > > > look.... > > >>> > >> > > > >> > First my > > generic > > >>> > collection hierarchy > > >>> > >> > (which only > > >>> > >> > > > contains a > name > > and > > >>> > >> > > > >> > > children)... > > >>> > >> > > > >> > > >>> > >> > > > >> > package > > jxpathresearch; > > >>> > >> > > > >> > > >>> > >> > > > >> > import > > >>> > java.util.ArrayList; > > >>> > >> > > > >> > > >>> > >> > > > >> > public > > class HierarchyPojo > > >>> > extends > > >>> > >> > > > > > ArrayList { > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0public > > >>> > HierarchyPojo(String name){ > > >>> > >> > > > >> > > >>> > this.setName(name); > > >>> > >> > > > >>=A0 > > =A0=A0=A0} > > >>> > >> > > > >>=A0 > > =A0=A0=A0private String name =3D > > >>> > ""; > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0public String > > >>> > getName() { > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0return name; > > >>> > >> > > > >>=A0 > > =A0=A0=A0} > > >>> > >> > > > >>=A0 > > =A0=A0=A0public void > > >>> > setName(String name) { > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0this.name =3D name; > > >>> > >> > > > >>=A0 > > =A0=A0=A0} > > >>> > >> > > > >> > > >>> > >> > > > >> } > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> > Next, > > the wrapper for the > > >>> > root context > > >>> > >> > (as Matt > > >>> > >> > > > suggested) > and > > populated > > >>> > >> > > > >> > with > > animals... > > >>> > >> > > > >> > > >>> > >> > > > >> > package > > jxpathresearch; > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> > public > > class > > >>> > CollectionRoot { > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0private HierarchyPojo > > >>> > hierarchyPojo; > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0public > > >>> > CollectionRoot(){ > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0//Animal > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0hierarchyPojo =3D > > >>> > new > > >>> > >> > > > > > HierarchyPojo("Animal"); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0//Animal.Dog > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0HierarchyPojo dog > > >>> > =3D new > > >>> > >> > > > > > HierarchyPojo("Dog"); > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > //Animal.Dog.Labrador > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0dog.add(new > > >>> > >> > > > > > >>> > HierarchyPojo("Labrador")); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0//Animal.Dog.Boxer > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0dog.add(new > > >>> > >> > > > > > HierarchyPojo("Boxer")); > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > //Animal.Dog.Mastiff > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0dog.add(new > > >>> > >> > > > > > >>> > HierarchyPojo("Mastiff")); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0//Animal.Cat > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0HierarchyPojo cat > > >>> > =3D new > > >>> > >> > > > > > HierarchyPojo("Cat"); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0//Animal.Cat.Tiger > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0cat.add(new > > >>> > >> > > > > > HierarchyPojo("Tiger")); > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > //Animal.Cat.Cougar > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0cat.add(new > > >>> > >> > > > > > HierarchyPojo("Cougar")); > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > //Animal.Cat.Leopard > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0cat.add(new > > >>> > >> > > > > > >>> > HierarchyPojo("Leopard")); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0//Add Animal.Dog > > >>> > & > > >>> > >> > Animal.Cat > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > hierarchyPojo.add(dog); > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > hierarchyPojo.add(cat); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0} > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0public HierarchyPojo > > >>> > >> > getHierarchyPojo() > > >>> > >> > > > {return > > hierarchyPojo;} > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0public void > > >>> > >> > > > setHierarchyPojo(HierarchyPojo > > >>> > >> > > > > hierarchyPojo) > > >>> > >> > > > >> > > {this.hierarchyPojo =3D > > >>> > hierarchyPojo;} > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> } > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> > Finally > > invoke and test... > > >>> > >> > > > >> > > >>> > >> > > > >> > public > > class App > > >>> > >> > > > >> > > >>> > >> > > > >> { > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0public static void > > >>> > main( String[] > > >>> > >> > args ) > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0{ > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0JXPathContext > > >>> > context =3D > > >>> > >> > > > > > JXPathContext.newContext(new > > >>> > >> > > > >> > > CollectionRoot()); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0String query =3D > > >>> > >> > > > > > >>> > >> > > > >>> > "//hierarchyPojo[@name=3D'Tiger']"; > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0 =A0 =A0=A0=A0String fName =3D > > >>> > >> > > > > > context.getValue(query).toString(); > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > System.out.println("Ran > > >>> > >> > > > '"+query+"' > and > > >>> > got > > >>> > >> > > > > > >>> > '"+fName+"'"); > > >>> > >> > > > >> > > >>> > >> > > > >>=A0 > > =A0=A0=A0} > > >>> > >> > > > >> > > >>> > >> > > > >> } > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> > Above, > > should find one > > >>> > entry for > > >>> > >> > > > 'name=3DTiger' > but > > it does > > >>> > not, I get an > > >>> > >> > > > >> > > exception. This still > > >>> > doesn't seem > > >>> > >> > to traverse > > >>> > >> > > > the > Collection > > correctly. Any > > >>> > >> > > > >> > help > > would be most > > >>> > welcome. > > >>> > >> > > > >> > > Exception in thread > > >>> > "main" > > >>> > >> > > > >> > > >>> > >> > > > >>> > > > org.apache.commons.jxpath.JXPathNotFoundException: > > >>> > >> > > > No value > for > > xpath: > > >>> > >> > > > >> > > >>> > //hierarchyPojo[@name=3D'Tiger'] > > >>> > >> > > > >> > > >>> > >> > > > >> > Thanks > > for reading, > > >>> > >> > > > >> > Andrew > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> > > >>> > >> > > > >> On > Mon, > > Feb 9, 2009 at > > >>> > 10:24 PM, Andrew > > >>> > >> > Hughes > > >>> > >> > > > wrote: > > >>> > >> > > > >> > > >>> > >> > > > > >>> > > Thanks Matt - I will > > >>> > test this out > > >>> > >> > tomorrow > > >>> > >> > > > when I am > back in > > the > > >>> > >> > > > > >>> > > office... > > >>> > >> > > > > >>> > > >>> > >> > > > > >>> > > Being constructive... > > >>> > >> > > > > >>> > > Surely this should at > > >>> > least be a > > >>> > >> > precondition > > >>> > >> > > > check and > throw a > > specific > > >>> > >> > > > > >>> > > exception if it's > > >>> > not supported? > > >>> > >> > > > > >>> > > Thank You > > >>> > >> > > > > >>> > > --Andrew > > >>> > >> > > > > >>> > > >>> > >> > > > > >>> > > >>> > >> > > > >>> > On > > Mon, Feb 9, 2009 at > > >>> > 2:27 PM, Matt > > >>> > >> > Benson > > >>> > >> > > > wrote: > > >>> > >> > > > > >>> > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > Most likely your > > >>> > problem is not > > >>> > >> > with > > >>> > >> > > > generics, > but > > simply with the fact > > >>> > >> > > > > >>>> > > that JXPath has a > > >>> > hard time > > >>> > >> > using a > > >>> > >> > > > collection > as its > > root.=A0 The > > >>> > easiest > > >>> > >> > > > > >>>> > > workaround is to > > >>> > use some parent > > >>> > >> > object to > > >>> > >> > > > hold a > reference > > to your > > >>> > >> > > > > >>>> > > container. > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > HTH, > > >>> > >> > > > > >>>> > > Matt > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > --- On Sun, > > >>> > 2/8/09, Andrew > > >>> > >> > Hughes > > >>> > >> > > > > > wrote: > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > > From: Andrew > > >>> > Hughes > > >>> > >> > > > > > >>> > >> > > > > >>>> > > > Subject: > > >>> > JXPath over > > >>> > >> > Generic > > >>> > >> > > > > > Collection, How? > > >>> > >> > > > > >>>> > > > To: > > >>> > "Commons Users > > >>> > >> > List" > > >>> > >> > > > > > >>> > >> > > > > >>>> > > > Date: Sunday, > > >>> > February 8, > > >>> > >> > 2009, 5:09 > > >>> > >> > > > PM > > >>> > >> > > > > >>>> > > > Hi All, > > >>> > >> > > > > >>>> > > > Hopefully the > > >>> > solution is > > >>> > >> > as easy as > > >>> > >> > > > the > question. I > > would > > >>> > >> > > > > >>>> > > > like to > > >>> > perform > > >>> > >> > > > > >>>> > > > evaluation on > > >>> > a (very > > >>> > >> > simple) generic > > >>> > >> > > > > collection... as > > you > > >>> > >> > > > > >>>> > > > can see below > > >>> > >> > > > > >>>> > > > > > >>> > (HeirarchyPojo). I should > > >>> > >> > be able to > > >>> > >> > > > ask for a > > >>> > >> > > > > >>>> > > > > > >>> > HeirarchyPojo's with > > >>> > >> > > > > >>>> > > > > > >>> > name=3D'Bill' or the > > >>> > >> > 3rd > > >>> > >> > > > Child... > The > > problem is that > > >>> > >> > > > > >>>> > > > nothing ever > > >>> > evaluate on > > >>> > >> > > > > >>>> > > > this data > > >>> > structure. > > >>> > >> > What's the > > >>> > >> > > > deal with > > Generic > > >>> > >> > > > > >>>> > > > Collections > > >>> > and JXPath? > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > p.s this is > > >>> > not in the > > >>> > >> > userguide and > > >>> > >> > > > would be a > most > > >>> > >> > > > > >>>> > > > welcomed > > >>> > addition (if > > >>> > >> > > > > >>>> > > > we can nut > > >>> > this out with > > >>> > >> > your help). > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > Cheers. > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > package > > >>> > xpath.and.generics; > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > import > > >>> > java.util.ArrayList; > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > public class > > >>> > HeirarchyPojo > > >>> > >> > extends > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > ArrayList{ > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0public > > >>> > >> > HeirarchyPojo(){} > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0private > > >>> > String id; > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0private > > >>> > String name; > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0public > > >>> > String getId() { > > >>> > >> > > > > >>>> > > > > > >>> > return id; > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0} > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0public > > >>> > void > > >>> > >> > setId(String id) { > > >>> > >> > > > > >>>> > > > > > >>> > this.id =3D id; > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0} > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0public > > >>> > String getName() > > >>> > >> > { > > >>> > >> > > > > >>>> > > > > > >>> > return name; > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0} > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0public > > >>> > void > > >>> > >> > setName(String name) > > >>> > >> > > > { > > >>> > >> > > > > >>>> > > > > > >>> > this.name =3D name; > > >>> > >> > > > > >>>> > > >=A0 =A0=A0=A0} > > >>> > >> > > > > >>>> > > > > > >>> > >> > > > > >>>> > > > } > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > >>> > >> > > > > >>>> > > >>> > >> > > > > > >>> > >> > > > >>> > > > > --------------------------------------------------------------------- > > >>> > >> > > > > >>>> > > 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 > > >>> > >> > > > > >>> > >> > > > > >>> > >> > > >>> > >> > > >>> > >> > > >>> > >> > > >>> > >> > > >>> > > > > --------------------------------------------------------------------- > > >>> > >> 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 > > >>> > > >>> > > >> > > > > >=20 >=20 >=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org >=20 > =0A=0A=0A --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org