commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [Digester] Converting String value of an attribute to array of integers
Date Sat, 18 Feb 2006 02:34:43 GMT
On Fri, 2006-02-17 at 18:12 -0800, Craig McClanahan wrote:
> > <C ID="7" author="CT" depends="4,6">
> >         <flavour>AAC</range>
> > </C>
> >
> > I currently use d.addSetProperties("List/A") to read in my other
> > attributes.
> As you might have figured out, you are going to need a new Rule
> implementation to accomplish this.  Something along these lines should do
> the trick (where MyClass is the bean class):


I agree with Craig's suggestion here; a custom rule will do the trick
nicely. It might also be possible to register a custom String->int[]
converter for beanutils, but I have some vague memory that there's a
problem with that.

> Note that the above code assumes you change the attribute name from
> "depends" to "dependsValue".  Alternatively, you could leave the attribute
> name the same but change the property name on the bean to something else.
> Making the names different is important to avoid having the Set Properties
> Rule blow up because it doesn't know how to do this conversion.

Actually, SetPropertiesRule has the ability to specify explicit
attrname->propname mappings. Mapping to a null property causes the
attribute to be ignored. As you only need to override one particular
attribute you should be able to do:
  d.addSetProperties("List/C", "depends", null);
to map all attributes to identically named properties *except* the
depends property which will be ignored (and processed by your custom
rule instead).



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

View raw message