JavaBeans In, JavaBeans Out

by Ajay Apte, Ping Chen, Stephen Gest, David Morrill, Mike Weis,
Component Technology, IBM Software Solutions Division



Abstract

IBM's new BeanExtender promotes the creation and deployment of pure JavaBeans. It provides an easy and extensible way to compose a new bean from a collection of component JavaBeans. The JavaBeans can be of any type–from visual widgets to abstract business objects. JavaBeans can be composed using a variety of techniques, including direct event connections, event handling through scripting, publishing of an inner JavaBeans' application programming interfaces (APIs) through delegation, and publishing new APIs. The new bean can be further customized using property editors and layout tools. Finally, the new bean is saved using the bean persistence model. The persisted bean can be used directly, as a template, or as a "cookie-cutter."


Overview

Many Java-integrated development environments concentrate on developing Java applets and/or standalone Java applications for the Web browser, ignoring the advantage of developing JavaBeans as output. The advantage of the "JavaBeans out" approach is that it allows Java developers to reuse their own JavaBeans and other JavaBeans. IBM's new BeanExtender focuses on "JavaBeans out" when assembling multiple JavaBeans. JavaBeans are assembled through direct event connections, scripted event connections, and the publishing of new and inner bean interfaces.

This article outlines the requirements of a sample business card application, details the JavaBeans used in constructing the application, and demonstrates the use of a variety of techniques in BeanExtender to compose the new JavaBeans from the component JavaBeans. This article assumes some knowledge of Java, Java AWT, and JavaBeans.


A Business Card Example

Let's explore a simple example: building a business card application using existing JavaBeans. We want our finished application to look something like the following:


Figure 1. Business card example

Requirements
  • An animated GIF. In the example, the light bulb should blink on and off.

  • A Company Name GIF

  • An address

  • The name of a person

  • One or two phone numbers
Since reusable components are desired, the application must also result in JavaBeans with settable properties for the following:
  • Animated GIF file name

  • Company name string and corresponding GIF file name

  • address string

  • person name string

  • phone number 1 string

  • phone number 2 string
To keep the card interesting, we will make the animation play five cycles whenever the mouse cursor enters the area displaying the person's name. To make the card useful, we will cause a mouse click on any of the displayed properties to send its own event with its own property data.

Creating the display layout

The first task is to lay out a set of JavaBean components to make up the display of our business card. Here we can use a GIF animation bean, a GIF viewer bean, and a few text JavaBeans. Use your favorite JavaBeans development environment to accomplish this. Examples are IBM Visual Age for Java and IBM VisualAge WebRunner.

Getting the bulb to light

Getting the animated GIF to play involves a little more work. First, we must connect the "mouse enter" event from the text bean for the person's name to the GIF animation bean. A simple bean abstraction illustrates this:


Figure 3. Event connection

The simple event connection is not enough in this case. Ordinarily, the animation would play indefinitely upon receiving the event. Remember, we only wanted to cycle the animation five times. To solve this problem, we need to introduce some logic in the middle of the connection. This is referred to as "scripting" JavaBeans together. In a scripted event connection, we can use a scripting language (such as NetREXX) or the Java language itself to wire additional logic onto the event. We'll look at this additional logic later in the article.


Figure 4. Scripted event connection

Making one working bean out of connected JavaBeans

We now have a handful of JavaBeans together in a collection that looks like one bean, but how do we make it act like one bean? "Publishing" is the answer. We expose the inner JavaBeans' properties with their new "business card" names, create any additional "business card" properties, and hide the rest.

It is important to note that the above solutions can be provided without having access to any of the bean source code. All we are doing is using the public properties, events, interfaces, and methods of the JavaBeans. We can choose the best GIF animation bean, the best Text bean, and so on. Although the JavaBeans may come from different vendors and probably were not made to work together, they can be grouped together into a functioning aggregate bean through BeanExtender's event connection, scripting, and publishing features.


Assembly surface

BeanExtender's features are accessed through the client application, the assembly surface. Through this surface, we'll explore event connection, scripting, and publishing. These features are represented as tabbed pages within the assembly surface. The following figure displays a view of the assembly surface after the text and GIF JavaBeans have been added and renamed appropriately.


Direct event connections

Most JavaBeans-integrated development environments (IDEs) provide an event connection model. Some IDEs use visual clues like dragging a line from one bean to another and then specifying a method to invoke. Other IDEs use a tree or list view style. Here is BeanExtender's event connections list view, displaying several event connections tied to property changes within the inner JavaBeans. When the background property of the PersonName bean changes, the backgrounds of the Address bean, the PhoneNum bean, and the FaxNum bean change to that same background color.

The direct event connections work well when the JavaBeans either are simple or are initially developed to work together.


Scripted event connections

Most JavaBeans IDEs provide some means of adding code for wiring JavaBeans. Typically, the means is Java code, and it may require a two-step process: putting the code into a new method and connecting an event to the method.

BeanExtender provides a multiple-scripting language solution with a single-step process by combining the two steps. The languages supported in BeanExtender version 1.2 are Java and NetREXX. More languages, such as JavaScript and Visual Basic, will be added. Support may also be added for multilingual scripting within the same bean. The following figure shows the BeanExtender Scripting IDE, displaying scripting code that is attached to the "mouse enter" event of the PersonName bean. This code executes a loop that plays the animation five times when the mouse cursor enters the area displaying the person's name.

The scripting IDE shown is the default, but the scripting IDE interface allows for other user interfaces to be plugged in.

The scripting connections work well when the connected JavaBeans were not developed to work together.


Publishing new and inner bean interfaces

Not many JavaBeans IDEs provide a mechanism for defining an output JavaBeans' interface. Another way of looking at this is to imagine opening up a bean only to find one or more JavaBeans nested inside. In turn, each nested bean may have JavaBeans inside of it, and so on.

BeanExtender can publish the output JavaBeans' API by specifying new properties/events/interfaces/methods [1], and republishing inner JavaBeans' properties/events/interfaces/methods. In addition, BeanExtender allows the inner JavaBeans' editing information to be saved inside the resulting outer bean. This allows the resulting bean to be "opened up" later in order to re-edit the inner bean interfaces. This is also referred to as "drill-down" support.

In the following figure, the business card bean API is defined by republishing several of the inner JavaBeans' properties and defining a new method and a new event.

The publish mechanism is ideal for changing a JavaBeans' behavior, aggregating JavaBeans into a new user resource type (URT), and extending or restricting a JavaBeans' behavior.

The following figure shows the requested republished properties, new method, and new event, displayed through the publish view of the assembly surface.

The next two figures show the bean assembler publishing a new event (the BusinessCardDataEvent), which is delivered to interested clients whenever the user clicks the mouse over any of the areas displaying a property of the business card bean. Figure 11 shows the abstract view of the new event for the business card bean. Figure 12 displays the assembly surface view.


Figure 11. Abstract view of publishing a BusinessCardDataEvent


"Black box" and reuse

It should be noted that the three features shown above are all embedded into the resulting business card bean. In other words, the direct connections, the scripted connections, and the publishing are all hidden inside the newly created bean. Thus, we have a bean that is truly a "black box" that can be used again and again.


Summary

The guiding principle behind IBM's BeanExtender is putting pure JavaBeans in and getting pure JavaBeans out. BeanExtender compiles new JavaBeans from collections of component JavaBeans by using a variety of techniques, including direct event connections, event handling through scripting, publishing of an inner JavaBeans' APIs through delegation, and publishing new APIs.

BeanExtender is available for downloading on IBM's alphaWorks Web site. BeanExtender will be integrated into several JavaBeans development tools, such as IBM VisualAge for Java and IBM VisualAge WebRunner.


Footnotes
  1. Sun Microsystems JavaBeans API Specification version 1.01,
    (http://www.javasoft.com/beans).
References
  1. BeanExtender Technology in IBM software catalog,
    (http://www.software.ibm.com/ad/javabeans/beanextender).

  2. Factoring JavaBeans for the Enterprise (IBM ITSO Redbook). Addison-Wesley Publishing Company, 1997.

  3. IBM alphaWorks (http://www.alphaWorks.ibm.com).

  4. WebRunner Web site.(http://www.taligent.com/Products/webrunner/webhome.html).


About the Authors

Ajay Apte, Ping Chen, Stephen Gest, David Morrill,
Mike Weis
The authors are part of the component technology team at IBM in Austin, Texas. This team is currently developing BeanExtender based on JavaSoft's JavaBeans specification. They develop and run this code on Windows NT(TM), Windows 95(TM), OS/2, and AIX. The team members hold many patents and internal IBM awards. Their technical focuses span the range of components, database access, graphics, compilers, visual builders, and scripting. The team has also worked on the component technologies OpenDoc and Taligent CommonPoint Frameworks.



Java is a trademark of Sun Microsystems, Inc.

Other companies, products, and service names may be trademarks or service marks of others.

Copyright    Trademark



  Java Feature Java Home  
IBM HomeOrderEmployment