Chapter 9. Moving the server application to Java 365
We directly export the classes using the VisualAge for Java export function. When we run the
application on the iSeries server, we have to set the CLASSPATH environment variable to
include the IFS file directory where we stored the class files. In Figure 9-23, we export the
classes to the iSeries server using a network drive.
Figure 9-23 Exporting the class files
9.4.5 Implementing the client
This section explains how to build the client class of the RMI application. We create a new
class that is a subclass of javax.swing.JFrame and implements the PartsContainer interface.
This class uses the ToolboxGUI class as re-usable part. For details about the ToolboxGUI
class and the PartsContainer interface, refer to 4.6.5, Reusable GUI part on page 170.
The name of the client program is RMIExample. As shown in Figure 9-24, we create global
variables for the port name and system name and create a new instance of the ItemSubmitter
class, which we call remoteRequestor. We use the remoteRequestor object for all of our RMI
Figure 9-24 Creating the client class
public class RMIExample extends javax.swing.JFrame implements
DatabaseAccessExample.PartsContainer, java.awt.event.WindowListener
private DatabaseAccessExample.ToolboxGUI ivjToolboxGUI1 = null;
static java.lang.String port = null;
static java.lang.String systemName;
ItemSubmitter remoteRequestor = new ItemSubmitter();
366 Building Java Applications for the iSeries Server with VisualAge for Java 3.5
The RMIExample main method (Figure 9-25) was created by VisualAge for Java.
Figure 9-25 RMIExample main() method
When the application is run, the main() method instantiates a new instance of the
RMIExample class. We only have to modify it to use the first argument of the parameter list to
set the port variable.
The connectToDB() method shown in Figure 9-26 is executed when the user clicks the
Connect button.
Figure 9-26 RMIExample connectToDB() method
We use the system name from the screen TextField as a parameter to set the systemName
variable. We call the linked() method of the remoteRequestor object, which was instantiated
from the ItemSubmitter class to establish the RMI connection.
The getRecord() method, shown in Figure 9-27, is called when the user clicks the Get Part
public static void main(java.lang.String[] args) {
if ((port = args[0]) != null)
try {
RMIExample aRMIExample;
aRMIExample = new RMIExample();
aRMIExample.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
java.awt.Insets insets = aRMIExample.getInsets();
aRMIExample.setSize(aRMIExample.getWidth() + insets.left + insets.right,
aRMIExample.getHeight() + + insets.bottom);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JFrame");
System.out.println("Please Input port number");
public void connectToDB(String systemName, String userid, String password) throws
Exception {
this.systemName = systemName;
remoteRequestor.linked(systemName, port);
Chapter 9. Moving the server application to Java 367
Figure 9-27 RMIExample getRecord() method
The getRecord() method calls the submit() method of the remoteRequestor object passing
the part number as a parameter. An Item object is returned that contains the details about the
Item (or Part).
If an Item object is returned, the item requested was found in the database. We use the getter
methods provided by the Item object to retrieve the information and display it on the screen.
The populateAllParts() method, shown in Figure 9-28, is called when the user clicks the
Get All Parts button. It calls the submitAll() method of the remoteRequestor object passing
no parameters.
Figure 9-28 RMIExample populateAllParts() method
public String getRecord(String partNo, javax.swing.JTextField partDesc,
javax.swing.JTextField partQty, javax.swing.JTextField partPrice,
javax.swing.JTextField partDate) throws Exception {
Item rtnItem = remoteRequestor.submit(partNo);
if ((rtnItem) != null)
partPrice.setText("$" + (rtnItem.getItemPrice()).toString());
else {
return "Record not found";
return "Record found";
public void populateAllParts(javax.swing.table.DefaultTableModel defaultTableModel)
throws Exception
Item rtnItem = remoteRequestor.submitAll();
if (rtnItem != null) {
for (int i = 0; i < rtnItem.getNumEntries(); i++) {
ItemDetail rtnDetail = rtnItem.getNextEntry(i);
String[] array = new String[5];
array[0] = rtnDetail.getItemId();
array[1] = rtnDetail.getItemDsc();
array[2] = rtnDetail.getItemPrice();
array[3] = rtnDetail.getItemQty();
array[4] = rtnDetail.getItemDate();

Get Building Java Applications for the iSeries Server with VisualAge for Java 3.5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.