commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject Re: [Commons-Digester] Mapping an ArrayList
Date Thu, 01 Jan 1970 00:00:00 GMT

---- Matt Campbell <> wrote: 
> I have the following simple xml file.
> <security>
>      <security-sections>
>           <section>
>                <name>issueDetail</name>
>                <role>manager</role>
>                <role>user</role>
>           </section>

> How would I map the role elements to an arraylist named roles?

I suggest changing the SecuritySection class like this:
  SecuritySection.addRole(String role) {
after which the digester rule becomes trivial.

Alternatively you could change the input format to:
then use ObjectCreateRule to create the ArrayList on <roles> and CallMethodRule to invoke
its add method on <role>

If you absolutely cannot do either of these, then I guess you can create the ArrayList at
the section tag. The rule which sets the name attribute will then need to specify a "target
offset" in order to access the SecuritySection object as it is no longer the top object on
the stack. This is rather inelegant; I would recommend one of the other approaches instead.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message