commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: Digester
Date Sun, 09 Oct 2005 06:02:00 GMT
On Fri, 2005-10-07 at 19:41 +0200, Ing. Fabio Biscaro wrote:
> Hi! I have this xml code snippet:
> 
> <slice id="chiudi">
> 			<UID>18290a0d-43ac-40b2-a1a4-638a89f0c041-96</UID>
> 			<captures>
> 				<capture id="chiudi_1127312064299_17"> ...
> 				<capture ....
> 
> I use this digester:
> 
> 			<pattern value="captures/capture">


> When I use digester to fill capture object properties I need to fill
> "parentUID" with uid of slices info which is parent. How can I pass slice
> UID to capture bean?
> 
> ../../../UID doesnt work!

Presumably you've left out some rule which looks like:
  <pattern value="captures/capture>
    <set-next method="addCapture"/>

Assuming you have this, then in the Slice.addCapture method, you can
just set the capture object's UID:

public class Slice
  public void addCapture(Capture capture) {
    capture.setUID(this.UID);
    this.captures.add(capture);
  }


A pattern "../../../UID" will never work. Remember that Digester is just
a simple wrapper around the SAX api, **not** the DOM api. And as with
SAX, once an element has been processed it is forgotten by digester. The
only place data seen in the past is stored is inside objects you've
created with ObjectCreateRule rules. So whatever solution you use, it
will involve retrieving the data from the Slice object.

An alternative is to create a special SetUIDRule rule class, which
assumes that when it fires the object on the top of the stack is a
Capture, and the object second-from-top is a Slice object. This is only
a dozen lines of code or so. Don't be worried about writing your own
rules; digester is designed for this. Unfortunately, the xmlrules module
for digester isn't so easy to plug custom rules into.

Or maybe you could write an ObjectCreationFactory, and use a
FactoryCreateRule to create your Capture objects instead of an
ObjectCreateRule; the FactoryCreateRule could assume the object on top
of the stack is a Slice object.

I think the first option (setting the UID in the addCapture method) is
the best, assuming you *are* adding created Capture objects as children
of the Slice object - which would be the normal thing to do.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message