--- On Wed, 2/11/09, Andrew Hughes ahhug...@gmail.com wrote:
From: Andrew Hughes ahhug...@gmail.com
Subject: Re: JXPath over Generic Collection?, How?
To: Commons Users List user@commons.apache.org
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 {
public Thing(String name) {
this.name = name;
}
private String name = ;
public String getName() {
return name;
}
private ArrayListThing children = new
ArrayListThing();
public ArrayListThing getChildren() {
return children;
}
}
public static void main(String[] args) {
//get some same data
Thing animal = new Thing(Animal);
//Animal.Dog.*
Thing dog = new Thing(Dog);
dog.getChildren().add(new
Thing(Labrador));
dog.getChildren().add(new
Thing(Boxer));
animal.getChildren().add(dog);
//Animal.Cat.*
Thing cat = new Thing(Cat);
cat.getChildren().add(new Thing(Lion));
cat.getChildren().add(new
Thing(Tiger));
animal.getChildren().add(cat);
//run a query on it
JXPathContext context =
JXPathContext.newContext(animal);
String query = /Animal;
Thing result = (Thing) context.getValue(query);
String path = context.getPointer(query).asPath();
System.out.println(Ran ' + query +
' and got ' +
result.getName() + ' on path ' + path +
'.);
}
What would you be trying to select? If you want to know how to look for a
given Thing in this graph, I can probably help. 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. 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
ahhug...@gmail.com wrote:
Yeah, that makes sense. The part that was confusing me
is that if I
have...
public class Thing {
private ListThing 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
gudnabr...@yahoo.com wrote:
It should be as simple as Thing _containing_ a
ListThing rather than
_being_ a ListThing. Composition over
inheritance, do you see?
HTH,
Matt
--- On Tue, 2/10/09, Andrew Hughes
ahhug...@gmail.com wrote:
From: Andrew Hughes
ahhug...@gmail.com
Subject: Re: JXPath over Generic
Collection?, How?
To: Commons Users List
user@commons.apache.org,
gudnabr...@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
gudnabr...@yahoo.com wrote:
I admit I hadn't looked at this with
a highly
critical eye, but this
business of Thing extending
ArrayListThing
seems quite strange to me.
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. It looks
as though
you're trying to represent
a tree structure. This may be a good
example of a
reason for the idea of
composition over inheritance. 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
ahhug...@gmail.com wrote:
From: Andrew Hughes
ahhug...@gmail.com
Subject: Re: JXPath over Generic
Collection?, How?
To: Commons Users List
user@commons.apache.org
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 {
public static void main(
String[] args ){
JXPathContext context =
JXPathContext.newContext(new
ThingRoot());