KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ebank > web > ATMBean


1 /*
2  * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2004 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

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 JavaDoc;
36 import java.math.BigDecimal JavaDoc;
37
38
39 public class ATMBean {
40     private BigDecimal JavaDoc amount;
41     private int operation;
42     private String JavaDoc accountId;
43     private String JavaDoc operationString;
44     private String JavaDoc 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 JavaDoc doTx() {
62         String JavaDoc 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 JavaDoc e) {
84                     Debug.print(message);
85
86                     return e.getMessage();
87                 } catch (InvalidParameterException e) {
88                     // Not possible
89
} catch (AccountNotFoundException e) {
90                     // Not possible
91
} catch (InsufficientCreditException e) {
92                     message = messages.getString("InsufficientCreditError");
93                     Debug.print(message);
94                 } catch (IllegalAccountTypeException e) {
95                     // Not possible
96
}
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 JavaDoc e) {
104                     Debug.print(message);
105
106                     return e.getMessage();
107                 } catch (InvalidParameterException e) {
108                     // Not possible
109
} catch (AccountNotFoundException e) {
110                     // Not possible
111
} catch (IllegalAccountTypeException e) {
112                     // Not possible
113
}
114             }
115         } else {
116             if (operation == 0) {
117                 try {
118                     txctl.withdraw(amount, "ATM Withdrawal", accountId);
119                 } catch (RemoteException JavaDoc e) {
120                     Debug.print(message);
121
122                     return e.getMessage();
123                 } catch (InvalidParameterException e) {
124                     // Not possible
125
} catch (AccountNotFoundException e) {
126                     // Not possible
127
} catch (IllegalAccountTypeException e) {
128                     // Not possible
129
} 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 JavaDoc e) {
140                     Debug.print(message);
141
142                     return e.getMessage();
143                 } catch (InvalidParameterException e) {
144                     // Not possible
145
} catch (AccountNotFoundException e) {
146                     // Not possible
147
} catch (IllegalAccountTypeException e) {
148                     // Not possible
149
}
150             }
151         }
152
153         selectedAccount = customerBean.getAccountDetails();
154
155         return message;
156     }
157
158     public BigDecimal JavaDoc getAmount() {
159         return amount;
160     }
161
162     public String JavaDoc getAccountId() {
163         return accountId;
164     }
165
166     public String JavaDoc getOperationString() {
167         return operationString;
168     }
169
170     public String JavaDoc 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 JavaDoc 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 JavaDoc 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