The Client Code Comparison
Implementing the MTS/EJB Client
Both the EJB and MTS clients have been implemented using Java code using the Visual J++ version 6.0 compiler.
MTS Client - The MTS client shown below calls into the MTS server object's methods by first acquiring a pointer to the server object. The new keyword here instantiates the bank.Checking MTS Server object. This leads the Microsoft JVM to use the CLSID to make a CoCreateInstance() call. The IUnknown pointer returned by CoCreateInstance() is then cast to bank.IChecking, as shown below.
EJB Client
- The EJB client shown below calls into the EJB server object's
methods by first acquiring a pointer to the server object. The
client first uses JNDI to get a reference to the EJB component's
home interface. It then uses this reference to create an instance
of the EJB component and holds on to this reference when calling
into the component methods.
MTS - Client Code |
EJB - Client Code |
import
com.ms.wfc.app.*; import com.ms.wfc.core.*; import com.ms.wfc.ui.*; import com.ms.wfc.html.*; import com.ms.com.*; import bank.*; |
import
com.ms.wfc.app.*; import com.ms.wfc.core.*; import com.ms.wfc.ui.*; import com.ms.wfc.html.*; import com.ms.com.*; import java.rmi.*; import java.util.*; import Bank.*; |
public
class CheckingClient extends Form { static final int INITIAL_RECORD = 11; int accountNo; String name; double balance; int count; bank.IChecking server; |
public
class CheckingClient extends Form { static final int INITIAL_RECORD = 11; int accountNo; String name; double balance; int count; public CheckingHome home = null; public Checking server = null; |
////////////////////////////////////////////////////////////////
public CheckingClient () { //////////////////////////////////////////////////////////////// super(); initForm(); try { server = (bank.IChecking) new bank.Checking (); } catch (Exception ex) { ex.printStackTrace (); } fillAccountList (); } |
//////////////////////////////////////////////////////////////// public CheckingClient () { //////////////////////////////////////////////////////////////// super(); initForm(); try { home = (CheckingHome) Naming.lookup ("checking"); if (home == null) { System.out.println ("null TellerHome returned..."); } server = home.create (); } catch (Exception e) { e.printStackTrace (); } fillAccountList (); } |
/**
* CheckingClient overrides dispose so it can clean up the * component list. */ //////////////////////////////////////////////////////////////// public void dispose() { //////////////////////////////////////////////////////////////// super.dispose(); components.dispose(); } |
/**
* CheckingClient overrides dispose so it can clean up the * component list. */ //////////////////////////////////////////////////////////////// public void dispose() { //////////////////////////////////////////////////////////////// super.dispose(); components.dispose(); } |
////////////////////////////////////////////////////////////////
public void fillAccountList() { //////////////////////////////////////////////////////////////// accountList.removeAll (); count = 0; boolean bMoreElements = true; do { try { name = server.getCustomerName (count+INITIAL_RECORD); if(name == null) break; accountList.addItem ((new Integer (count+INITIAL_RECORD)) .toString ()); } catch (Exception ex) { ex.printStackTrace (); bMoreElements = false; } ++count; } while (bMoreElements == true); } |
//////////////////////////////////////////////////////////////// public void fillAccountList() { //////////////////////////////////////////////////////////////// accountList.removeAll (); count = 0; boolean bMoreElements = true; do { try { name = server.getCustomerName (count+INITIAL_RECORD); if(name == null) break; accountList.addItem((new Integer (count+INITIAL_RECORD)) .toString ()); } catch (Exception ex) { ex.printStackTrace (); bMoreElements = false; } ++count; } while (bMoreElements == true); } |
////////////////////////////////////////////////////////////////
private void retrieveButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// if (accountList.getSelectedItem () == null) return; String accSel = (accountList.getSelectedItem ()).toString (); accountNo = (new Integer (accSel)).intValue (); try { balance = server.getBalance (accountNo); name = server.getCustomerName (accountNo); numberEdit.setText ( (new Integer (accountNo)).toString () ); nameEdit.setText (name); balanceEdit.setText ( (new Double (balance)).toString () ); } catch (Exception ex) { ex.printStackTrace (); } } |
//////////////////////////////////////////////////////////////// private void retrieveButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// if (accountList.getSelectedItem () == null) return; String accSel = (accountList.getSelectedItem ()).toString (); accountNo = (new Integer (accSel)).intValue (); try { balance = server.getBalance (accountNo); name = server.getCustomerName (accountNo); numberEdit.setText ( (new Integer (accountNo)).toString () ); nameEdit.setText (name); balanceEdit.setText ( (new Double (balance)).toString () ); } catch (Exception ex) { ex.printStackTrace (); } } |
////////////////////////////////////////////////////////////////
private void addButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// accountNo = count+INITIAL_RECORD; name = nameEdit.getText (); balance = ( new Double (balanceEdit.getText ()) ).doubleValue (); if ((accountNo == 0) || (name == null)) return; try { server.createAccount (accountNo, name, balance); } catch (Exception ex) { ex.printStackTrace (); } fillAccountList (); } |
//////////////////////////////////////////////////////////////// private void addButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// accountNo = count+INITIAL_RECORD; name = nameEdit.getText (); balance = ( new Double (balanceEdit.getText ()) ).doubleValue (); if ((accountNo == 0) || (name == null)) return; try { server.createAccount (accountNo, name, balance); } catch (Exception ex) { ex.printStackTrace (); } fillAccountList (); } |
////////////////////////////////////////////////////////////////
private void closeButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// Application.exit (); } |
//////////////////////////////////////////////////////////////// private void closeButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// Application.exit (); } |
////////////////////////////////////////////////////////////////
private void creditButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// if (accountList.getSelectedItem () == null) return; String accSel = (accountList.getSelectedItem ()).toString (); accountNo = (new Integer (accSel)).intValue (); double amount = ( new Double (creditEdit.getText ()) ).doubleValue (); try { server.credit (amount, accountNo); balance = server.getBalance (accountNo); name = server.getCustomerName (accountNo); numberEdit.setText ( (new Integer (accountNo)).toString () ); nameEdit.setText (name); balanceEdit.setText ( (new Double (balance)).toString () ); } catch (Exception ex) { ex.printStackTrace (); } } |
//////////////////////////////////////////////////////////////// private void creditButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// if (accountList.getSelectedItem () == null) return; String accSel = (accountList.getSelectedItem ()).toString (); accountNo = (new Integer (accSel)).intValue (); double amount = ( new Double (creditEdit.getText ()) ).doubleValue (); try { server.credit (amount, accountNo); balance = server.getBalance (accountNo); name = server.getCustomerName (accountNo); numberEdit.setText ( (new Integer (accountNo)).toString () ); nameEdit.setText (name); balanceEdit.setText ( (new Double (balance)).toString () ); } catch (Exception ex) { ex.printStackTrace (); } } |
////////////////////////////////////////////////////////////////
private void debitButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// if (accountList.getSelectedItem () == null) return; String accSel = (accountList.getSelectedItem ()).toString (); accountNo = (new Integer (accSel)).intValue (); double amount = ( new Double (debitEdit.getText ()) ).doubleValue (); try { server.debit (amount, accountNo); balance = server.getBalance (accountNo); name = server.getCustomerName (accountNo); numberEdit.setText ( (new Integer (accountNo)).toString () ); nameEdit.setText (name); balanceEdit.setText ( (new Double (balance)).toString () ); } catch (Exception ex) { ex.printStackTrace (); } } |
//////////////////////////////////////////////////////////////// private void debitButton_click(Object source, Event e) { //////////////////////////////////////////////////////////////// if (accountList.getSelectedItem () == null) return; String accSel = (accountList.getSelectedItem ()).toString (); accountNo = (new Integer (accSel)).intValue (); double amount = ( new Double (debitEdit.getText ()) ).doubleValue (); try { server.debit (amount, accountNo); balance = server.getBalance (accountNo); name = server.getCustomerName (accountNo); numberEdit.setText ( (new Integer (accountNo)).toString () ); nameEdit.setText (name); balanceEdit.setText ( (new Double (balance)).toString () ); } catch (Exception ex) { ex.printStackTrace (); } } |
/**
* NOTE: The following code is required by the Visual J++ form * designer. It can be modified using the form editor. Do not * modify it using the code editor. */ Container components = new Container(); ListBox accountList = new ListBox(); Button retrieveButton = new Button(); Button closeButton = new Button(); Button addButton = new Button(); Edit numberEdit = new Edit(); Edit nameEdit = new Edit(); Edit balanceEdit = new Edit(); Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); Edit creditEdit = new Edit(); Edit debitEdit = new Edit(); Button creditButton = new Button(); Button debitButton = new Button(); private
void initForm() { accountList.setAllowDrop(true);
retrieveButton.setLocation(new
Point(184, 240)); closeButton.setLocation(new
Point(184, 280)); addButton.setLocation(new
Point(96, 112)); numberEdit.setLocation(new
Point(120, 16)); nameEdit.setLocation(new
Point(120, 48)); balanceEdit.setLocation(new
Point(120, 80)); label1.setLocation(new
Point(16, 16)); label2.setLocation(new
Point(16, 48)); label3.setLocation(new
Point(16, 80)); creditEdit.setLocation(new
Point(16, 152)); debitEdit.setLocation(new
Point(16, 184)); creditButton.setLocation(new
Point(184, 152)); debitButton.setLocation(new
Point(184, 184)); this.setNewControls(new
Control[] { |
/**
* NOTE: The following code is required by the Visual J++ form * designer. It can be modified using the form editor. Do not * modify it using the code editor. */ Container components = new Container(); ListBox accountList = new ListBox(); Button retrieveButton = new Button(); Button closeButton = new Button(); Button addButton = new Button(); Edit numberEdit = new Edit(); Edit nameEdit = new Edit(); Edit balanceEdit = new Edit(); Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); Edit creditEdit = new Edit(); Edit debitEdit = new Edit(); Button creditButton = new Button(); Button debitButton = new Button(); private
void initForm() { accountList.setAllowDrop(true);
retrieveButton.setLocation(new
Point(184, 240)); closeButton.setLocation(new
Point(184, 280)); addButton.setLocation(new
Point(96, 112)); numberEdit.setLocation(new
Point(120, 16)); nameEdit.setLocation(new
Point(120, 48)); balanceEdit.setLocation(new
Point(120, 80)); label1.setLocation(new
Point(16, 16)); label2.setLocation(new
Point(16, 48)); label3.setLocation(new
Point(16, 80)); creditEdit.setLocation(new
Point(16, 152)); debitEdit.setLocation(new
Point(16, 184)); creditButton.setLocation(new
Point(184, 152)); debitButton.setLocation(new
Point(184, 184)); this.setNewControls(new
Control[] { |
/**
* The main entry point for the application. * * @param args Array of parameters passed to the application * via the command line. */ //////////////////////////////////////////////////////////////// public static void main (String args[]) { //////////////////////////////////////////////////////////////// Application.run (new CheckingClient ()); } } |
/**
* The main entry point for the application. * * @param args Array of parameters passed to the application * via the command line. */ //////////////////////////////////////////////////////////////// public static void main (String args[]) { //////////////////////////////////////////////////////////////// Application.run (new CheckingClient ()); } } |
CheckingClient.java |
CheckingClient.java |
click here to go
to My Advanced Java / J2EE Tutorial HomePage... |
This site was developed and is maintained by Gopalan Suresh Raj This page has been visited times since May 04,1999. |
Last Updated : May 04,'99 |
Copyright (c) 1997-2000, Gopalan Suresh Raj - All rights reserved. Terms of use. |
All products and companies mentioned at this site are trademarks of their respective owners. |