You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Kris Nuttycombe <Kr...@noaa.gov> on 2004/12/04 01:55:39 UTC
[beanutils] PropertyUtils & DynaBeans
Hi, all,
As it currently stands, PropertyUtils doesn't support DynaBeans for a
number of its methods. It doesn't make much sense to return
PropertyDescriptors for DynaBeans, but it's no great pain to use
WrapDynaClass on an ordinary class and thereby be able to introspect
either regular beans or DynaBeans using the same interface. To support
this, I'd like to add a method with the signature:
DynaProperty[] getDynaProperties(Object bean)
to PropertyUtilsBean, with a corresponding static method in PropertyUtils.
Now, one of the other advantages of using PropertyUtilsBean is that it
caches the introspected data. Conceivably, this would also be a useful
feature for the getDynaProperties method. However, here we have a
problem: since DynaClass doesn't have any way to enforce that its
implementations implement HashCode, there's no way to use the same map
caching strategy as is used for the PropertyDescriptors. This
illustrates a larger issue, which is that DynaClass objects aren't
singletons like Class objects are.
To resolve this, I propose adding an AbstractDynaClass base class that
implements hashCode() and equals() based upon the public methods
available in DynaClass. This way, even if DynaClasses aren't singletons,
they can be used for hash keys. It might be also useful to implement a
registry for DynaClasses in this abstract class to provide
singleton-like functionality. Existing DynaClass implementations would
be modified to extend AbstractDynaClass.
Any thoughts?
Kris
--
=====================================================
Kris Nuttycombe
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6337
Kris.Nuttycombe@noaa.gov
=====================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Paulo Gaspar <de...@kebom.net>.
> OK, you're off my Christmas Card list now Paulo.
=:oD
That's the spirit! Maybe your're cool after all...
Cheers,
Paulo
Niall Pemberton wrote:
>OK, you're off my Christmas Card list now Paulo.
>
>Niall
>
>----- Original Message -----
>From: "Paulo Gaspar"
>To: "Jakarta Commons Developers List"
>Sent: Saturday, December 04, 2004 3:41 PM
>Subject: Re: [beanutils] PropertyUtils & DynaBeans
>
>
>
>
>>Niall,
>>
>>What looks pretty clear is that YOU do not know what he is talking about.
>>
>>On caching: he is only talking about caching introspection information,
>>not the actual beans.
>>
>>Go and study what the DynaBean/DynaClass implementations are all about.
>>Do your home work if you really care about them.
>>
>>Regards,
>>Paulo Gaspar
>>
>>Niall Pemberton wrote:
>>
>>
>>
>>>Maybe you could spell out the issues with PropertyUtils and DynaBeans and
>>>the methods involved and what you're trying to do because its not clear
>>>
>>>
>what
>
>
>>>your trying to resolve.
>>>
>>>I'm don't see much value in the getDynaProperties() method being in
>>>PropertyUtils - all you need to do is make eveything a DynaBean then you
>>>
>>>
>can
>
>
>>>get the DynaProperties and do whatever you want using the existing
>>>DynaBean/DynaClass methods - no need for PropertyUtils at all.
>>>
>>>DynaBean dynaBean = (bean instanceof DynaBean)
>>> ? (DynaBean)bean : new WrapDynaBean(bean);
>>>
>>>For caching to work people are going to have to change how they create
>>>DynaBeans and I believe its better left up to the environment they're
>>>
>>>
>being
>
>
>>>used in to implement a caching mechanism - Struts does this for its
>>>DynaActionForm implementation.
>>>
>>>Niall
>>>
>>>----- Original Message -----
>>>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>>>To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
>>>Sent: Saturday, December 04, 2004 12:55 AM
>>>Subject: [beanutils] PropertyUtils & DynaBeans
>>>
>>>
>>>
>>>
>>>
>>>
>>>>Hi, all,
>>>>
>>>>As it currently stands, PropertyUtils doesn't support DynaBeans for a
>>>>number of its methods. It doesn't make much sense to return
>>>>PropertyDescriptors for DynaBeans, but it's no great pain to use
>>>>WrapDynaClass on an ordinary class and thereby be able to introspect
>>>>either regular beans or DynaBeans using the same interface. To support
>>>>this, I'd like to add a method with the signature:
>>>>
>>>>DynaProperty[] getDynaProperties(Object bean)
>>>>
>>>>to PropertyUtilsBean, with a corresponding static method in
>>>>
>>>>
>PropertyUtils.
>
>
>>>>Now, one of the other advantages of using PropertyUtilsBean is that it
>>>>caches the introspected data. Conceivably, this would also be a useful
>>>>feature for the getDynaProperties method. However, here we have a
>>>>problem: since DynaClass doesn't have any way to enforce that its
>>>>implementations implement HashCode, there's no way to use the same map
>>>>caching strategy as is used for the PropertyDescriptors. This
>>>>illustrates a larger issue, which is that DynaClass objects aren't
>>>>singletons like Class objects are.
>>>>
>>>>To resolve this, I propose adding an AbstractDynaClass base class that
>>>>implements hashCode() and equals() based upon the public methods
>>>>available in DynaClass. This way, even if DynaClasses aren't singletons,
>>>>they can be used for hash keys. It might be also useful to implement a
>>>>registry for DynaClasses in this abstract class to provide
>>>>singleton-like functionality. Existing DynaClass implementations would
>>>>be modified to extend AbstractDynaClass.
>>>>
>>>>Any thoughts?
>>>>
>>>>Kris
>>>>
>>>>
>>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
OK, you're off my Christmas Card list now Paulo.
Niall
----- Original Message -----
From: "Paulo Gaspar" <de...@kebom.net>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Saturday, December 04, 2004 3:41 PM
Subject: Re: [beanutils] PropertyUtils & DynaBeans
> Niall,
>
> What looks pretty clear is that YOU do not know what he is talking about.
>
> On caching: he is only talking about caching introspection information,
> not the actual beans.
>
> Go and study what the DynaBean/DynaClass implementations are all about.
> Do your home work if you really care about them.
>
> Regards,
> Paulo Gaspar
>
> Niall Pemberton wrote:
>
> >Maybe you could spell out the issues with PropertyUtils and DynaBeans and
> >the methods involved and what you're trying to do because its not clear
what
> >your trying to resolve.
> >
> >I'm don't see much value in the getDynaProperties() method being in
> >PropertyUtils - all you need to do is make eveything a DynaBean then you
can
> >get the DynaProperties and do whatever you want using the existing
> >DynaBean/DynaClass methods - no need for PropertyUtils at all.
> >
> >DynaBean dynaBean = (bean instanceof DynaBean)
> > ? (DynaBean)bean : new WrapDynaBean(bean);
> >
> >For caching to work people are going to have to change how they create
> >DynaBeans and I believe its better left up to the environment they're
being
> >used in to implement a caching mechanism - Struts does this for its
> >DynaActionForm implementation.
> >
> >Niall
> >
> >----- Original Message -----
> >From: "Kris Nuttycombe" <Kr...@noaa.gov>
> >To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
> >Sent: Saturday, December 04, 2004 12:55 AM
> >Subject: [beanutils] PropertyUtils & DynaBeans
> >
> >
> >
> >
> >>Hi, all,
> >>
> >>As it currently stands, PropertyUtils doesn't support DynaBeans for a
> >>number of its methods. It doesn't make much sense to return
> >>PropertyDescriptors for DynaBeans, but it's no great pain to use
> >>WrapDynaClass on an ordinary class and thereby be able to introspect
> >>either regular beans or DynaBeans using the same interface. To support
> >>this, I'd like to add a method with the signature:
> >>
> >>DynaProperty[] getDynaProperties(Object bean)
> >>
> >>to PropertyUtilsBean, with a corresponding static method in
PropertyUtils.
> >>
> >>Now, one of the other advantages of using PropertyUtilsBean is that it
> >>caches the introspected data. Conceivably, this would also be a useful
> >>feature for the getDynaProperties method. However, here we have a
> >>problem: since DynaClass doesn't have any way to enforce that its
> >>implementations implement HashCode, there's no way to use the same map
> >>caching strategy as is used for the PropertyDescriptors. This
> >>illustrates a larger issue, which is that DynaClass objects aren't
> >>singletons like Class objects are.
> >>
> >>To resolve this, I propose adding an AbstractDynaClass base class that
> >>implements hashCode() and equals() based upon the public methods
> >>available in DynaClass. This way, even if DynaClasses aren't singletons,
> >>they can be used for hash keys. It might be also useful to implement a
> >>registry for DynaClasses in this abstract class to provide
> >>singleton-like functionality. Existing DynaClass implementations would
> >>be modified to extend AbstractDynaClass.
> >>
> >>Any thoughts?
> >>
> >>Kris
> >>
> >>
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Paulo Gaspar <de...@kebom.net>.
Niall,
What looks pretty clear is that YOU do not know what he is talking about.
On caching: he is only talking about caching introspection information,
not the actual beans.
Go and study what the DynaBean/DynaClass implementations are all about.
Do your home work if you really care about them.
Regards,
Paulo Gaspar
Niall Pemberton wrote:
>Maybe you could spell out the issues with PropertyUtils and DynaBeans and
>the methods involved and what you're trying to do because its not clear what
>your trying to resolve.
>
>I'm don't see much value in the getDynaProperties() method being in
>PropertyUtils - all you need to do is make eveything a DynaBean then you can
>get the DynaProperties and do whatever you want using the existing
>DynaBean/DynaClass methods - no need for PropertyUtils at all.
>
>DynaBean dynaBean = (bean instanceof DynaBean)
> ? (DynaBean)bean : new WrapDynaBean(bean);
>
>For caching to work people are going to have to change how they create
>DynaBeans and I believe its better left up to the environment they're being
>used in to implement a caching mechanism - Struts does this for its
>DynaActionForm implementation.
>
>Niall
>
>----- Original Message -----
>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
>Sent: Saturday, December 04, 2004 12:55 AM
>Subject: [beanutils] PropertyUtils & DynaBeans
>
>
>
>
>>Hi, all,
>>
>>As it currently stands, PropertyUtils doesn't support DynaBeans for a
>>number of its methods. It doesn't make much sense to return
>>PropertyDescriptors for DynaBeans, but it's no great pain to use
>>WrapDynaClass on an ordinary class and thereby be able to introspect
>>either regular beans or DynaBeans using the same interface. To support
>>this, I'd like to add a method with the signature:
>>
>>DynaProperty[] getDynaProperties(Object bean)
>>
>>to PropertyUtilsBean, with a corresponding static method in PropertyUtils.
>>
>>Now, one of the other advantages of using PropertyUtilsBean is that it
>>caches the introspected data. Conceivably, this would also be a useful
>>feature for the getDynaProperties method. However, here we have a
>>problem: since DynaClass doesn't have any way to enforce that its
>>implementations implement HashCode, there's no way to use the same map
>>caching strategy as is used for the PropertyDescriptors. This
>>illustrates a larger issue, which is that DynaClass objects aren't
>>singletons like Class objects are.
>>
>>To resolve this, I propose adding an AbstractDynaClass base class that
>>implements hashCode() and equals() based upon the public methods
>>available in DynaClass. This way, even if DynaClasses aren't singletons,
>>they can be used for hash keys. It might be also useful to implement a
>>registry for DynaClasses in this abstract class to provide
>>singleton-like functionality. Existing DynaClass implementations would
>>be modified to extend AbstractDynaClass.
>>
>>Any thoughts?
>>
>>Kris
>>
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Kris Nuttycombe <Kr...@noaa.gov>.
Niall Pemberton wrote:
>Maybe its not a bad idea, but then again there are easier methods - I uses
>caches which use the "name" of the DyanClass. Another issue is it would work
>for your "regular" DynaClass, but those that also implement the
>MutableDynaClass (e.g. LazyDynaClass) would have problems since dyna
>properties can be added/removed which would change the hash code.
>
>
This is a bit of a problem, but I suspect that in most cases where
you're using a DynaClass as a hash key you probably
won't be mutating it. In any case, the general contract of hashCode only
states that hash codes must remain constant so long
as no properties that are used in the equals() comparison are modified,
so this shouldn't be unexpected behavior, and it is
in compliance with the general contract of equals().
>Also since DynaClass is just an interface we could change the
>implementations provided in BeanUtils but theres no way of guaranteeing that
>custom implementations outside of BeanUtils would implement it in this
>standard fashion.
>
I think that a two-pronged approach to this issue is probably the best:
provide an abstract base class for DynaClass,
as I was suggesting, but have that delegate to a DynaUtils class as you
suggest. This makes the functionality available
to anyone who's implementing DynaClass, but gives them the flexibility
not to use it if it's not appropriate for their purposes.
>Perhaps the best way would be to provide a generateHashCode(DynaClass)
>method and compare DynaClasses method (and getDyanProperties() method) in
>one of the utils beans to make it easier for people to implement these types
>of behaviours - maybe a new DynaUtils would be a good idea for this?
>
>If you think its worth it then submit a bugzilla ticket, preferably with
>code :-)
>
>Niall
>
>P.S. toString() utility methods for DynaClass and DynaBean might make good
>additons as well.
>
>
I'll add builder methods for toString() to the DynaUtils class as well.
One question, though: there doesn't appear to be any
public method to retrieve the keys of a mapped property or the number of
items available from an indexed property.
I can go ahead and post my implementation to Bugzilla without supporting
these property types, but it seems like these
might be important methods to add to DynaClass in some future release.
Kris
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Paulo Gaspar <de...@kebom.net>.
Hi Niall,
Obviously, I must apologise for previous remarks, since you are up to
date with the DynaBean stuff implementation and I am completelly outdated.
But now I am curious: how does the whole introspection caching stuff
work if there are multiple class loaders? Is there some provision to
handle using classe loaded by multiple sibling classloaders or should
its use be restricted to a "single classloader universe"?
With my best regards,
Paulo Gaspar
Niall Pemberton wrote:
>My mistake - you're right on the getDynaProperties() implementation.
>
>Maybe its not a bad idea, but then again there are easier methods - I uses
>caches which use the "name" of the DyanClass. Another issue is it would work
>for your "regular" DynaClass, but those that also implement the
>MutableDynaClass (e.g. LazyDynaClass) would have problems since dyna
>properties can be added/removed which would change the hash code.
>
>Also since DynaClass is just an interface we could change the
>implementations provided in BeanUtils but theres no way of guaranteeing that
>custom implementations outside of BeanUtils would implement it in this
>standard fashion.
>
>Perhaps the best way would be to provide a generateHashCode(DynaClass)
>method and compare DynaClasses method (and getDyanProperties() method) in
>one of the utils beans to make it easier for people to implement these types
>of behaviours - maybe a new DynaUtils would be a good idea for this?
>
>If you think its worth it then submit a bugzilla ticket, preferably with
>code :-)
>
>Niall
>
>P.S. toString() utility methods for DynaClass and DynaBean might make good
>additons as well.
>
>----- Original Message -----
>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
>Sent: Monday, December 06, 2004 8:40 PM
>Subject: Re: [beanutils] PropertyUtils & DynaBeans
>
>
>
>
>>Ah, I hadn't realized that WrapDynaClass cached automatically. That
>>basically solves my problem with the
>>PropertyUtils.get*PropertyDescriptors() methods not supporting DynaBeans.
>>
>>I still think it wouldn't be a bad idea for DynaClasses to implement
>>hashCode() and equals() in a standard fasion.
>>
>>Kris
>>
>>As an aside, you probably mean this, right?
>>
>>public DynaProperty[] getDynaProperties(Object bean) {
>> return (bean instanceof DynaBean)
>> ? ((DynaBean)bean).getDynaClass().getDynaProperties()
>> :
>>
>>
>WrapDynaClass.createDynaClass(bean.getClass()).getDynaProperties();
>
>
>>}
>>
>>
>>
>>Niall Pemberton wrote:
>>
>>
>>
>>>OK the performance issue is a good point, but I don't agree with your
>>>reasoning to include it in PropertyUtils.
>>>
>>>WrapDynaClass instances are singletons as it already caches instances of
>>>itself - (it's constructor is private and new WrapDynaClass intances are
>>>created with the static createDynaClass() method which uses a cache).
>>>
>>>So I guess your proposed getDynaProperties(Object bean) method would look
>>>something like
>>>
>>>public DynaProperty[] getDynaProperties(Object bean) {
>>> return (bean instanceof DynaBean)
>>> ? ((DynaBean)bean).getDynaClass().getDynaProperties()
>>> : WrapDynaBean.createDynaClass(bean).getDynaProperties();
>>>}
>>>
>>>...with no need to cache anything in PropertyUtils. Maybe this is a nice
>>>convenience method, but I'm pretty neutral about whether it should be
>>>
>>>
>added
>
>
>>>to the API or not.
>>>
>>>
>>>Niall
>>>
>>>
>>>----- Original Message -----
>>>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>>>To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
>>>Sent: Monday, December 06, 2004 5:31 PM
>>>Subject: Re: [beanutils] PropertyUtils & DynaBeans
>>>
>>>
>>>
>>>
>>>
>>>
>>>>The main issue is that my code needs to perform bean introspection on an
>>>>Object without knowing whether that object is a regular bean or a
>>>>DynaBean. Sure, I could add a clause like you suggest everywhere I want
>>>>to do this, but it seems like this is really something that should be
>>>>handled in PropertyUtils so that introspection information can be
>>>>cached. The system I'm working on processes tens of thousands of objects
>>>>at a pass, so creating a new WrapDynaBean for each object when a lookup
>>>>on the classlass would suffice seems excessive.
>>>>
>>>>Kris
>>>>
>>>>
>>>>
>>>>Niall Pemberton wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Maybe you could spell out the issues with PropertyUtils and DynaBeans
>>>>>
>>>>>
>and
>
>
>>>>>the methods involved and what you're trying to do because its not clear
>>>>>
>>>>>
>>>>>
>>>>>
>>>what
>>>
>>>
>>>
>>>
>>>>>your trying to resolve.
>>>>>
>>>>>I'm don't see much value in the getDynaProperties() method being in
>>>>>PropertyUtils - all you need to do is make eveything a DynaBean then
>>>>>
>>>>>
>you
>
>
>>>>>
>>>>>
>>>can
>>>
>>>
>>>
>>>
>>>>>get the DynaProperties and do whatever you want using the existing
>>>>>DynaBean/DynaClass methods - no need for PropertyUtils at all.
>>>>>
>>>>>DynaBean dynaBean = (bean instanceof DynaBean)
>>>>> ? (DynaBean)bean : new WrapDynaBean(bean);
>>>>>
>>>>>For caching to work people are going to have to change how they create
>>>>>DynaBeans and I believe its better left up to the environment they're
>>>>>
>>>>>
>>>>>
>>>>>
>>>being
>>>
>>>
>>>
>>>
>>>>>used in to implement a caching mechanism - Struts does this for its
>>>>>DynaActionForm implementation.
>>>>>
>>>>>Niall
>>>>>
>>>>>----- Original Message -----
>>>>>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>>>>>To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
>>>>>Sent: Saturday, December 04, 2004 12:55 AM
>>>>>Subject: [beanutils] PropertyUtils & DynaBeans
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Hi, all,
>>>>>>
>>>>>>As it currently stands, PropertyUtils doesn't support DynaBeans for a
>>>>>>number of its methods. It doesn't make much sense to return
>>>>>>PropertyDescriptors for DynaBeans, but it's no great pain to use
>>>>>>WrapDynaClass on an ordinary class and thereby be able to introspect
>>>>>>either regular beans or DynaBeans using the same interface. To support
>>>>>>this, I'd like to add a method with the signature:
>>>>>>
>>>>>>DynaProperty[] getDynaProperties(Object bean)
>>>>>>
>>>>>>to PropertyUtilsBean, with a corresponding static method in
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>PropertyUtils.
>>>
>>>
>>>
>>>
>>>>>>Now, one of the other advantages of using PropertyUtilsBean is that it
>>>>>>caches the introspected data. Conceivably, this would also be a useful
>>>>>>feature for the getDynaProperties method. However, here we have a
>>>>>>problem: since DynaClass doesn't have any way to enforce that its
>>>>>>implementations implement HashCode, there's no way to use the same map
>>>>>>caching strategy as is used for the PropertyDescriptors. This
>>>>>>illustrates a larger issue, which is that DynaClass objects aren't
>>>>>>singletons like Class objects are.
>>>>>>
>>>>>>To resolve this, I propose adding an AbstractDynaClass base class that
>>>>>>implements hashCode() and equals() based upon the public methods
>>>>>>available in DynaClass. This way, even if DynaClasses aren't
>>>>>>
>>>>>>
>singletons,
>
>
>>>>>>they can be used for hash keys. It might be also useful to implement a
>>>>>>registry for DynaClasses in this abstract class to provide
>>>>>>singleton-like functionality. Existing DynaClass implementations would
>>>>>>be modified to extend AbstractDynaClass.
>>>>>>
>>>>>>Any thoughts?
>>>>>>
>>>>>>Kris
>>>>>>
>>>>>>
>>>>>>
>>>>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
My mistake - you're right on the getDynaProperties() implementation.
Maybe its not a bad idea, but then again there are easier methods - I uses
caches which use the "name" of the DyanClass. Another issue is it would work
for your "regular" DynaClass, but those that also implement the
MutableDynaClass (e.g. LazyDynaClass) would have problems since dyna
properties can be added/removed which would change the hash code.
Also since DynaClass is just an interface we could change the
implementations provided in BeanUtils but theres no way of guaranteeing that
custom implementations outside of BeanUtils would implement it in this
standard fashion.
Perhaps the best way would be to provide a generateHashCode(DynaClass)
method and compare DynaClasses method (and getDyanProperties() method) in
one of the utils beans to make it easier for people to implement these types
of behaviours - maybe a new DynaUtils would be a good idea for this?
If you think its worth it then submit a bugzilla ticket, preferably with
code :-)
Niall
P.S. toString() utility methods for DynaClass and DynaBean might make good
additons as well.
----- Original Message -----
From: "Kris Nuttycombe" <Kr...@noaa.gov>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Monday, December 06, 2004 8:40 PM
Subject: Re: [beanutils] PropertyUtils & DynaBeans
> Ah, I hadn't realized that WrapDynaClass cached automatically. That
> basically solves my problem with the
> PropertyUtils.get*PropertyDescriptors() methods not supporting DynaBeans.
>
> I still think it wouldn't be a bad idea for DynaClasses to implement
> hashCode() and equals() in a standard fasion.
>
> Kris
>
> As an aside, you probably mean this, right?
>
> public DynaProperty[] getDynaProperties(Object bean) {
> return (bean instanceof DynaBean)
> ? ((DynaBean)bean).getDynaClass().getDynaProperties()
> :
WrapDynaClass.createDynaClass(bean.getClass()).getDynaProperties();
> }
>
>
>
> Niall Pemberton wrote:
>
> >OK the performance issue is a good point, but I don't agree with your
> >reasoning to include it in PropertyUtils.
> >
> >WrapDynaClass instances are singletons as it already caches instances of
> >itself - (it's constructor is private and new WrapDynaClass intances are
> >created with the static createDynaClass() method which uses a cache).
> >
> >So I guess your proposed getDynaProperties(Object bean) method would look
> >something like
> >
> >public DynaProperty[] getDynaProperties(Object bean) {
> > return (bean instanceof DynaBean)
> > ? ((DynaBean)bean).getDynaClass().getDynaProperties()
> > : WrapDynaBean.createDynaClass(bean).getDynaProperties();
> >}
> >
> >...with no need to cache anything in PropertyUtils. Maybe this is a nice
> >convenience method, but I'm pretty neutral about whether it should be
added
> >to the API or not.
> >
> >
> >Niall
> >
> >
> >----- Original Message -----
> >From: "Kris Nuttycombe" <Kr...@noaa.gov>
> >To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> >Sent: Monday, December 06, 2004 5:31 PM
> >Subject: Re: [beanutils] PropertyUtils & DynaBeans
> >
> >
> >
> >
> >>The main issue is that my code needs to perform bean introspection on an
> >>Object without knowing whether that object is a regular bean or a
> >>DynaBean. Sure, I could add a clause like you suggest everywhere I want
> >>to do this, but it seems like this is really something that should be
> >>handled in PropertyUtils so that introspection information can be
> >>cached. The system I'm working on processes tens of thousands of objects
> >>at a pass, so creating a new WrapDynaBean for each object when a lookup
> >>on the classlass would suffice seems excessive.
> >>
> >>Kris
> >>
> >>
> >>
> >>Niall Pemberton wrote:
> >>
> >>
> >>
> >>>Maybe you could spell out the issues with PropertyUtils and DynaBeans
and
> >>>the methods involved and what you're trying to do because its not clear
> >>>
> >>>
> >what
> >
> >
> >>>your trying to resolve.
> >>>
> >>>I'm don't see much value in the getDynaProperties() method being in
> >>>PropertyUtils - all you need to do is make eveything a DynaBean then
you
> >>>
> >>>
> >can
> >
> >
> >>>get the DynaProperties and do whatever you want using the existing
> >>>DynaBean/DynaClass methods - no need for PropertyUtils at all.
> >>>
> >>>DynaBean dynaBean = (bean instanceof DynaBean)
> >>> ? (DynaBean)bean : new WrapDynaBean(bean);
> >>>
> >>>For caching to work people are going to have to change how they create
> >>>DynaBeans and I believe its better left up to the environment they're
> >>>
> >>>
> >being
> >
> >
> >>>used in to implement a caching mechanism - Struts does this for its
> >>>DynaActionForm implementation.
> >>>
> >>>Niall
> >>>
> >>>----- Original Message -----
> >>>From: "Kris Nuttycombe" <Kr...@noaa.gov>
> >>>To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
> >>>Sent: Saturday, December 04, 2004 12:55 AM
> >>>Subject: [beanutils] PropertyUtils & DynaBeans
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>>Hi, all,
> >>>>
> >>>>As it currently stands, PropertyUtils doesn't support DynaBeans for a
> >>>>number of its methods. It doesn't make much sense to return
> >>>>PropertyDescriptors for DynaBeans, but it's no great pain to use
> >>>>WrapDynaClass on an ordinary class and thereby be able to introspect
> >>>>either regular beans or DynaBeans using the same interface. To support
> >>>>this, I'd like to add a method with the signature:
> >>>>
> >>>>DynaProperty[] getDynaProperties(Object bean)
> >>>>
> >>>>to PropertyUtilsBean, with a corresponding static method in
> >>>>
> >>>>
> >PropertyUtils.
> >
> >
> >>>>Now, one of the other advantages of using PropertyUtilsBean is that it
> >>>>caches the introspected data. Conceivably, this would also be a useful
> >>>>feature for the getDynaProperties method. However, here we have a
> >>>>problem: since DynaClass doesn't have any way to enforce that its
> >>>>implementations implement HashCode, there's no way to use the same map
> >>>>caching strategy as is used for the PropertyDescriptors. This
> >>>>illustrates a larger issue, which is that DynaClass objects aren't
> >>>>singletons like Class objects are.
> >>>>
> >>>>To resolve this, I propose adding an AbstractDynaClass base class that
> >>>>implements hashCode() and equals() based upon the public methods
> >>>>available in DynaClass. This way, even if DynaClasses aren't
singletons,
> >>>>they can be used for hash keys. It might be also useful to implement a
> >>>>registry for DynaClasses in this abstract class to provide
> >>>>singleton-like functionality. Existing DynaClass implementations would
> >>>>be modified to extend AbstractDynaClass.
> >>>>
> >>>>Any thoughts?
> >>>>
> >>>>Kris
> >>>>
> >>>>
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> >
> >
>
> --
> =====================================================
> Kris Nuttycombe
> Associate Scientist
> Geospatial Data Services Group
> CIRES, National Geophysical Data Center/NOAA
> (303) 497-6337
> Kris.Nuttycombe@noaa.gov
> =====================================================
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Kris Nuttycombe <Kr...@noaa.gov>.
Ah, I hadn't realized that WrapDynaClass cached automatically. That
basically solves my problem with the
PropertyUtils.get*PropertyDescriptors() methods not supporting DynaBeans.
I still think it wouldn't be a bad idea for DynaClasses to implement
hashCode() and equals() in a standard fasion.
Kris
As an aside, you probably mean this, right?
public DynaProperty[] getDynaProperties(Object bean) {
return (bean instanceof DynaBean)
? ((DynaBean)bean).getDynaClass().getDynaProperties()
: WrapDynaClass.createDynaClass(bean.getClass()).getDynaProperties();
}
Niall Pemberton wrote:
>OK the performance issue is a good point, but I don't agree with your
>reasoning to include it in PropertyUtils.
>
>WrapDynaClass instances are singletons as it already caches instances of
>itself - (it's constructor is private and new WrapDynaClass intances are
>created with the static createDynaClass() method which uses a cache).
>
>So I guess your proposed getDynaProperties(Object bean) method would look
>something like
>
>public DynaProperty[] getDynaProperties(Object bean) {
> return (bean instanceof DynaBean)
> ? ((DynaBean)bean).getDynaClass().getDynaProperties()
> : WrapDynaBean.createDynaClass(bean).getDynaProperties();
>}
>
>...with no need to cache anything in PropertyUtils. Maybe this is a nice
>convenience method, but I'm pretty neutral about whether it should be added
>to the API or not.
>
>
>Niall
>
>
>----- Original Message -----
>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
>Sent: Monday, December 06, 2004 5:31 PM
>Subject: Re: [beanutils] PropertyUtils & DynaBeans
>
>
>
>
>>The main issue is that my code needs to perform bean introspection on an
>>Object without knowing whether that object is a regular bean or a
>>DynaBean. Sure, I could add a clause like you suggest everywhere I want
>>to do this, but it seems like this is really something that should be
>>handled in PropertyUtils so that introspection information can be
>>cached. The system I'm working on processes tens of thousands of objects
>>at a pass, so creating a new WrapDynaBean for each object when a lookup
>>on the classlass would suffice seems excessive.
>>
>>Kris
>>
>>
>>
>>Niall Pemberton wrote:
>>
>>
>>
>>>Maybe you could spell out the issues with PropertyUtils and DynaBeans and
>>>the methods involved and what you're trying to do because its not clear
>>>
>>>
>what
>
>
>>>your trying to resolve.
>>>
>>>I'm don't see much value in the getDynaProperties() method being in
>>>PropertyUtils - all you need to do is make eveything a DynaBean then you
>>>
>>>
>can
>
>
>>>get the DynaProperties and do whatever you want using the existing
>>>DynaBean/DynaClass methods - no need for PropertyUtils at all.
>>>
>>>DynaBean dynaBean = (bean instanceof DynaBean)
>>> ? (DynaBean)bean : new WrapDynaBean(bean);
>>>
>>>For caching to work people are going to have to change how they create
>>>DynaBeans and I believe its better left up to the environment they're
>>>
>>>
>being
>
>
>>>used in to implement a caching mechanism - Struts does this for its
>>>DynaActionForm implementation.
>>>
>>>Niall
>>>
>>>----- Original Message -----
>>>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>>>To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
>>>Sent: Saturday, December 04, 2004 12:55 AM
>>>Subject: [beanutils] PropertyUtils & DynaBeans
>>>
>>>
>>>
>>>
>>>
>>>
>>>>Hi, all,
>>>>
>>>>As it currently stands, PropertyUtils doesn't support DynaBeans for a
>>>>number of its methods. It doesn't make much sense to return
>>>>PropertyDescriptors for DynaBeans, but it's no great pain to use
>>>>WrapDynaClass on an ordinary class and thereby be able to introspect
>>>>either regular beans or DynaBeans using the same interface. To support
>>>>this, I'd like to add a method with the signature:
>>>>
>>>>DynaProperty[] getDynaProperties(Object bean)
>>>>
>>>>to PropertyUtilsBean, with a corresponding static method in
>>>>
>>>>
>PropertyUtils.
>
>
>>>>Now, one of the other advantages of using PropertyUtilsBean is that it
>>>>caches the introspected data. Conceivably, this would also be a useful
>>>>feature for the getDynaProperties method. However, here we have a
>>>>problem: since DynaClass doesn't have any way to enforce that its
>>>>implementations implement HashCode, there's no way to use the same map
>>>>caching strategy as is used for the PropertyDescriptors. This
>>>>illustrates a larger issue, which is that DynaClass objects aren't
>>>>singletons like Class objects are.
>>>>
>>>>To resolve this, I propose adding an AbstractDynaClass base class that
>>>>implements hashCode() and equals() based upon the public methods
>>>>available in DynaClass. This way, even if DynaClasses aren't singletons,
>>>>they can be used for hash keys. It might be also useful to implement a
>>>>registry for DynaClasses in this abstract class to provide
>>>>singleton-like functionality. Existing DynaClass implementations would
>>>>be modified to extend AbstractDynaClass.
>>>>
>>>>Any thoughts?
>>>>
>>>>Kris
>>>>
>>>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
>
--
=====================================================
Kris Nuttycombe
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6337
Kris.Nuttycombe@noaa.gov
=====================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
OK the performance issue is a good point, but I don't agree with your
reasoning to include it in PropertyUtils.
WrapDynaClass instances are singletons as it already caches instances of
itself - (it's constructor is private and new WrapDynaClass intances are
created with the static createDynaClass() method which uses a cache).
So I guess your proposed getDynaProperties(Object bean) method would look
something like
public DynaProperty[] getDynaProperties(Object bean) {
return (bean instanceof DynaBean)
? ((DynaBean)bean).getDynaClass().getDynaProperties()
: WrapDynaBean.createDynaClass(bean).getDynaProperties();
}
...with no need to cache anything in PropertyUtils. Maybe this is a nice
convenience method, but I'm pretty neutral about whether it should be added
to the API or not.
Niall
----- Original Message -----
From: "Kris Nuttycombe" <Kr...@noaa.gov>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Monday, December 06, 2004 5:31 PM
Subject: Re: [beanutils] PropertyUtils & DynaBeans
> The main issue is that my code needs to perform bean introspection on an
> Object without knowing whether that object is a regular bean or a
> DynaBean. Sure, I could add a clause like you suggest everywhere I want
> to do this, but it seems like this is really something that should be
> handled in PropertyUtils so that introspection information can be
> cached. The system I'm working on processes tens of thousands of objects
> at a pass, so creating a new WrapDynaBean for each object when a lookup
> on the classlass would suffice seems excessive.
>
> Kris
>
>
>
> Niall Pemberton wrote:
>
> >Maybe you could spell out the issues with PropertyUtils and DynaBeans and
> >the methods involved and what you're trying to do because its not clear
what
> >your trying to resolve.
> >
> >I'm don't see much value in the getDynaProperties() method being in
> >PropertyUtils - all you need to do is make eveything a DynaBean then you
can
> >get the DynaProperties and do whatever you want using the existing
> >DynaBean/DynaClass methods - no need for PropertyUtils at all.
> >
> >DynaBean dynaBean = (bean instanceof DynaBean)
> > ? (DynaBean)bean : new WrapDynaBean(bean);
> >
> >For caching to work people are going to have to change how they create
> >DynaBeans and I believe its better left up to the environment they're
being
> >used in to implement a caching mechanism - Struts does this for its
> >DynaActionForm implementation.
> >
> >Niall
> >
> >----- Original Message -----
> >From: "Kris Nuttycombe" <Kr...@noaa.gov>
> >To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
> >Sent: Saturday, December 04, 2004 12:55 AM
> >Subject: [beanutils] PropertyUtils & DynaBeans
> >
> >
> >
> >
> >>Hi, all,
> >>
> >>As it currently stands, PropertyUtils doesn't support DynaBeans for a
> >>number of its methods. It doesn't make much sense to return
> >>PropertyDescriptors for DynaBeans, but it's no great pain to use
> >>WrapDynaClass on an ordinary class and thereby be able to introspect
> >>either regular beans or DynaBeans using the same interface. To support
> >>this, I'd like to add a method with the signature:
> >>
> >>DynaProperty[] getDynaProperties(Object bean)
> >>
> >>to PropertyUtilsBean, with a corresponding static method in
PropertyUtils.
> >>
> >>Now, one of the other advantages of using PropertyUtilsBean is that it
> >>caches the introspected data. Conceivably, this would also be a useful
> >>feature for the getDynaProperties method. However, here we have a
> >>problem: since DynaClass doesn't have any way to enforce that its
> >>implementations implement HashCode, there's no way to use the same map
> >>caching strategy as is used for the PropertyDescriptors. This
> >>illustrates a larger issue, which is that DynaClass objects aren't
> >>singletons like Class objects are.
> >>
> >>To resolve this, I propose adding an AbstractDynaClass base class that
> >>implements hashCode() and equals() based upon the public methods
> >>available in DynaClass. This way, even if DynaClasses aren't singletons,
> >>they can be used for hash keys. It might be also useful to implement a
> >>registry for DynaClasses in this abstract class to provide
> >>singleton-like functionality. Existing DynaClass implementations would
> >>be modified to extend AbstractDynaClass.
> >>
> >>Any thoughts?
> >>
> >>Kris
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Kris Nuttycombe <Kr...@noaa.gov>.
The main issue is that my code needs to perform bean introspection on an
Object without knowing whether that object is a regular bean or a
DynaBean. Sure, I could add a clause like you suggest everywhere I want
to do this, but it seems like this is really something that should be
handled in PropertyUtils so that introspection information can be
cached. The system I'm working on processes tens of thousands of objects
at a pass, so creating a new WrapDynaBean for each object when a lookup
on the classlass would suffice seems excessive.
Kris
Niall Pemberton wrote:
>Maybe you could spell out the issues with PropertyUtils and DynaBeans and
>the methods involved and what you're trying to do because its not clear what
>your trying to resolve.
>
>I'm don't see much value in the getDynaProperties() method being in
>PropertyUtils - all you need to do is make eveything a DynaBean then you can
>get the DynaProperties and do whatever you want using the existing
>DynaBean/DynaClass methods - no need for PropertyUtils at all.
>
>DynaBean dynaBean = (bean instanceof DynaBean)
> ? (DynaBean)bean : new WrapDynaBean(bean);
>
>For caching to work people are going to have to change how they create
>DynaBeans and I believe its better left up to the environment they're being
>used in to implement a caching mechanism - Struts does this for its
>DynaActionForm implementation.
>
>Niall
>
>----- Original Message -----
>From: "Kris Nuttycombe" <Kr...@noaa.gov>
>To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
>Sent: Saturday, December 04, 2004 12:55 AM
>Subject: [beanutils] PropertyUtils & DynaBeans
>
>
>
>
>>Hi, all,
>>
>>As it currently stands, PropertyUtils doesn't support DynaBeans for a
>>number of its methods. It doesn't make much sense to return
>>PropertyDescriptors for DynaBeans, but it's no great pain to use
>>WrapDynaClass on an ordinary class and thereby be able to introspect
>>either regular beans or DynaBeans using the same interface. To support
>>this, I'd like to add a method with the signature:
>>
>>DynaProperty[] getDynaProperties(Object bean)
>>
>>to PropertyUtilsBean, with a corresponding static method in PropertyUtils.
>>
>>Now, one of the other advantages of using PropertyUtilsBean is that it
>>caches the introspected data. Conceivably, this would also be a useful
>>feature for the getDynaProperties method. However, here we have a
>>problem: since DynaClass doesn't have any way to enforce that its
>>implementations implement HashCode, there's no way to use the same map
>>caching strategy as is used for the PropertyDescriptors. This
>>illustrates a larger issue, which is that DynaClass objects aren't
>>singletons like Class objects are.
>>
>>To resolve this, I propose adding an AbstractDynaClass base class that
>>implements hashCode() and equals() based upon the public methods
>>available in DynaClass. This way, even if DynaClasses aren't singletons,
>>they can be used for hash keys. It might be also useful to implement a
>>registry for DynaClasses in this abstract class to provide
>>singleton-like functionality. Existing DynaClass implementations would
>>be modified to extend AbstractDynaClass.
>>
>>Any thoughts?
>>
>>Kris
>>
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
>
--
=====================================================
Kris Nuttycombe
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6337
Kris.Nuttycombe@noaa.gov
=====================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [beanutils] PropertyUtils & DynaBeans
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Maybe you could spell out the issues with PropertyUtils and DynaBeans and
the methods involved and what you're trying to do because its not clear what
your trying to resolve.
I'm don't see much value in the getDynaProperties() method being in
PropertyUtils - all you need to do is make eveything a DynaBean then you can
get the DynaProperties and do whatever you want using the existing
DynaBean/DynaClass methods - no need for PropertyUtils at all.
DynaBean dynaBean = (bean instanceof DynaBean)
? (DynaBean)bean : new WrapDynaBean(bean);
For caching to work people are going to have to change how they create
DynaBeans and I believe its better left up to the environment they're being
used in to implement a caching mechanism - Struts does this for its
DynaActionForm implementation.
Niall
----- Original Message -----
From: "Kris Nuttycombe" <Kr...@noaa.gov>
To: "Commons Developers Jakarta" <co...@jakarta.apache.org>
Sent: Saturday, December 04, 2004 12:55 AM
Subject: [beanutils] PropertyUtils & DynaBeans
> Hi, all,
>
> As it currently stands, PropertyUtils doesn't support DynaBeans for a
> number of its methods. It doesn't make much sense to return
> PropertyDescriptors for DynaBeans, but it's no great pain to use
> WrapDynaClass on an ordinary class and thereby be able to introspect
> either regular beans or DynaBeans using the same interface. To support
> this, I'd like to add a method with the signature:
>
> DynaProperty[] getDynaProperties(Object bean)
>
> to PropertyUtilsBean, with a corresponding static method in PropertyUtils.
>
> Now, one of the other advantages of using PropertyUtilsBean is that it
> caches the introspected data. Conceivably, this would also be a useful
> feature for the getDynaProperties method. However, here we have a
> problem: since DynaClass doesn't have any way to enforce that its
> implementations implement HashCode, there's no way to use the same map
> caching strategy as is used for the PropertyDescriptors. This
> illustrates a larger issue, which is that DynaClass objects aren't
> singletons like Class objects are.
>
> To resolve this, I propose adding an AbstractDynaClass base class that
> implements hashCode() and equals() based upon the public methods
> available in DynaClass. This way, even if DynaClasses aren't singletons,
> they can be used for hash keys. It might be also useful to implement a
> registry for DynaClasses in this abstract class to provide
> singleton-like functionality. Existing DynaClass implementations would
> be modified to extend AbstractDynaClass.
>
> Any thoughts?
>
> Kris
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org