commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [digester]: Is there a way to populate bean tags by only one call
Date Fri, 16 May 2003 16:06:59 GMT


On Fri, 16 May 2003, Norbert Krömeke wrote:

> Date: Fri, 16 May 2003 07:22:28 +0200
> From: Norbert Krömeke <N.Kroemeke@actosoft.de>
> Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> To: Jakarta Commons Users <commons-user@jakarta.apache.org>
> Subject: [digester]: Is there a way to populate bean tags by only one call
>
> Hi,
>
> I'm looking for the solution to resolve fallowing problem. The XML input
> looks like this :
>
> ...
> <parameters>
>    <track1>1234567</track1>
>    <track2>666666666</track2>
>    ....
>    <tag-name>tag-body</tag-name>
> </parameters>
>
> I want to use only one function to collect all this 'sub-tags' from <parameters>
by
> call of addParam(tag-name, tag-body).
>

Assuming you have a JavaBean that is supposed to represent an instance of
the <parameters> element, and it has individual properties for each of the
nested things, you could initialize Digester rules programmatically like
this:

  digester.addObjectCreate("parameters",
                           "com.sun.MyParametersBeanClass");
  digester.addCallMethod("parameters/track1",
                         "setTrack1", 0);
  ...
  digester.addCallMethod("parameters/tag-name",
                         "setTagName", 0);

The "0" argument is a special flag that says to take the parameter value
from the body content of the element.

> How can I do it if I use digester-rules.dtd file.

I don't use the XML format much, but the following should be equivalent:

<digester-rules>
  <object-create-rule pattern="parameters"
                    classname="com.sun.MyParametersBeanClass"/>
  <call-method-rule   pattern="parameters/track1"
                   methodname="setTrack1"
                   paramcount="0"/>
  ...
  <call-method-rule   pattern="parameters/tag-name"
                   methodname="setTagName"
                   paramcount="0"/>
</digester-ruless>

>
>
> Thank you Norbert Krömeke
>

Craig McClanahan

Mime
View raw message