Saturday, August 20, 2016

Persistence

Persistence

Persistence is the ability to save a Bean to nonvolatile storage and retrieve it at a later time. The information that is particularly important are the configuration settings. 
Let us first see how the BDK allows you to save a set of Beans that have been configured and connected together to form an application. 
Recall our previous example involving both the Colors and TickTock Beans. The rectangular property of the Colors Bean was changed to true, and the interval property of the TickTock Bean was changed to one second. These changes can be saved. 
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. 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. Confirm that the rectangular property of the Colors Bean is true and that the interval property for the TickTock Bean is equal to one second. 
The object serialization capabilities provided by the Java class libraries are used to provide persistence for Beans. If a Bean inherits directly or indirectly from java.awt.Component, it is automatically serializable, because that class implements the java.io.Serializable interface. 
If a Bean does not inherit an implementation of the Serializable interface, you must provide this yourself. Otherwise, containers cannot save the configuration of your component. 
The transient keyword can be used to designate data members of a Bean that should not be serialized. The color variable of the Colors class is an example of such an item.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home