You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Wannheden, Knut" <kn...@paranor.ch> on 2003/06/05 11:47:05 UTC

[jxpath] JXPathContext#iterate(String) returns same object multip le times

Hi all,

I just noted that both the methods JXPathContext#iterate(String) and
JXPathContext#iteratePointers(String) can return the same object multiple
times if the path (or pointer) to it is different.

In my object graph I have some two-way associations which can cause this
behaviour and that's of course not desirable.  In this scenario
iteratePointers("//b") can end up returning something like:

	/a[1]/b[1]
	/a[1]/b[1]/a/b[1]
	/a[1]/b[1]/a/[b[1]/a/b[1]
	...

The two-way associations I have are actually containments comparable to
XML's parent-child relationship between elements.  How can I extend JXPath
to specify what properties in my model are parent relationships?

But regardless of these parent-child relationships I think it's questionable
whether the same object should ever be returned twice by these iterators.
Because it means that the iteration can turn out to be never-ending.  Or
will it even always be indefinite?  But I've probably missed an important
aspect here :-)

--
knut

Re: [jxpath] JXPathContext#iterate(String) returns same object multip le times

Posted by Dmitri Plotnikov <dp...@yahoo.com>.
Knut,

No, you are absolutely right.  JXPath is guaranteed to returned unique
pointers, but not unique objects.  If your graph has multiple paths to
the same object, it may be returned repeatedly. The "//" axis has a
protection built into it against simple loops like a->b->a (you'll need
to use the nigthly build to get that behavior).  Other than that there
is really no cure other than specifying more explicit paths. 

- Dmitri


--- "Wannheden, Knut" <kn...@paranor.ch> wrote:
> Hi all,
> 
> I just noted that both the methods JXPathContext#iterate(String) and
> JXPathContext#iteratePointers(String) can return the same object
> multiple
> times if the path (or pointer) to it is different.
> 
> In my object graph I have some two-way associations which can cause
> this
> behaviour and that's of course not desirable.  In this scenario
> iteratePointers("//b") can end up returning something like:
> 
> 	/a[1]/b[1]
> 	/a[1]/b[1]/a/b[1]
> 	/a[1]/b[1]/a/[b[1]/a/b[1]
> 	...
> 
> The two-way associations I have are actually containments comparable
> to
> XML's parent-child relationship between elements.  How can I extend
> JXPath
> to specify what properties in my model are parent relationships?
> 
> But regardless of these parent-child relationships I think it's
> questionable
> whether the same object should ever be returned twice by these
> iterators.
> Because it means that the iteration can turn out to be never-ending. 
> Or
> will it even always be indefinite?  But I've probably missed an
> important
> aspect here :-)
> 
> --
> knut
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com