You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Roshan A. Punnoose" <rp...@proteus-technologies.com> on 2007/12/19 20:27:01 UTC

Re:[BeanUtils] BeanUtils and Introspector

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


Re: [BeanUtils] BeanUtils and Introspector

Posted by Ole Ersoy <ol...@gmail.com>.
Hi Roshan,

The dynamic properties would first have to be added to the bean's EClass.  Then you would access the dynamic properties using EMF's reflective methods, eGet() and eSet().  So for instance if you added a property "Street"...note that you would first have to model this as an EAttribute, and then add the EAttribute to the EClass, ...anyways, assuming you added it...you would then get the property on an instance of the EClass like this:

someObject.eGet("Street");

The general sequence is to create a EClass.

Add EReferences (Representing references) and EAttributes (Representing primitive properties...non object references).

Create an instance of the EClass.  someObject = EFactory.create(myEClass);

Then later if you need to add primitive properties, you just add more EAttributes to the EClass and then create another instance.  Now the instance will have these properties, and you can set and get them using eGet and eSet.

Tuscany Service Data Objects work in a similar way.

Cheers,
- Ole







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


RE: [BeanUtils] BeanUtils and Introspector

Posted by "Roshan A. Punnoose" <rp...@proteus-technologies.com>.
Thanks!

This is exactly what I have been looking for. I think the best course
would be to look into adding a BeanInfo class to the classloader or
using the Tuscany SDO impl.

Roshan

-----Original Message-----
From: Ole Ersoy [mailto:ole.ersoy@gmail.com] 
Sent: Wednesday, December 19, 2007 3:23 PM
To: Jakarta Commons Users List
Subject: Re: [BeanUtils] BeanUtils and Introspector

Just added a few comments to Simon's comments:

simon wrote:

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

The same is true for the instances of an EMF EClass.  You would have
to the EClass instance first, then use the EClass instance to create 
and instance of the Object the EClass instance represents.  Then you
could
use eGet and eSet to get and set the properties you added to the eClass.
So
it sounds like the two processes are very similar.  

I think Tuscany SDO supports
adding properties to an existing instance at runtime.  I think that is 
what the type being "Open" means...  There's more info here:

http://java.sys-con.com/read/358059.htm

Cheers,
- Ole



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


Re: [BeanUtils] BeanUtils and Introspector

Posted by Ole Ersoy <ol...@gmail.com>.
Just added a few comments to Simon's comments:

simon wrote:

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

The same is true for the instances of an EMF EClass.  You would have
to the EClass instance first, then use the EClass instance to create 
and instance of the Object the EClass instance represents.  Then you could
use eGet and eSet to get and set the properties you added to the eClass.  So
it sounds like the two processes are very similar.  

I think Tuscany SDO supports
adding properties to an existing instance at runtime.  I think that is 
what the type being "Open" means...  There's more info here:

http://java.sys-con.com/read/358059.htm

Cheers,
- Ole



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


Re: Re:[BeanUtils] BeanUtils and Introspector

Posted by simon <si...@chello.at>.
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