package oracle.demo.handlerchain.service;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Iterator;
public class BankBean implements BankBeanInterface{
private Bank m_bank;
public BankBean(){
m_bank = BankFactory.createBank();
}
public String createAccount(String acctName,float initBalance) throws
RemoteException,AccountException {
return m_bank.addNewAccount(acctName,initBalance);
}
public void deposit(String acctID, float amount) throws
RemoteException, AccountException {
Account theAccount = m_bank.getAccount(acctID);
if(theAccount == null){
throw new AccountException("No account found for " + acctID);
}
theAccount.deposit(amount);
}
public void withdraw(String acctID, float amount) throws
RemoteException, AccountException {
Account theAccount = m_bank.getAccount(acctID);
if(theAccount == null){
throw new AccountException("No account found for " + acctID);
}
theAccount.withdraw(amount);
}
public float getBalance(String acctID, String acctName) throws
RemoteException, AccountException {
Account theAccount = m_bank.getAccount(acctID);
if(theAccount == null){
throw new AccountException("No account found for " + acctID);
}
return theAccount.getBalance();
}
public String getAccountID(String acctName) throws
RemoteException, AccountException {
List acctList = m_bank.getAccounts();
Iterator it = acctList.iterator();
Account theAccount = null;
while(it.hasNext()){
Account curAccount = (Account)it.next();
if(curAccount.getAccountName().equals(acctName)){
theAccount = curAccount;
break;
}
}
if(theAccount == null){
throw new AccountException("No acct id found for " + acctName);
}
return theAccount.getAccountID();
}
}
|