commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [beanutils] adding DynaBean.populate(Map) method?
Date Thu, 30 May 2002 17:11:21 GMT
From: "Craig R. McClanahan" <craigmcc@apache.org>
> On Thu, 30 May 2002, James Strachan wrote:
>
> > Date: Thu, 30 May 2002 12:34:42 +0100
> > From: James Strachan <james_strachan@yahoo.co.uk>
>>
> > When working with DynaBeans it might be nice to offer a populate(Map)
method
> > to easily populate a DynaBean from a map where the keys are property
names
> > and the values are the new property values to populate. I've already hit
a
> > 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
WrapDynaBean).

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
reason.

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
doConversions);
}

Not sure if its worth it though.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message