1 27 28 29 package com.sun.ebank.web; 30 31 import com.sun.ebank.util.*; 32 import com.sun.ebank.ejb.tx.TxController; 33 import com.sun.ebank.ejb.exception.*; 34 import java.util.*; 35 import java.rmi.RemoteException ; 36 import java.math.BigDecimal ; 37 38 39 public class ATMBean { 40 private BigDecimal amount; 41 private int operation; 42 private String accountId; 43 private String operationString; 44 private String prepString; 45 private AccountDetails selectedAccount; 46 private ResourceBundle messages; 47 private BeanManager beanManager; 48 private CustomerBean customerBean; 49 50 public ATMBean() { 51 messages = null; 52 beanManager = null; 53 amount = null; 54 operation = 0; 55 accountId = null; 56 operationString = null; 57 prepString = null; 58 selectedAccount = null; 59 } 60 61 public String doTx() { 62 String message = null; 63 TxController txctl = beanManager.getTxController(); 64 65 operationString = messages.getString("WithdrewString"); 66 prepString = messages.getString("FromString"); 67 Debug.print(accountId); 68 69 customerBean.setAccount(accountId); 70 selectedAccount = customerBean.getAccountDetails(); 71 72 boolean isCreditAcct = false; 73 74 if (selectedAccount.getType() 75 .equals("Credit")) { 76 isCreditAcct = true; 77 } 78 79 if (isCreditAcct) { 80 if (operation == 0) { 81 try { 82 txctl.makeCharge(amount, "ATM Withdrawal", accountId); 83 } catch (RemoteException e) { 84 Debug.print(message); 85 86 return e.getMessage(); 87 } catch (InvalidParameterException e) { 88 } catch (AccountNotFoundException e) { 90 } catch (InsufficientCreditException e) { 92 message = messages.getString("InsufficientCreditError"); 93 Debug.print(message); 94 } catch (IllegalAccountTypeException e) { 95 } 97 } else { 98 operationString = messages.getString("DepositedString"); 99 prepString = messages.getString("ToString"); 100 101 try { 102 txctl.makePayment(amount, "ATM Deposit", accountId); 103 } catch (RemoteException e) { 104 Debug.print(message); 105 106 return e.getMessage(); 107 } catch (InvalidParameterException e) { 108 } catch (AccountNotFoundException e) { 110 } catch (IllegalAccountTypeException e) { 112 } 114 } 115 } else { 116 if (operation == 0) { 117 try { 118 txctl.withdraw(amount, "ATM Withdrawal", accountId); 119 } catch (RemoteException e) { 120 Debug.print(message); 121 122 return e.getMessage(); 123 } catch (InvalidParameterException e) { 124 } catch (AccountNotFoundException e) { 126 } catch (IllegalAccountTypeException e) { 128 } catch (InsufficientFundsException e) { 130 message = messages.getString("InsufficientFundsError"); 131 Debug.print(message); 132 } 133 } else { 134 operationString = messages.getString("DepositedString"); 135 prepString = messages.getString("ToString"); 136 137 try { 138 txctl.deposit(amount, "ATM Deposit", accountId); 139 } catch (RemoteException e) { 140 Debug.print(message); 141 142 return e.getMessage(); 143 } catch (InvalidParameterException e) { 144 } catch (AccountNotFoundException e) { 146 } catch (IllegalAccountTypeException e) { 148 } 150 } 151 } 152 153 selectedAccount = customerBean.getAccountDetails(); 154 155 return message; 156 } 157 158 public BigDecimal getAmount() { 159 return amount; 160 } 161 162 public String getAccountId() { 163 return accountId; 164 } 165 166 public String getOperationString() { 167 return operationString; 168 } 169 170 public String getPrepString() { 171 return prepString; 172 } 173 174 public AccountDetails getSelectedAccount() { 175 return selectedAccount; 176 } 177 178 public void setMessages(ResourceBundle messages) { 179 this.messages = messages; 180 } 181 182 public void setAmount(BigDecimal amount) { 183 this.amount = amount; 184 Debug.print("Setting amount to: " + amount); 185 } 186 187 public void setOperation(int operation) { 188 this.operation = operation; 189 Debug.print("Setting operation to: " + operation); 190 } 191 192 public void setAccountId(String accountId) { 193 this.accountId = accountId; 194 Debug.print("Setting account id to: " + accountId); 195 } 196 197 public void setBeanManager(BeanManager beanManager) { 198 this.beanManager = beanManager; 199 } 200 201 public void setCustomerBean(CustomerBean customerBean) { 202 this.customerBean = customerBean; 203 } 204 } 205 | Popular Tags |