Beruflich Dokumente
Kultur Dokumente
Introduction to JavaBeans:
Now create another instance of the OurButton Bean. Label it “Rotate Y” and map its
action event to the “rotateY” method of the Molecule Bean. The steps to do this are very
similar to those just described for the button labeled “Rotate X”.Test the application by clicking
these buttons and observing how the molecule moves.
Introspection:
Introspection is the automatic process of analyzing a bean’s design patterns to reveal
the bean’s properties, events and methods. Introspection asks JavaBeans components what are
the properties and events it supports. The JavaBeans API provides a great deal of Support for
introspection so as to enable the application builder tool to find out information about that
structures and functionality of a bean , we cannot think of JavaBeans technology without
considering introspection mechanism. There are two ways of support introspection. In the first
method of introspection is supported by reflection where you name methods with certain
conventions, like set/getProperty() and add/Listener(). In the second method you explicitly
expose the bean’s behavior through a class which extends SimpleBeanInfo which in turn
provides default implementation of BeanInfo interface.
Developing a Simple Bean using the BDK:
Here are the steps that you must follow to create a new Bean:
Bound Properties:
Sometimes when a Bean property changes, another object might need to be notified of
the change and react to the change, we can do this by making a property bound property.
Therefore when a bound property changes, notification of the change is sent to the interested
listeners through java.beans.PropertyChangeEvent class.
Bound properties support java.beans.PropertyChangeListener so as to receive
PropertyChangeEvent notifications. The accessor methods for a bound property are defined in
the same way as those for simple properties. However you also provide the event listener
registration methods for PropertyChangeListener classes and fire a PropertyChangeEvent
event to the PropertyChangeListener object by calling their PropertyChange methods. The
convenience java.beans.PropertyChangeSupport class enables your bean to implement these
methods. In order to listen the property change, an object must be able to add and remove
itself from listener list in the bean containing the bound property. It must also be able to
respond to the event notification method that signals a property change.
Create an instance of the TickTock Bean. The Properties window should show one
property for this component. It is “Interval” and its initial value is 5. This represents the number
of seconds that elapse between property change events generated by the TickTock Bean.
Change the value to 1.
Now you need to map events generated by the TickTock Bean into method calls on
the Colors Bean. Follow these steps:
Go to the menu bar of the BeanBox and select Edit | Events | propertyChange |
propertyChange. You should now see a line extending from the button to the cursor.
Move the cursor so that it is inside the Colors Bean display area, and click the left mouse
button. You should see the Event Target Dialog dialog box.
The dialog box allows you to choose a method that should be invoked when this event
occurs. Select the entry labeled “change” and click the OK button. You should see a
message box appear very briefly, stating that the tool is “Generating and compiling
adaptor class.”
You should now see the color of your component change every second.
Constrained Properties:
Constrained properties are more complicated that bound properties because they also
support property change listener which happen to be vetoers. i.e., the listener may accept the
property change or forbid it.
A bean property is constrained it the bean supports the
java.beans.VetoableChangeListener and java.bean.PropertyChangeEvent classes and if the set
method for this property throws a java.beans.PropertyVetoException.
The accessor methods for a constrained property are defined in the same way as those
for simple properties, with the addition that the setXXX method throws a
PropertyVetoException.
public void setPropertyName(PropertyType value)throws PropertyVetoException
{. . .}
Persistence:
Persistence means storing the data in a durable space so that is can be accessed at a
later time by the same application or another. In persistence data outlives the process that
created it. Remember if you want a class to be persisted then it should implement
java.io.Serializable.
In the context of JavaBeans we configure Beans with all its necessary configuration
setting, so that it can be later restored with same configuration setting.
Customizes:
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. 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.