On Friday, November 22, 2002, at 10:34 PM, YAWN,MIKE (HP-PaloAlto,ex1) wrote:

Hi,

It looks as if digester provides prebuilt rules to set properties in one of
two ways - either using the value of an XML attribute, or using the value of
a nested XML element.

What I'm trying to do is use a nested element. But, the value of the XML
element is not the value I want to set the property to; instead, it is a
key, which should be used to retrieve an object from a HashMap. That
retrieved object is then what I want to set the property value to.

I don't think there is a rule which can easily be adapted to do this
(although I'd love to be proven wrong). Can someone give me a quick set of
steps for creating a new rule that would behave this way?
hi mike

hopefully this should be reasonable straightforward. with digester, there are usually several ways to approach a problem. i'll try to give you mine.

one way to break down the problem is:

1. get objects into map in the first place
2. push the correct object onto the stack from your map when one of the nested elements is encountered
3. use SetNextRule to set the property

you'll be able to do 1 by using a custom constructor. (you might need to do something like pushing you map implementation onto the stack right at the start so that your rules can share it.)

3 is covered in the documentation.

2 requires your custom rule. you should probably create a rule that extends Rule and overrides begin or body (depending on whether the key value is in an attribute or the element body). this rule should look up the object from your map and push it onto the stack. (so it should be pretty easy.)

hope this helps.

- robert


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to