BOUND PROPERTIES
Bound Property - PropertyChangeEvent
• A Bean that has a bound property generates an
event when the property is changed. The event is
of type PropertyChangeEvent and is sent to
objects that previously registered an interest in
receiving such notifications.
• The TickTock Bean is supplied with the BDK. It
generates a property change event every N
seconds. N is a property of the Bean that can be
changed via the Properties window of the BDK.
The next example builds an application that uses
the TickTock Bean to automatically control the
Colors Bean.
BOUND PROPERTY FOR TICKTOCK
BEAN
Constrained property
• A Bean that has a constrained property
generates an event when an attempt is made
to change its value. The event is of type
PropertyChangeEvent. It is sent to objects
that previously registered an interest in
receiving such notifications. Those other
objects have the ability to veto the proposed
change. This capability allows a Bean to
operate differently according to its run-time
environment.
MORE ABOUT CONSTRAINED PROPERTY
• For a constrained property, the bean keeps track
of a set of veto listeners. When a constrained
property is about to change, the listeners are
consulted about the change. Any one of the
listeners has a chance to veto the change, in
which case the property remains unchanged.
• The veto listeners are separate from the
property change listeners. Fortunately,
the java.beans package includes
a VetoableChangeSupport class that greatly
simplifies constrained properties.
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
non volatile 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
information that is particularly important are
the configuration settings.
• The easiest way to serialize a Bean is to have
it implement the java.io.Serializable interface,w
hich is simply a marker interface. Implementing j
ava.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 auto
matic serialization is obtained. There is
one important restriction: any class that impleme
nts 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
SAVING A BEAN
• To save the application, go to the menu bar of
the BeanBox and select File | Save. A dialog
box should appear, allowing you to specify the
name of a file to which the Beans and their
configuration parameters should be saved.
Supply a filename and click the OK button on
that dialog box. Exit from the BDK.
PERSISTENCE
• Start the BDK again. To restore the
application, go to the menu bar of the
BeanBox and select File | Load. A dialog box
should appear, allowing you to specify the
name of the file from which an application
should be restored. Supply the name of the
file in which the application was saved, and
click the OK button. Your application should
now be functioning.
CUSTOMIZER
• The Properties window of the BDK allows a
developer to modify the properties of a Bean.
However, this may not be the best user
interface for a complex component with many
interrelated properties. Therefore, a Bean
developer can provide a customizer that helps
another developer configure this software.
CUSTOMIZER
• 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.