/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.aries.samples.bank.chq;
import org.apache.aries.samples.bank.api.ChequingAccountService;
import org.apache.aries.samples.bank.api.Constants;
/* This class is to become a Session Bean according to our original design. */
public class ChequingAccountServiceImpl implements ChequingAccountService {
class AccountRecord {
String name;
public String getName() {
return name;
}
int balance;
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public AccountRecord (String name) {
this.name = name;
balance = 0;
}
}
private static final int BASE = Constants.CHEQUING_ACCOUNT_BASE;
private static int nextAccount_ = BASE;
private static AccountRecord[] _accounts = new AccountRecord[10];
@Override
public int open(String name) {
int accountNumber = nextAccount_++;
_accounts[accountNumber-BASE] = new AccountRecord (name);
System.out.println("ChequingAccountServiceImpl.open() = "+accountNumber);
return accountNumber;
}
@Override
public int balance(int accountNumber) {
int balance = _accounts[accountNumber-BASE].getBalance();
System.out.println("ChequingAccountServiceImpl.balance("+accountNumber+") = "+balance);
return balance;
}
@Override
public void deposit(int accountNumber, int funds) {
AccountRecord record = _accounts[accountNumber-BASE];
record.setBalance(record.getBalance() + funds);
System.out.println("ChequingAccountServiceImpl.deposit("+accountNumber+","+funds+")");
}
@Override
public void withdraw(int accountNumber, int funds) {
AccountRecord record = _accounts[accountNumber-BASE];
record.setBalance(record.getBalance() - funds);
System.out.println("ChequingAccountServiceImpl.withdraw("+accountNumber+","+funds+")");
}
@Override
public String name(int accountNumber) {
String name =_accounts[accountNumber-BASE].getName();
System.out.println ("ChequingAccountServiceImpl.getName("+accountNumber+" = " + name);
return name;
}
}