Xbeans Tutorial

In this tutorial we will build a complete distributed data exchange application without writing any code! To accomplish that you need a Java Bean design tool.

We will use Borland's JBuilder. We assume you know how to use JBuilder. (For instructions on how to add Xbeans to the JBuilder palette, see Richard Kuo's excellent detailed instructions.)

If you use a different Java Bean design tool, you will need to take the analogous steps in your tool.

If you do not have or want to use a Java Bean design tool, you can still do this tutorial by writing the code by hand that the design tool generates. It's actually very little code. Please read this for more information.

The application we are going to build looks like this:

This is actually two programs, one that sends data and one that receives it. We'll call them senderDemo and receiverDemo.

Setup

The first thing you need to do is to download the second release of Xbeans and the Xbeans Communication Pack. Place the Xbeans, DOM and XSLT Jar files in a place that your Java compiler / IDE and runtime environment can find it.

You should add the Xbeans to the JBuilder Designer's palette.

We will now create and run the two programs, senderDemo and receiverDemo.

senderDemo

The lower left panel of the designer should now look like this:

Now you need to set properties on these five Xbeans. You do that by selecting the Xbean and then modifying the property editor.

Let's first set up the channel illustrated here:

The parser is the first Xbean. It's DOMListener is the viewer. So we need to set the parser's DOMListener property to be the first viewer bean. Here's how to accomplish this:

Now go ahead and set the other DOMListener properties for the first viewer, the translator, the second viewer and the sender. The receiver and the third viewer are part of the receiver program. We'll do those below.

You should now have the sender side channel set up. Now you need to set other properties on the Xbeans. Set them as follows:

Xbean   Property  Value
parser     
   xmlSource  cookbook.xml
 translator  
   translationFile  BookToOutline.xsl
 sender    
   id  receiver
 

 protocol

corba

 

 compression

 True

Note that there are other properties you can set on the Xbeans that will modify the behavior of this demo. The properties are documented here.

Also, note that you are using a predefined xsl file for the translator. Rather than using this XSL file, you could use the translator's customizer to automatically generate the XSL file. The customizer lets you explore the DTDs graphically and define assignments by pointing and clicking. More information on the translator can be found here.

parser1.generateDocument();

This code needs to be added after the channel has been set up. Note that this assumes the parser xbean is being referenced in the program by a variable named "parser1". If not, change it appropriately.

Now it's on to the second program, the receiverDemo.

receiverDemo

You have now built both programs. You can now run them.

Running the distributed data exchange demo

For simplicity, we will run both the senderDemo and the receiverDemo programs on the same machine and from JBuilder. However, without too much trouble you could set it up so they are on different machines.

The only set up you need to do is to run tnameserv, Sun's CORBA name service that comes with jdk1.3. It is found in jdk1.3/bin/tnameserv

When the name service is started successfully, it prints out a message like this:

Initial Naming Context:
IOR:000000000000002849444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578743a312e3000000000010000000000000058000101000000000f32342e3232312e313730
2e31393400000e7a000000000018afabcafe0000000279c3e4e10000000800000000000000000000
000100000001000000140000000000010020000000000001010000000000
TransientNameServer: setting port for initial object references to: 900
Ready.

Now run the receiverDemo program from JBuilder. It will not have any visible behavior until you run the senderDemo to send it an XML document.

Now run the senderDemo program from JBuilder. First you should see the parsed document in the viewer. The document is a cookbook.

Move the viewer to another location on your screen. All viewers are going to be shown in the same location.

After examining the document, press continue and you should see the translated document in another viewer. The document is an outline of the cookbook.

After examing the document, press continue and the document will be sent "over the wire" using CORBA.

The receiverDemo should now show the received document in its viewer. The received document is, of course, the same outline.

Congratulations, you are done! You should have three viewers on your screen. If you ran the demo on different machines, then you should have two viewers on the sender machine and one viewer on the receiver machine.

Rather than using CORBA to send the document, you could have used RMI, Servlets, SOAP, EJB or HTTP. It's a matter of replacing the sender and receiver Xbeans and configuring appropriately.