img
interest in receiving such notifications. A class that handles this event must implement the
PropertyChangeListener interface.
A Bean that has a constrained property generates an event when an attempt is made to
change its value. It also generates an event of type PropertyChangeEvent. It too is sent to objects
that previously registered an interest in receiving such notifications. However, those other
objects have the ability to veto the proposed change by throwing a PropertyVetoException.
This capability allows a Bean to operate differently according to its run-time environment.
A class that handles this event must implement the VetoableChangeListener interface.
Persistence
Persistence is the ability to save the current state of a Bean, including the values of a Bean's
properties and instance variables, to nonvolatile storage and to retrieve them at a later time.
The object serialization capabilities provided by the Java class libraries are used to provide
persistence for Beans.
The easiest way to serialize a Bean is to have it implement the java.io.Serializable interface,
which is simply a marker interface. Implementing java.io.Serializable makes serialization
automatic. Your Bean need take no other action. Automatic serialization can also be inherited.
Therefore, if any superclass of a Bean implements java.io.Serializable, then automatic
serialization is obtained. There is one important restriction: any class that implements
java.io.Serializable must supply a parameterless constructor.
When using automatic serialization, you can selectively prevent a field from being saved
through the use of the transient keyword. Thus, data members of a Bean specified as transient
will not be serialized.
If a Bean does not implement java.io.Serializable, you must provide serialization yourself,
such as by implementing java.io.Externalizable. Otherwise, containers cannot save the
configuration of your component.
Customizers
A Bean developer can provide a customizer that helps another developer configure the Bean. A
customizer can provide a step-by-step guide through the process that must be followed to use
the component in a specific context. Online documentation can also be provided. A Bean
developer has great flexibility to develop a customizer that can differentiate his or her product
in the marketplace.
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 28-1 lists the interfaces in
java.beans and provides a brief description of their functionality. Table 28-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.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home