JXPath - Iterating over all elements that 'lie on the way'

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JXPath - Iterating over all elements that 'lie on the way'

"Gebhardt, Jörn"
Hi,

I have the following scenario:
1.) I'm using Hibernate as O/R mapping tool.
2.) I dynamically need parts of the object tree in the frontend. To achieve this, I have a DTO structure that is similar to the Hibernate objects and that has also some kind of lazy loading capabilities.

Now I want to use JXPath expressions to define the parts of the backend object graph that should be shipped to the frontend.

E.g. if I have the association:
 Company (1)->(n) Department (1)->(n) Employee
(i.e. a company has several departments and each department has a number of employees)
and I have a specific company that I use as root context and I want to retrieve all employoees of the company I'd write some code like this:

JXPathContext.newContext(company).iterate("departments/employees")

However, I also want to iterate over all objects that 'lie on the way', i.e. in the above example I additionally want to iterate over all departments.

Is there a way to access all objects that have been visited while resolving the XPath expression? Or can I write my own extension to the reference implementation that helps me, collecting all these objects?

Thanks in advance,
Jörn


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

Reply | Threaded
Open this post in threaded view
|

Re: JXPath - Iterating over all elements that 'lie on the way'

Torsten Curdt
> However, I also want to iterate over all objects that 'lie on the  
> way', i.e. in the above example I additionally want to iterate over  
> all departments.
>
> Is there a way to access all objects that have been visited while  
> resolving the XPath expression? Or can I write my own extension to  
> the reference implementation that helps me, collecting all these  
> objects?
>

I think you are after the "ancestor" axis

HTH

cheers
--
Torsten

PGP.sig (193 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

AW: JXPath - Iterating over all elements that 'lie on the way'

"Gebhardt, Jörn"
In reply to this post by "Gebhardt, Jörn"
>> Is there a way to access all objects that have been visited while
>> resolving the XPath expression? Or can I write my own extension to the
>> reference implementation that helps me, collecting all these objects?
>
>
> I think you are after the "ancestor" axis
>
> HTH

Hi Torsten,

this helps only to some extend...
First of all, I don't know how I can get the AncestorContext of an element and secondly do I believe that rolling back the ancestors für all results isn't very efficient, as I will walk through the same root objects for every item in the result collection.
From what I have seen in the code isn't it very straight forward to "patch" the reference implementation only at a specific point to protocol all the objects that have been visited. But I must admit that the code is somewhat complex and not easy to understand by just skimming over at the source code...

Do you see any easy option to plug in a call back whenever a new object is retrieved that lies on one of the target paths?

Thanks in advance,
Jörn


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