1 package server;
2
3 import java.rmi.Remote;
4 import java.rmi.RemoteException;
5 import java.rmi.server.UnicastRemoteObject;
6 import java.rmi.server.RMIClientSocketFactory;
7 import java.rmi.server.RMIServerSocketFactory;
8 import java.math.BigDecimal;
9 import org.jstk.example.bank.Exceptions;
10import org.jstk.example.bank.BankIntf;
11import common.RemoteBank;
12import common.RemoteAccount;
13import common.RemoteIterator;
14
15public class RemoteBankImpl extends UnicastRemoteObject implements RemoteBank {
16 private BankIntf bi;
17 private RMIClientSocketFactory clientFactory = null;
18 private RMIServerSocketFactory serverFactory = null;;
19 private int port = 0;
20 public RemoteBankImpl(BankIntf bi) throws RemoteException {
21 this.bi = bi;
22 }
23 public RemoteBankImpl(BankIntf bi, int port,
24 RMIClientSocketFactory clientFactory,
25 RMIServerSocketFactory serverFactory) throws java.rmi.RemoteException {
26 super(port, clientFactory, serverFactory);
27 this.bi = bi;
28 this.clientFactory = clientFactory;
29 this.serverFactory = serverFactory;
30 this.port = port;
31 }
32 public RemoteAccount openAccount(BigDecimal initialDeposit) throws RemoteException {
33 return new RemoteAccountImpl(bi.openAccount(initialDeposit), port, clientFactory, serverFactory);
34 }
35 public void closeAccount(String acctNo) throws Exceptions.AccountNotFound,
36 Exceptions.AccountClosed, RemoteException {
37 bi.closeAccount(acctNo);
38 }
39 public RemoteAccount getAccount(String acctNo) throws Exceptions.AccountNotFound, RemoteException {
40 return new RemoteAccountImpl(bi.getAccount(acctNo), port, clientFactory, serverFactory);
41 }
42 public RemoteIterator accounts() throws RemoteException {
43 return new RemoteIteratorImpl(bi, port, clientFactory, serverFactory);
44 }
45}
46