Exercise

You have been shown a simple program to display a JNDI namespace as a command line program (JNDITree.java in Listing 3.6). Today's exercise is to write a GUI version of this program using the Swing JTree class.If you already know Swing, you can use JNDITree.java as a guide for your program and go ahead and write your own JNDI browser.

If you do not know Swing, the exercise directory for Day 3 on the accompanying CD-ROM includes a template program called JNDIBrowser.java for you to enhance. The JNDIBrowser program handles all of the Swing initialization, all you have to do is get a list of the names in the JNDI namespace and create a new javax.swing.tree.DefaultMutableTreeNode representing the name and add this to the JTree. When you add a name that is also a context, you need to add all the names in this sub-context.

Comments have been added to the JNDIBrowser.java file to show you where to add your code.

Don't worry if this sounds complex—it isn't. You only have to write about 12 lines of code (most of which you can adapt from JNDITree.java).

Before you rush off and write your first piece of Java code for this book, remember that you need to set up your CLASSPATH to include the J2EE Reference Implementation classes using the setenv script, as discussed in today's lesson. You can run the supplied solution using the following commands.

Under Windows, use

%J2EE_HOME%insetenv
java –classpath .;%CPATH% JNDIBrowser

Under Linux and Unix, use

$J2EE_HOME/bin/setenv
java –classpath .:$CPATH JNDIBrowser

If you complete this exercise or simply run the provided solution, you will see that the JNDI names are listed in the order they were added to the context. As a second exercise, change your program to display the names in alphabetical order. The solution called JNDIBrowserSort.java program shows how this can be achieved using the java.util.TreeMap class.

You will find these programs useful for browsing the JNDI namespace when you are developing J2EE applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.233.153