/* * * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved. * * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */ import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; public class AccountClient { public static void main(String[] args) { try { Context initial = new InitialContext(); Object objref = initial.lookup("MyAccount"); AccountHome home = (AccountHome)PortableRemoteObject.narrow(objref, AccountHome.class); Account duke = home.create("123", "Duke", "Earl", 0.00); duke.credit(88.50); duke.debit(20.25); double balance = duke.getBalance(); System.out.println("balance = " + String.valueOf(balance)); duke.remove(); Account joe = home.create("836", "Joe", "Jones", 0.00); joe.credit(34.55); Account jones = home.findByPrimaryKey("836"); jones.debit(2.00); balance = jones.getBalance(); System.out.println("balance = " + String.valueOf(balance)); Account pat = home.create("456", "Pat", "Smith", 0.00); pat.credit(44.77); Account john = home.create("730", "John", "Smith", 0.00); john.credit(19.54); Account mary = home.create("268", "Mary", "Smith", 0.00); mary.credit(100.07); Collection c = home.findByLastName("Smith"); Iterator i=c.iterator(); while (i.hasNext()) { Account account = (Account)i.next(); String id = (String)account.getPrimaryKey(); double amount = account.getBalance(); System.out.println(id + ": " + String.valueOf(amount)); } c = home.findInRange(20.00, 99.00); i=c.iterator(); while (i.hasNext()) { Account account = (Account)i.next(); String id = (String)account.getPrimaryKey(); double amount = account.getBalance(); System.out.println(id + ": " + String.valueOf(amount)); } } catch (InsufficientBalanceException ex) { System.err.println("Caught an InsufficientBalanceException: " + ex.getMessage()); } catch (Exception ex) { System.err.println("Caught an exception." ); ex.printStackTrace(); } } }