FileDocCategorySizeDatePackage
AccountImpl.javaAPI DocExample3741Thu Dec 15 21:44:08 GMT 2005com.oreilly.jent.rmi

AccountImpl

public class AccountImpl extends UnicastRemoteObject implements Account
AccountImpl: Implementation of the Account remote interface.

Fields Summary
private float
mBalance
private String
mName
Constructors Summary
public AccountImpl(String name)

  // Create a new account with the given name
       
    mName = name;
  
Methods Summary
private booleancheckTransfer(Account src, float amt)

    boolean approved = false;
    try {
      if (src.getBalance() >= amt) {
        approved = true;
      }
    }
    catch (RemoteException re) {
      // If some remote exception occurred, then the transfer is still
      // compromised, so return false
      approved = false;
    }
    return approved;
  
public voiddeposit(float amt)

    mBalance += amt;
    // Log transaction...
    System.out.println("--> Deposited " + amt +
                       " into account " + getName());
    System.out.println("    New balance: " + getBalance());
  
public floatgetBalance()

    return mBalance;
  
public java.lang.StringgetName()

    return mName;
  
public voidtransfer(float amt, Account src)

    if (checkTransfer(src, amt)) {
      src.withdraw(amt);
      this.deposit(amt);
      // Log transaction...
      System.out.println("--> Transferred " + amt +
                         " from account " + getName());
      System.out.println("    New balance: " + getBalance());
    }
    else {
      throw new InsufficientFundsException("Source account balance " +
      "is insufficient for transfer");
    }
  
public voidwithdraw(float amt)

    if (mBalance >= amt) {
      mBalance -= amt;
      // Log transaction...
      System.out.println("--> Withdrew " + amt +
                         " from account " + getName());
      System.out.println("    New balance: " + getBalance());
    }
    else {
      throw new InsufficientFundsException("Withdrawal request of " +
                                           amt + " exceeds balance of "
                                           + mBalance);
    }