1 package client;
2 
3 import java.rmi.Remote;
4 import java.rmi.RemoteException;
5 import java.math.BigDecimal;
6 import java.util.Iterator;
7 import org.jstk.example.bank.Exceptions;
8 import org.jstk.example.bank.BankIntf;
9 import org.jstk.example.bank.AccountIntf;
10import common.RemoteBank;
11import common.RemoteAccount;
12
13public class BankProxy implements BankIntf {
14    private RemoteBank rb;
15    public BankProxy(RemoteBank rb){
16        this.rb = rb;
17    }
18    public AccountIntf openAccount(BigDecimal initialDeposit){
19        try {
20            return new AccountProxy(rb.openAccount(initialDeposit));
21        } catch (RemoteException re){
22            throw new RuntimeException(re);
23        }
24    }
25    public void closeAccount(String acctNo) throws Exceptions.AccountNotFound,
26            Exceptions.AccountClosed {
27        try {
28            rb.closeAccount(acctNo);
29        } catch (RemoteException re){
30            throw new RuntimeException(re);
31        }
32    }
33    public AccountIntf getAccount(String acctNo) throws Exceptions.AccountNotFound {
34        try {
35            return new AccountProxy(rb.getAccount(acctNo));
36        } catch (RemoteException re){
37            throw new RuntimeException(re);
38        }
39    }
40    public Iterator accounts() {
41        try {
42            return new IteratorProxy(rb.accounts());
43        } catch (RemoteException re){
44            throw new RuntimeException(re);
45        }
46    }
47}
48