Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology.

Similar presentations


Presentation on theme: "Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology."— Presentation transcript:

1 Java Beans & Serialization CS-328 Dick Steflik

2 Java Beans Java based component technology –originally developed to provide java with a component technology like vbx/ocx of VB –originally used for user interface widgets –currently used for server side componets Requirements –Bean naming conventions –must be serializable, to support persistence

3 Bean Naming Conventions “setters” –set or modify a bean property value –must start with “set” “getters” –retrieve property values from a bean –must start with “get”

4 Bean Properties Simple –represents a single property and can be defined with a pair of get/set methods Indexed –represents an array of properties Bound –a bound property notifies other objects when its value changes –generates a PropertyChange event with property name, old value and new value Constrained –an object with constrained properties allows other objects to veto a constrained property value change –Constrained property listeners can veto a change by throwing a PropertyVetoException

5 Interaction Levels Properties Bean Methods Event

6 Bean Framework Network Bean Container Bean

7 Introspection the processby which a builder tool finds out which properties, methods, and events a bean supports. –searching for classes and methods that follow certain naming conventions –by querying the BeanInfo of a class BeanInfo is an interface whose methods allow the interrogation of a beans properties, methods and events

8 Introspection Introspector Methods Properties Events

9 Reflection The core APIs used by the JavaBeans Introspector class java.lang.reflect

10 a simple GasTank Bean Class Gastank implements Serializable{ private double capacity; private int percent_full; public void setCapacity(double pounds){ capacity = pounds; } public double getCapacity() { return Capacity; } public void setPercent_full( int p) { percent_full = p; } public int getPercent_full() { return percent_full; } }

11 Jarring the Bean Beans are packaged in a java archive (jar) file the jar utility comes with the JDK the jar file must be explicitly in your class path in JDK 1.2.x all AWT and Swing classes are beans

12 GUI Builders Because of a bean’s naming convention the GUIs introspector can build a property sheet for each bean automatically The GUI builder allows you to configure the bean as your app. Needs Because the bean is serializable the configured properties can be saves by the GUI Builder

13 Beans Development Kit Download the latest BDK from SUN Comes with the Beanbox –allows building of bean applications –provides the jar utility –allows saving of configured beans

14 Persistance for persistance a bean must implement the Serializable interface java.io.Serializable saving of the bean’s fields is automatic, you need do nothing, everything is done by the JavaBean API the same applies to retrieving the bean’s persistent values

15 Loading and Saving an Object

16 Saving an Object

17 Restoring an Object

18

19 For more on JavaBeans JavaBeans Home Page - http://java.sun.com/beans/


Download ppt "Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology."

Similar presentations


Ads by Google