The BeanInfo Interface in JAVA BEANS

The BeanInfo Interface in JAVA BEANS
The BeanInfo Interface in JAVA BEANS

ABT examine a bean and expose its features
(properties,methods and events) in a
property sheet using java.beans.Introspector class.

Introspection class uses JDK core reflection API
to discover a bean methods and then applies
the javabeans design patterns to discover the
bean features. This discovery process is INTROSPECTION

BeanInfo methods:

PropertyDescriptor[] getPropertyDescriptors();
MethodDescriptor[] getMethodDescriptors();
EventSetDescriptor[] getEventsSetDescriptors();

BeanInfo classes contains DESCRIPTORS that
precisely describe the target beans features.

The BDK implements following descriptor classes.

FeatureDescriptor =>the base class for other
descriptor classes.

BeanDescriptor => defines target bean class type
and name

PropertyDescriptor=> decribes bean properties

IndexedPropertyDescriptor=> defines index prop.

EventSetDescriptor=> describes event the target
bean fires.

MethodDescriptor => defines target bean methods


propertyDescriptor[] getPropertyDescriptors()
PropertyDescriptor background =
new PropertyDescriptor(“background”,beanclass);
….. “foreground”
….. “font”
….. “label”

Using BeanInfo to Define the Events a Bean Fires

You can explicitly “publish” the events a Bean fires by using a class that implements the BeanInfo interface. The ExplicitButton demo Bean subclasses OurButton, and provides an associated ExplicitButtonBeanInfo class. ExplicitButtonBeanInfo implements the following method to explicitly define interfaces to which ExplicitButton fires events.

public EventSetDescriptor[] getEventSetDescriptors() {
try {
EventSetDescriptor push = new EventSetDescriptor(beanClass,

EventSetDescriptor changed = new EventSetDescriptor(beanClass,

push.setDisplayName(“button push”);
changed.setDisplayName(“bound property change”);

EventSetDescriptor[] rv = { push, changed};
return rv;
} catch (IntrospectionException e) {
throw new Error(e.toString());

Drop an ExplicitButton instance in the BeanBox, and pull down the Edit|Events menu. Notice that only those interfaces explicitly exposed in the ExplicitButtonBeanInfo class are listed. No inherited capabilities are exposed

Leave a Reply