Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Bean Markup Language, Part 1

Learn the ABCs of IBM's powerful JavaBeans connection language

IBM's alphaWorks site is a treasure trove of early-release software for Java developers. Everything on the site can be downloaded for free, although various disclaimers and restrictions apply, and IBM maintains ownership of the software. Among the many fascinating offerings from alphaWorks is BML, the Bean Markup Language. BML is similar to XML JavaBeans, the topic of a recent JavaBeans column series (see Resources), but has capabilities that XML JavaBeans doesn't even approach.

"Bean Markup Language": Read the whole series!



Because BML's outstanding documentation includes both a user's guide and a tutorial, this article will focus on what BML does, leaving experimentation to the interested reader. We'll look at the Bean Markup Language, including an explanation of the BML player and the BML compiler. BML tags will be defined by way of an illustrative example. The article will conclude with speculation about possible applications of BML that aren't touched on at IBM's site.

A wiring language for JavaBeans

BML is a language for describing structures of nested and interconnected JavaBeans. The goal of BML is to create a language that declaratively describes a structure of interconnected JavaBeans that may function together as a component, or even as a complete application. Its purpose is specifically not to create new functionality; that's what classes are for. BML provides a way to specify how components are connected to one another to perform useful tasks.

Two JavaBeans may maintain an association in one of several ways:

  • Reference -- A field or property of a JavaBean may hold a reference to another JavaBean; in other words, the value of a JavaBean's field or property is itself a JavaBean.
  • Containment -- Sometimes the value of a JavaBean field is also a JavaBean, but is not accessible from outside the bean. The bean that is the field's value can then be said to be contained by the other bean; for example, a Frame bean may contain a Panel.
  • Event binding -- One JavaBean may be an event listener for another JavaBean. When a particular event occurs, it will receive a callback from the event source with an event object.


BML provides ways to instantiate JavaBeans hierarchically, to connect them via event relationships, to assign field and property values, and to call bean methods.

BML's purpose is not to create new Java classes; rather, it is to connect instances of existing classes. To use an analogy based on electronics, if JavaBeans were software integrated circuits (components that perform specific functions), BML would be the wires and circuit-board traces that connected the components. Just as a circuit board can be used as a higher level component, itself composed of components, so can BML be used to create a new JavaBean, composed completely of lower level JavaBeans containing and/or sending events to one another.

An example from the BML tutorial appears in Figure 1. Here, we see a bee juggling three items (an eye, a bee, and an m -- get it?). On the left are the components: a frame, which contains a panel, and a panel, which contains the juggler bean (an instance of a JavaBean class), and Start and Stop button beans. The buttons are connected to the juggler bean via event listener interfaces. On the right is the application, a juggler bean with two buttons that start and stop the juggling. The components have been combined declaratively in BML, and the result is a little runnable application.

1 | 2 | 3 | 4 | 5 | 6 |  Next >
Resources
  • Download the source code for this article:
  • Related reading in JavaWorld
  • IBM's BML and XML resources
  • The three great virtues of a programmer
  • According to Larry Wall, creator of Perl (the second best computer language in existence) the three great virtues of a programmer are laziness, impatience, and hubris. Read a description of these virtues
    http://hiro.protagonist.net/perl/virtue.html