commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: [beanutils] adding DynaBean.populate(Map) method?
Date Thu, 30 May 2002 17:11:21 GMT
From: "Craig R. McClanahan" <>
> On Thu, 30 May 2002, James Strachan wrote:
> > Date: Thu, 30 May 2002 12:34:42 +0100
> > From: James Strachan <>
> > When working with DynaBeans it might be nice to offer a populate(Map)
> > to easily populate a DynaBean from a map where the keys are property
> > and the values are the new property values to populate. I've already hit
> > use case for this in Jelly.

Actually after further refactoring of code I no longer need this feature
afterall though I may do again in the future...

>> Adding this method to DynaBean would also mirror
> > the BeanUtils.populate(Object bean, Map) method in a more OO way.
> >
> Can't you just use BeanUtils.populate() for this already?  It knows (or if
> not it's a bug) how to deal with DynaBeans.

Sure, though BeanUtils.populate() does test for mapped and indexed
properties along with performing conversions. So its fairly heavy weight
(indeed its an argument for not using this mechanism by default in

My initial motivation for the suggestion was mostly out of cosmetic reasons,
calling dynaBean.populate(Map) is a more natural OO way to do it and to save
folks typing about 4/5 lines of code to iterate over the Map and call
dynaBean.set(name, value) for each Map.Entry..

> Since o.a.c.b.DynaBean is an interface, wouldn't this break every existing
> DynaBean implementation in the world?

Good point. I kinda assumed there'd be a DynaBeanSupport class from which we
all derive, but alas no. So I'm now -1 on my own suggestion for this very

Maybe we could have a DynaBeanUtils class and make this a static helper
method? We could have a couple of helper factory methods too...

public class DynaBeanUtils {

    // does not support indexed or mapped properties
    // conversion is done only if the DyanBean implementation supports it
    public static void  populate(DynaBean dynaBean, Map map);

    // creates a new DynaBean wrapper around a Java Bean that
    // may or may not perform automatic conversion on setters
    public static void DynaBean newWrapBean(Object bean, boolean

Not sure if its worth it though.


Do You Yahoo!?
Get your free address at

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

View raw message