FileDocCategorySizeDatePackage
Account_Impl.javaAPI DocExample1976Thu Nov 08 00:23:08 GMT 2001com.ora.rmibook.chapter17.better

Account_Impl

public class Account_Impl extends UnicastRemoteObject implements Account, Unreferenced

Fields Summary
private Money
_balance
private LockingFactory
_factory
private String
_accountName
Constructors Summary
public Account_Impl(Money startingBalance, String accountName)

        _balance = startingBalance;
        _accountName = accountName;
    
Methods Summary
private voidcheckForNegativeAmount(Money amount)

        int cents = amount.getCents();

        if (0 > cents) {
            throw new NegativeAmountException();
        }
    
private voidcheckForOverdraft(Money amount)

        if (amount.greaterThan(_balance)) {
            throw new OverdraftException(false);
        }
        return;
    
public synchronized MoneygetBalance()

        return _balance;
    
public synchronized voidmakeDeposit(Money amount)

        checkForNegativeAmount(amount);
        _balance.add(amount);
        return;
    
public synchronized voidmakeWithdrawal(Money amount)

        checkForNegativeAmount(amount);
        checkForOverdraft(amount);
        _balance.subtract(amount);
        return;
    
public voidsetFactory(LockingFactory factory)

        _factory = factory;
    
public voidunreferenced()

        if (null == _factory) {
            return;
        }
        try {
            _factory.serverNoLongerActive(_accountName);
        } catch (RemoteException e) {/* Factory is having issues*/
        }
        _factory = null;