commons-user mailing list archives

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

---- Matt Campbell <mattcampbell.85@gmail.com> 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) {
    this.roles.add(role);
  }
after which the digester rule becomes trivial.

Alternatively you could change the input format to:
  <roles>
    <role>...</role>
    <role>...</role>
  </roles>
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.

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