📄 banking.java
字号:
package itso.bank.facade;
import itso.bank.exception.AccountDoesNotExistException;
import itso.bank.exception.BankException;
import itso.bank.exception.CustomerDoesNotExistException;
import itso.bank.exception.InsufficientFundsException;
import itso.bank.model.*;
import itso.ejb.model.facade.BankEJB;
import itso.ejb.model.facade.BankEJBHome;
import java.math.BigDecimal;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
/**
* JavaBean Banking, implementing the banking example fa鏰de.
*
* @author Fabio Ferraz, modified Ueli Wahli
*/
public class Banking implements Serializable {
//the Switch: EJB=true Memory=false
boolean ejb = true;
// the memory Bank
private transient Bank bank;
private Bank getBank() {
if (bank == null) bank = Bank.getInstance();
return bank;
}
// the EJB Bank home
private BankEJBHome bankEJBHome = null;
private BankEJBHome getBankEJBHome() throws BankException {
try {
if (bankEJBHome == null) {
Object ior = new InitialContext().lookup("java:comp/env/ejb/BankEJB");
bankEJBHome = (BankEJBHome) PortableRemoteObject.narrow(ior, BankEJBHome.class);
}
return bankEJBHome;
} catch (NamingException e) { throw new BankException(); }
}
// get BankEJB session bean
private BankEJB getBankEJB() throws BankException, RemoteException {
try {
return getBankEJBHome().create();
} catch (CreateException e) { throw new BankException(); }
}
// business methods
public BigDecimal deposit(String accountID, BigDecimal amount)
throws AccountDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().deposit(accountID, amount);
else return getBank().deposit(accountID, amount);
} catch (RemoteException e) { throw new BankException();
} catch (CreateException e) { throw new BankException(); }
}
public BigDecimal withdraw(String accountID, BigDecimal amount)
throws InsufficientFundsException, AccountDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().withdraw(accountID, amount);
else return getBank().withdraw(accountID, amount);
} catch (RemoteException e) { throw new BankException();
} catch (CreateException e) { throw new BankException(); }
}
public BigDecimal transfer(String accountID1, String accountID2, BigDecimal amount)
throws InsufficientFundsException, AccountDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().transfer(accountID1, accountID2, amount);
else return getBank().transfer(accountID1, accountID2, amount);
} catch (RemoteException e) { throw new BankException();
} catch (CreateException e) { throw new BankException(); }
}
public Customer getCustomer(String customerID)
throws CustomerDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().getCustomer(customerID);
else return getBank().getCustomer(customerID);
} catch (RemoteException e) { throw new BankException(); }
}
public Account getAccount(String accountID)
throws AccountDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().getAccount(accountID);
else return getBank().getAccount(accountID);
} catch (RemoteException e) { throw new BankException(); }
}
public Account[] getAccounts(String customerID)
throws CustomerDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().getAccounts(customerID);
else return getBank().getAccounts(customerID);
} catch (RemoteException e) { throw new BankException(); }
}
public TransRecord[] getTransactions(String accountID)
throws AccountDoesNotExistException, BankException {
try {
if (ejb) return getBankEJB().getTransactions(accountID);
else return getBank().getTransactions(accountID);
} catch (RemoteException e) { throw new BankException(); }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -