commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simon <simon.kitch...@chello.at>
Subject Re: Re:[BeanUtils] BeanUtils and Introspector
Date Wed, 19 Dec 2007 19:58:45 GMT
Hi Roshan,

When asked to introspect class Foo, the introspector first looks for a
class FooBeanInfo. If that is not present then it uses reflection to
iterate over the methods on class Foo and look for ones that match the
"bean property" naming conventions. But if FooBeanInfo exists, then the
introspector asks it for info about the properties of Foo, and does no
reflection at all.

So you can write a FooBeanInfo class that configures "properties" for
*class* Foo in any way you want, ie it could be configurable at runtime.

Note that this would allow you to dynamically add a property to *class
Foo*, but not to an *instance* of class Foo. AFAIK that was simply never
expected by the javabeans spec designers and I doubt that will ever be
possible.

Note also that (if I remember correctly) the introspector caches data.
This is particularly important for the default case (look at method
names) because that is very slow. I don't know if it also caches data
returned by custom BeanInfo classes.

The BeanUtils library provides a DynaBean class (originally invented by
the Struts project) which is a kind of Map. It then also provides
methods similar to the Introspector utils that work on either real bean
classes or DynaBean classes. You can therefore write code that uses the
BeanUtils introspector to access properties on objects without caring
whether they are "real" beans or DynaBeans. But it does not allow code
that uses the *standard* java Introspector to dynamically detect
properties.

Maybe you should be using Groovy?

Regards,

Simon

On Wed, 2007-12-19 at 14:27 -0500, Roshan A. Punnoose wrote:
> Thanks!
> 
> The article looks great.
> 
> I just tried the code, but it doesn't seem to generate getters and
> setters dynamically, which seem to be needed by the JavaBeans
> Introspector to recognize properties.
> 
> Roshan
> 
> -----Original Message-----
> From: Ole Ersoy [mailto:ole.ersoy@gmail.com] 
> Sent: Wednesday, December 19, 2007 2:03 PM
> To: Jakarta Commons Users List
> Subject: Re: BeanUtils and Introspector
> 
> Hi Roshan,
> 
> I just happened to see this, and the JavaBeans Introspector stuff is
> completely new to me.  However both Eclipse EMF beans / modeled classes
> and Apache Tuscany SDO (Service Data Objects) support adding properties
> dynamically.  There's a really good article on how to do it using EMF
> here:
> 
> http://www.devx.com/Java/Article/29093
> 
> Sorry I could not give you a more direct answer.
> 
> Cheers,
> - Ole
> 
> 
> 
> Roshan A. Punnoose wrote:
> > Hi,
> > 
> >  
> > 
> > I didn't see this on the User Guide, but is it possible to add dynamic
> > properties to a JavaBean and have the JavaBeans Introspector pick it
> up?
> > For example, if I have an Object Temporary, and at runtime, I want to
> > add properties (getter and setter methods) to it, then use the
> > Introspector class to get these dynamic properties, is that possible?
> > 
> >  
> > 
> > Roshan
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message