The
Java Beans API
The Java Beans functionality
is provided by a set of classes and interfaces in the java.beans package. This section provides a brief overview of its
contents. Table 37-1 lists the interfaces in java.beans and provides a brief description of their functionality.
Table 37-2 lists the classes in java.beans.
Although it is beyond the
scope of this chapter to discuss all of the classes, four are of particular
interest: Introspector, PropertyDescriptor, EventSetDescriptor, and MethodDescriptor. Each is briefly
examined here.
Introspector
The Introspector class provides several static methods that support
introspection. Of most interest is getBeanInfo(
). This method returns a BeanInfo
object that can be used to obtain information about the Bean. The getBeanInfo( ) method has several
forms, including the one shown here:
static BeanInfo
getBeanInfo(Class<?> bean)
throws IntrospectionException The returned object contains information about
the Bean specified by bean.
PropertyDescriptor
The PropertyDescriptor class describes the characteristics of a Bean
property. It supports several methods that manage and describe properties. For
example, you can determine if a property is bound by calling isBound( ). To determine if a property
is constrained, call isConstrained( ).
You can obtain the name of a property by calling getName( ).
EventSetDescriptor
The EventSetDescriptor class represents a Bean event. It supports
several methods that obtain the methods that a Bean uses to add or remove event
listeners, and to otherwise manage events. For example, to obtain the method
used to add listeners, call getAddListenerMethod(
). To obtain the method used to remove listeners, call getRemoveListenerMethod( ). To obtain the type of a listener, call getListenerType( ). You can obtain the
name of an event by calling getName( ).
MethodDescriptor
The MethodDescriptor class represents a Bean method. To obtain the name
of the method, call getName( ). You
can obtain information about the method by calling getMethod( ), shown here:
Method getMethod( )
An object of type Method that describes the method is
returned.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.