FileDocCategorySizeDatePackage
Account_Impl.javaAPI DocExample2624Thu Nov 08 00:23:04 GMT 2001com.ora.rmibook.chapter17.activation

Account_Impl

public class Account_Impl extends Activatable implements Account

Fields Summary
private Money
_balance
Constructors Summary
public Account_Impl(ActivationID id, MarshalledObject data)

        super (id, 0);
        try {
            _balance = (Money) data.get();
        } catch (Exception e) {

            /* Both ClassNotFoundException and IOException can
             be thrown.*/
        }
    
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 booleanequals(java.lang.Object object)

        // three cases. Either it's us, or it's our stub, or it's
        // not equal.

        if (object instanceof Account_Impl) {
            return (object == this);
        }
        if (object instanceof RemoteStub) {
            try {
                RemoteStub ourStub = (RemoteStub) RemoteObject.toStub(this);

                return ourStub.equals(object);
            } catch (NoSuchObjectException e) {
                // we're not listening on a port, therefore it's not our
                // stub
            }
        }
        return false;
    
public MoneygetBalance()

        return _balance;
    
public inthashCode()

        try {
            Remote ourStub = RemoteObject.toStub(this);

            return ourStub.hashCode();
        } catch (NoSuchObjectException e) {
        }
        return super.hashCode();
    
public voidmakeDeposit(Money amount)

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

        checkForNegativeAmount(amount);
        checkForOverdraft(amount);
        _balance.subtract(amount);
        return;