You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by robert burrell donkin <ro...@blueyonder.co.uk> on 2002/11/25 21:01:15 UTC

[beanutils] PropertyUtils.setProperty on classes which extend Map

this one is in bugzilla

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14440

i've got a test case which shows that classes which extend map don't have 
the setter called, instead the value is place into the map. i'm also 
willing to take a look at creating a fix.

just wanted to check that: is this a bug (rather than some obscure feature 
i'm not aware of)?

- robert


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


Re: [beanutils] Map as a pseudo-bean...? [was Re: [beanutils] PropertyUtils.setProperty on classes which extend Map]

Posted by Juozas Baliuka <ba...@centras.lt>.
I have some experimental code to generate beans at runtime (BCEL stuff) :

Class cls = generate(Class[] types, String[] names);
Object bean = cls.newInstance();

But I can't find use case for it myself :)


> On Tuesday, November 26, 2002, at 08:07 PM, Juozas Baliuka wrote:
>
> > It is trivial to generate "bean" at runtime, but it can be used in
> > "untyped" languages only.
> >  Map can be used the same way, without any "adapter".
> > I think type information is useless in this case ( "script" doe's not
use
> > it ).
> > Are "dynabeans" used as some kind of workaround for "not map enabled"
> > frameworks  ?
>
> i don't how you could use them but i don't think that this is the reason
> why they were developed.
>
> AFAIK they act as adapters (for bean-centric environments) for data which
> isn't in beans. for example, they can be used to wrap a resultset so that
> it appears to be beans. if the bean-centric environment uses beanutils for
> it's introspection then the dynabean wrapping the resultset will look and
> behaviour like a bean.
>
> (i'm not a dynabeans expert so hopefully i'll be corrected if i've gone
> wrong.)
>
> - robert
>
> > ----- Original Message -----
> > From: "Stephen Colebourne" <sc...@btopenworld.com>
> > To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> > Sent: Tuesday, November 26, 2002 9:50 PM
> > Subject: Re: [beanutils] Map as a pseudo-bean...? [was Re: [beanutils]
> > PropertyUtils.setProperty on classes which extend Map]
> >
> >
> >> From: "robert burrell donkin" <ro...@blueyonder.co.uk>
> >>> a map could act as a pseudo-bean by having each key-value pair act as
a
> >>> pseudo-property. the name of the property corresponds to the key (from
> > the
> >>> pair) and the property value corresponds to the value (from the pair).
> >>
> >> FYI, this is part of what [clazz] is trying to achieve.
> >>
> >> Stephen
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.
> > org>
> > For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.
> > org>
> >
>
>
> --
> 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] Map as a pseudo-bean...? [was Re: [beanutils] PropertyUtils.setProperty on classes which extend Map]

Posted by robert burrell donkin <ro...@AlmostHuman.com>.
On Tuesday, November 26, 2002, at 08:07 PM, Juozas Baliuka wrote:

> It is trivial to generate "bean" at runtime, but it can be used in
> "untyped" languages only.
>  Map can be used the same way, without any "adapter".
> I think type information is useless in this case ( "script" doe's not use
> it ).
> Are "dynabeans" used as some kind of workaround for "not map enabled"
> frameworks  ?

i don't how you could use them but i don't think that this is the reason 
why they were developed.

AFAIK they act as adapters (for bean-centric environments) for data which 
isn't in beans. for example, they can be used to wrap a resultset so that 
it appears to be beans. if the bean-centric environment uses beanutils for 
it's introspection then the dynabean wrapping the resultset will look and 
behaviour like a bean.

(i'm not a dynabeans expert so hopefully i'll be corrected if i've gone 
wrong.)

- robert

> ----- Original Message -----
> From: "Stephen Colebourne" <sc...@btopenworld.com>
> To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> Sent: Tuesday, November 26, 2002 9:50 PM
> Subject: Re: [beanutils] Map as a pseudo-bean...? [was Re: [beanutils]
> PropertyUtils.setProperty on classes which extend Map]
>
>
>> From: "robert burrell donkin" <ro...@blueyonder.co.uk>
>>> a map could act as a pseudo-bean by having each key-value pair act as a
>>> pseudo-property. the name of the property corresponds to the key (from
> the
>>> pair) and the property value corresponds to the value (from the pair).
>>
>> FYI, this is part of what [clazz] is trying to achieve.
>>
>> Stephen
>>
>>
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>>
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>
>


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


Re: [beanutils] Map as a pseudo-bean...? [was Re: [beanutils] PropertyUtils.setProperty on classes which extend Map]

Posted by Juozas Baliuka <ba...@centras.lt>.
It is trivial to generate "bean" at runtime, but it can be used in
"untyped" languages only.
 Map can be used the same way, without any "adapter".
I think type information is useless in this case ( "script" doe's not use
it ).
Are "dynabeans" used as some kind of workaround for "not map enabled"
frameworks  ?

----- Original Message -----
From: "Stephen Colebourne" <sc...@btopenworld.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Tuesday, November 26, 2002 9:50 PM
Subject: Re: [beanutils] Map as a pseudo-bean...? [was Re: [beanutils]
PropertyUtils.setProperty on classes which extend Map]


> From: "robert burrell donkin" <ro...@blueyonder.co.uk>
> > a map could act as a pseudo-bean by having each key-value pair act as a
> > pseudo-property. the name of the property corresponds to the key (from
the
> > pair) and the property value corresponds to the value (from the pair).
>
> FYI, this is part of what [clazz] is trying to achieve.
>
> Stephen
>
>
> --
> 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] Map as a pseudo-bean...? [was Re: [beanutils] PropertyUtils.setProperty on classes which extend Map]

Posted by Stephen Colebourne <sc...@btopenworld.com>.
From: "robert burrell donkin" <ro...@blueyonder.co.uk>
> a map could act as a pseudo-bean by having each key-value pair act as a
> pseudo-property. the name of the property corresponds to the key (from the
> pair) and the property value corresponds to the value (from the pair).

FYI, this is part of what [clazz] is trying to achieve.

Stephen


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


[beanutils] Map as a pseudo-bean...? [was Re: [beanutils] PropertyUtils.setProperty on classes which extend Map]

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Monday, November 25, 2002, at 11:25 PM, Craig R. McClanahan wrote:

<snip>

> AFAIK, we've never promised that the BeanUtils or PropertyUtils code
> formally support Maps as the *destination* of a property set operation,
> even though they are acceptable as the source in certain scenarios.  In
> addition, if we're going to support setting via PropertyUtils, we
> certainly should support getting for symmetry.
>
> I think it's worth investigating whether we can support a Map as a
> pseudo-bean -- but that should start with a general analysis of the
> problem space (including the thorny issue of deciding what the "property
> type" of such a property should be if there is no current value for a
> particular key), rather than a piecemeal fix to one aspect of the
> situation.

that does seem the best approach.

> I'm game to participate (a little) in a discussion like that -- just don'
> t
> have the cycles to lead one.  Do you?

probably. i'm not sure that i've the capability, though. guess we'll have 
to wait and see about that...

just to make sure that i understand the basic concept, here's my 
restatement:

a map could act as a pseudo-bean by having each key-value pair act as a 
pseudo-property. the name of the property corresponds to the key (from the 
pair) and the property value corresponds to the value (from the pair).

- robert


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


Re: [beanutils] PropertyUtils.setProperty on classes which extend Map

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Tuesday, November 26, 2002, at 07:26 PM, Craig R. McClanahan wrote:

>
>
> On Tue, 26 Nov 2002, robert burrell donkin wrote:
>
>> Date: Tue, 26 Nov 2002 19:12:21 +0000
>> From: robert burrell donkin <ro...@blueyonder.co.uk>
>> Reply-To: Jakarta Commons Developers List <commons-
>> dev@jakarta.apache.org>
>> To: Jakarta Commons Developers List <co...@jakarta.apache.org>
>> Subject: Re: [beanutils] PropertyUtils.setProperty on classes which
>>     extend Map
>>
>> On Monday, November 25, 2002, at 11:25 PM, Craig R. McClanahan wrote:
>>
>>> On Mon, 25 Nov 2002, robert burrell donkin wrote:
>>
>> <snip>
>>
>>> AFAIK, we've never promised that the BeanUtils or PropertyUtils code
>>> formally support Maps as the *destination* of a property set operation,
>>> even though they are acceptable as the source in certain scenarios.  In
>>> addition, if we're going to support setting via PropertyUtils, we
>>> certainly should support getting for symmetry.
>>
>> i certainly agree with the point above but... just to be clear (which i
>> probably wasn't before)
>>
>> the bug (as far as i understand it) concerns setting normal bean
>> properties on a bean that extends Hashtable. i have a bean with a 
>> property
>> that is set successfully when the class doesn't extend hashtable. when i
>> change the class definition so that it extends Hashtable, the property is
>> no longer set by PropertyUtils.
>>
>
> Not remembering the details, is it possible that by extending Hashtable
> you're creating a situation where you have a property that violates the
> JavaBean spec's naming patterns (such as having two setters, or a setter
> and a getter with different property types)?  That would certainly cause 
> a
> problem like this.

i've taken a look at the code. there's no problem with setSimpleProperty 
but setProperty fails.

this calls setNestedProperty. this method checks to see if bean instanceof 
Map and if so, put's the value keyed by the property name into the map 
rather than looking for a property setter.

IMHO the bug poster's right that the correct behaviour should be that if 
there is a matching property then that should be called instead of putting 
the value in the map. unless anyone has any objections i'll create a fix 
along those lines...

- robert


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


Re: [beanutils] PropertyUtils.setProperty on classes which extend Map

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

On Tue, 26 Nov 2002, robert burrell donkin wrote:

> Date: Tue, 26 Nov 2002 19:12:21 +0000
> From: robert burrell donkin <ro...@blueyonder.co.uk>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> Subject: Re: [beanutils] PropertyUtils.setProperty on classes which
>     extend Map
>
> On Monday, November 25, 2002, at 11:25 PM, Craig R. McClanahan wrote:
>
> > On Mon, 25 Nov 2002, robert burrell donkin wrote:
>
> <snip>
>
> > AFAIK, we've never promised that the BeanUtils or PropertyUtils code
> > formally support Maps as the *destination* of a property set operation,
> > even though they are acceptable as the source in certain scenarios.  In
> > addition, if we're going to support setting via PropertyUtils, we
> > certainly should support getting for symmetry.
>
> i certainly agree with the point above but... just to be clear (which i
> probably wasn't before)
>
> the bug (as far as i understand it) concerns setting normal bean
> properties on a bean that extends Hashtable. i have a bean with a property
> that is set successfully when the class doesn't extend hashtable. when i
> change the class definition so that it extends Hashtable, the property is
> no longer set by PropertyUtils.
>

Not remembering the details, is it possible that by extending Hashtable
you're creating a situation where you have a property that violates the
JavaBean spec's naming patterns (such as having two setters, or a setter
and a getter with different property types)?  That would certainly cause a
problem like this.

> so, it seems that this is a bug and isn't related to supporting maps as
> pseudo-beans (i'll create a new thread for that discussion).
>
> - robert
>

Craig


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


Re: [beanutils] PropertyUtils.setProperty on classes which extend Map

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Monday, November 25, 2002, at 11:25 PM, Craig R. McClanahan wrote:

> On Mon, 25 Nov 2002, robert burrell donkin wrote:

<snip>

> AFAIK, we've never promised that the BeanUtils or PropertyUtils code
> formally support Maps as the *destination* of a property set operation,
> even though they are acceptable as the source in certain scenarios.  In
> addition, if we're going to support setting via PropertyUtils, we
> certainly should support getting for symmetry.

i certainly agree with the point above but... just to be clear (which i 
probably wasn't before)

the bug (as far as i understand it) concerns setting normal bean 
properties on a bean that extends Hashtable. i have a bean with a property 
that is set successfully when the class doesn't extend hashtable. when i 
change the class definition so that it extends Hashtable, the property is 
no longer set by PropertyUtils.

so, it seems that this is a bug and isn't related to supporting maps as 
pseudo-beans (i'll create a new thread for that discussion).

- robert


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


Re: [beanutils] PropertyUtils.setProperty on classes which extend Map

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

On Mon, 25 Nov 2002, robert burrell donkin wrote:

> Date: Mon, 25 Nov 2002 20:01:15 +0000
> From: robert burrell donkin <ro...@blueyonder.co.uk>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: Jakarta Commons Developers <co...@jakarta.apache.org>
> Subject: [beanutils] PropertyUtils.setProperty on classes which extend Map
>
> this one is in bugzilla
>
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14440
>
> i've got a test case which shows that classes which extend map don't have
> the setter called, instead the value is place into the map. i'm also
> willing to take a look at creating a fix.
>
> just wanted to check that: is this a bug (rather than some obscure feature
> i'm not aware of)?
>

AFAIK, we've never promised that the BeanUtils or PropertyUtils code
formally support Maps as the *destination* of a property set operation,
even though they are acceptable as the source in certain scenarios.  In
addition, if we're going to support setting via PropertyUtils, we
certainly should support getting for symmetry.

I think it's worth investigating whether we can support a Map as a
pseudo-bean -- but that should start with a general analysis of the
problem space (including the thorny issue of deciding what the "property
type" of such a property should be if there is no current value for a
particular key), rather than a piecemeal fix to one aspect of the
situation.

I'm game to participate (a little) in a discussion like that -- just don't
have the cycles to lead one.  Do you?

> - robert
>

Craig


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