How do I restore a JavaBean from a saved version?

John Zukowski

Instead of continually creating JavaBeans components and setting their state to some common setting, you can save what tends to be called a pickled version of the component, with the bean properties set to their desired value. This would be saved to a .ser file in the JAR file of the application. Then, to create a version of the bean from this prototype, you would use Beans.instantiate(...) to create an instance of the component, as in:

Beans.instantiate (null, "mypackage.MyBean");

The first argument is the class loader, where null is used if you wish to use the system class loader, instead of a custom one.

About | Sitemap | Contact