You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Strachan <ja...@yahoo.co.uk> on 2002/05/30 13:34:42 UTC

[beanutils] adding DynaBean.populate(Map) method?

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. Adding this method to DynaBean would also mirror
the BeanUtils.populate(Object bean, Map) method in a more OO way.

I'm happy to go ahead and do the work for this if folks agree. Does this
seem a sensible idea? I'm +1

James


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


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [beanutils] adding DynaBean.populate(Map) method?

Posted by Jason van Zyl <jv...@zenplex.com>.
On Thu, 2002-05-30 at 07:34, James Strachan wrote:
> 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. Adding this method to DynaBean would also mirror
> the BeanUtils.populate(Object bean, Map) method in a more OO way.
> 
> I'm happy to go ahead and do the work for this if folks agree. Does this
> seem a sensible idea? I'm +1

+1
 
> James
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
jvz.

Jason van Zyl
jvanzyl@apache.org

http://tambora.zenplex.org


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [beanutils] adding DynaBean.populate(Map) method?

Posted by Juozas Baliuka <ba...@mwm.lt>.
+1
At 12:34 2002.05.30 +0100, you wrote:
>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. Adding this method to DynaBean would also mirror
>the BeanUtils.populate(Object bean, Map) method in a more OO way.
>
>I'm happy to go ahead and do the work for this if folks agree. Does this
>seem a sensible idea? I'm +1
>
>James
>
>
>_________________________________________________________
>Do You Yahoo!?
>Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [beanutils] adding DynaBean.populate(Map) method?

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Craig R. McClanahan" <cr...@apache.org>
> On Thu, 30 May 2002, James Strachan wrote:
>
> > Date: Thu, 30 May 2002 12:34:42 +0100
> > From: James Strachan <ja...@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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [beanutils] adding DynaBean.populate(Map) method?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 30 May 2002, James Strachan wrote:

> Date: Thu, 30 May 2002 12:34:42 +0100
> From: James Strachan <ja...@yahoo.co.uk>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: Jakarta Commons Developers <co...@jakarta.apache.org>
> Subject: [beanutils] adding DynaBean.populate(Map) method?
>
> 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. 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.

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

> I'm happy to go ahead and do the work for this if folks agree. Does this
> seem a sensible idea? I'm +1
>
> James
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>