FileDocCategorySizeDatePackage
NativeAccountImpl.javaAPI DocExample3416Thu Dec 15 21:46:30 GMT 2005com.oreilly.jent.rmi

NativeAccountImpl

public class NativeAccountImpl extends UnicastRemoteObject implements Account
NativeAccountImpl: Implementation of the Account remote interface using JNI native methods for the account transactions.

Fields Summary
private float
mBalance
private String
mName
Constructors Summary
public NativeAccountImpl(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 native voiddeposit(float amt)

public floatgetBalance()

    return mBalance;
  
public java.lang.StringgetName()

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

public voidtransfer(java.util.List amts, java.util.List srcs)

    ListIterator amtCurs = amts.listIterator();
    ListIterator srcCurs = srcs.listIterator();
    // Iterate through the accounts and the amounts to be
    // transferred from each (assumes amounts are given as Float
    // objects)
    while (amtCurs.hasNext() && srcCurs.hasNext()) {
      Float amt = (Float)amtCurs.next();
      Account src = (Account)srcCurs.next();
      // Make the transaction
      this.transfer(amt.floatValue(), src);
    }
  
public native voidwithdraw(float amt)