wood burning stoves 2.0*
The moose likes Java in General and the fly likes Introspector calling the Base Class multiple times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Introspector calling the Base Class multiple times" Watch "Introspector calling the Base Class multiple times" New topic
Author

Introspector calling the Base Class multiple times

sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi

I am having a Java Bean C (which extends B which in turn extends A) ...and each of these Classes have the BeanInfo classes .. ABeanInfo , BBeanInfo , CBeanInfo....


And i had written my beaninfos such a way that they are optimised by extending the basebeaninfo and calling super.getPropertyDescriptors and adding them to the Descriptoirs of extra methods like

Class A
{
private String name;
public void getName()
{
}
}

Class B extends A
{
private String city ;
public void getCity
{
}
}

class ABeanInfo extends SimpleBeanInfo
{
public PropertyDescriptors[] getPropertyDescriptors()
{
// Got the property descriptor for name
// return by forming array
}
}

My Class B bean info will look like this

class BBeanInfo extends ABeanInfo
{
public PropertyDescriptors[] getPropertyDescriptors()
{
PropertyDescriptors[] baseDesc = super.getPropertyDescriptors();
// Get the property descriptor for City
// Club the base class desc and the new ones added
// return by forming array
}
}


But when i use Introspector.getBeanInfo(B.class) , the A.getPropertyDescriptors method is getting called twice (One internally by the introspector and the other when my super.get...)

How can this be avoided ?? Ofcourse after the first time , the introspector is caching the instances of BeanInfos...

If this is the implicit behaviour , can i change my BeanInfo classses in such a way that it won't get called
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Introspector calling the Base Class multiple times