/**

 * Created by sgreene
 * Date: May 22, 2003

 * Modified by : Chandar
 *
 * File  : BankBean.java

 *
 * Overview :
 *     This file defines the implementation class of Bank Web Service.
*/

package oracle.demo.handlerchain.service;


import java.rmi.RemoteException;
import java.util.List;
import java.util.Iterator;

public class BankBean implements BankBeanInterface{

   // Bank object
    private Bank m_bank;


   /*
    * Constructor definition
    */
    public BankBean(){

        // get an instance of Bank db
        m_bank = BankFactory.createBank();
    }


   /*
    * This method creates new account in the bank
    */
    public String createAccount(String acctName,float initBalance) throws
            RemoteException,AccountException {
                // call method on BankMemDB  to create new account
        return m_bank.addNewAccount(acctName,initBalance);
    }


   /*
    * This method deposits amount in the existing account in bank
    */
    public void deposit(String acctID, float amount) throws
            RemoteException, AccountException {
        // get instance of existing account from bank
        Account theAccount = m_bank.getAccount(acctID);

        // throw exception if account does not exist
        if(theAccount == null){
            throw new AccountException("No account found for " + acctID);

        }
        // deposit the input amount
        theAccount.deposit(amount);
    }

   /*
    * This method withdraws amount from existing account
    */
    public void withdraw(String acctID, float amount) throws
            RemoteException, AccountException {
       // get instance of existing account from bank
        Account theAccount = m_bank.getAccount(acctID);


        // throw exception if account does not exist
        if(theAccount == null){
            throw new AccountException("No account found for " + acctID);
        }

        // withdraw amount from bank
        theAccount.withdraw(amount);
    }

   /*
    * This method withdraws gets the balance of existing account
    */

    public float getBalance(String acctID, String acctName) throws
            RemoteException, AccountException {

       // get instance of existing account from bank
        Account theAccount = m_bank.getAccount(acctID);

        // throw exception if account does not exist
        if(theAccount == null){
            throw new AccountException("No account found for " + acctID);
        }

        // get balance and return to client
        return theAccount.getBalance();
    }


   /*
    * This method withdraws gets the account id given a name
    */
    public String getAccountID(String acctName) throws
            RemoteException, AccountException {
        // get all the accounts in bank
        List acctList = m_bank.getAccounts();

        // get iterator on list of accounts
        Iterator it = acctList.iterator();

        Account theAccount = null;
        while(it.hasNext()){
            // get the account

            Account curAccount = (Account)it.next();

            // break if an account is found
            if(curAccount.getAccountName().equals(acctName)){
                theAccount = curAccount;
                break;
            }
        }

        // throw exception if no account is found
        if(theAccount == null){
            throw new AccountException("No acct id found for " + acctName);
         }

         // return the account id
        return theAccount.getAccountID();

    }

}

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy