/*
 * Account implementation.
 */

#include "AccountImpl.h"

AccountImpl::AccountImpl (const char *name, CORBA::Float balance)
  : POA_Bank::Account ()
  , name_ (name)
  , balance_ (balance)
{
}

char *
AccountImpl::name (void)
{
  return CORBA::string_dup (name_.c_str ());
}

CORBA::Float
AccountImpl::balance (void)
{
  return balance_;
}

void
AccountImpl::deposit (CORBA::Float amount)
{
  balance_ += amount;
}

void
AccountImpl::withdraw (CORBA::Float amount)
{
  if (amount > balance_)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ERROR: Amount requested (%.2f) exceeds available balance of %.2f\n"),
                  amount, balance_));
      throw Bank::Account::InsufficientFunds ();
    }
  else
    {
      balance_ -= amount;
    }
}
