The JavaBeans Component Model:

  • The JavaBeans architecture is an integration technology, a component framework that allows reusable component objects (called bean) to communicate with one another and with the framework.
  • The Java bean is an independent and reusable software component that you can manipulate visually in a builder tool.
  • Beans can be visible objects, such as AWT components, or invisible objects such as queues and stacks. A builder or integration tool manipulates beans to create applets and applications.
  • The component model specified by the JavaBeans 1.00-A specification defines five major services:
  1. Introspection: This process exposes the properties, the methods, and the events that the JavaBean component supports. It is used at runtime while the bean is being created with a visual development tool.
  2. Communication: This event handling mechanism creates an event that serves as a message to other components.
  3. Persistence: Persistence is a means of storing the state of a component. The simplest way to support persistence is to take advantage of Java object serialization, but it is up to the individual browsersor the applications that use the bean to actually save the state of the bean.
  4. Properties: Properties are the attributes of a bean that are referenced bya name. Those properties are usually read and written by calling methods on the bean created specifically for that purpose. Some property types affect neighboring beans as well as the one in which the property originates.
  5. Customization: one of the primary characteristics of a bean is its reusability. The beans framework provides several ways of customizing existing beans into new ones.

Bean Architecture:

  • A bean is represented by an interface that is seen by the users. The environment must connect to this interface, if it wants to interact with this bean.
  • Beans consist of three general purpose interfaces: events, properties, and methods. Because beans rely on their state, they must be persistent over time.

Events:

  • The Bean events are a mechanism for sending asynchronous messages between beans, and between beans and containers.
  • A bean usesan event to notify another bean to take an action or to inform the bean that a state change has occurred.
  • An event allows your beans to communicate when something interesting happens; to do this, they make use of the event model introduced in JDK version 1.1.
  • The event model used in Java 2 SDK is the same event model that was introduced in JDK version 1.1. there are three parts to this communication: event object, event listener, and event source.
  • The JavaBeans architecture communicates primarily using event listener interfaces that extend EventListener.
  • Bean developers can design their own event types and event listener interfaces and make their beans act as a source by implementing the  addXXXListener(EventObject e) and removeXXXListener(EventObject e) methods, where XXX is the name of the event type.
  • Then, the developers can make other beans act as event targets by implementing the XXXListener interface.
  • The sourceBean and targateBean are brought together by calling sourceBean.addXXXListener(targetBean).

Properties:

  • Properties define the characteristics of the bean. They can be changed at runtime through their get and set methods.
  • You can use properties to send two way synchronous communications between beans. Beans also support asynchronous property changes between beans using special event communication.

Methods:

  • Methods are operations through which you can interact with a bean. Beans receive notification of events by having the appropriate event source method call them.
  • Some methods are special and deals with properties and events. These methods must follows special naming conversions outlined in the beans specification.
  • Other methods might be unrelated to an event or property. All public methods of a bean are accessible to the bean framework and can be used to connect a bean to other beans.

Bean Introspection:

  • The JavaBean introspection process does expose the properties, the methods, and the events of a bean.
  • Bean classes are assumed to have properties id there are methods that either set or get a property type.
  • The BeanInfo interface, provides by the JavaBeans API, enables bean designers to expose properties, events, methods, and any global information about a bean.
  • The BeanInfo interface provides a series of methods to access bean information, but a bean developer can also include private dscription files that the BeanInfo class uses to define bean information. By default, a BeanInfo object is created when introspection is run on the bean.

 

java programming Part-3

 

A Sample Bean Interaction:

  • In figure given above, Container A and Container B contain six beans. A bean can interact with other beans that are present in the same container and with beans that are in a separate container.
  • In this example, Bean 1 interacts with Bean 4. It does not communicate with Bean 2 and Bean 3, which reside in the same container.
  • This illustrates the point that a bean can communicate with any other bean and is not restricted to communicating with Bean in the same container.
  • However, Bean 4 communicates with Bean 5, which resides in the same container. Source Bean 1 sends an event to the target Bean 4, which causes it  listen for messages on its event listener.
  • All other inter container and intra container beans interactions can be explained in a similar manner.

The Bean Development Kit (BDK):

  • The BDK is a Java application developed by JavaSoft that enables Java technology developers to create reusable components that use the bean model.
  • It is a complete system that contains source code for all examples and documentation. The BDK comes with a sample bean builder and customizer application called BeanBox.
  • The BeanBox is a test container that you can use to do the following:
  1. Resize and move beans
  2. Alter beans with property sheets
  3. Customize beans with a customizer application
  4. Connect beans together
  5. Drop beans onto a composition window
  6. Save bean through serialization
  7. Restore beans
  • The BDK comes with a set of 12 sample beans, which cover all of the aspects of the JavaBeans API.

JAR Files:

  • JAR (JAVA archive) is a platform independent file format that aggregates many files into one. You can bundle multiple Java applets and their requisite components (.class files, images, and sounds) in a JAR file and subsequently download to a browser in a single Hypertext Transfer Protocol (HTTP) transaction, which greatly improving the download speed.
  • The JAR format also does support compression, which does reduce the file size, further improving the download time. In addition, an applet author can digitally sign individual entries in a JAR file to authenticate their origin.
  • It is fully backward-compatible with an existing applet code and can be extended.
  • Changing the applet tag in you HTML page to accommodate a JAR file is easy. The JAR file on the server is identified by the archive parameter, which contains the directory location of the JAR file relative to the location of the HTML page; for example:

 

<applet code = “Animator.class”

archive = “jars/animator.jar”

width = “400” height=”200”>

<param name = “foo” value = “bar”>

</applet>

Written by Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe. Professional Skills: Programming - Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc. http://techliebe.com/about-us

Leave a Comment