KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jboss > ebank > TellerBean


1 package com.jboss.ebank;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 import javax.naming.InitialContext JavaDoc;
8 import javax.naming.NamingException JavaDoc;
9 import java.rmi.RemoteException JavaDoc;
10
11 import javax.ejb.SessionBean JavaDoc;
12 import javax.ejb.SessionContext JavaDoc;
13 import javax.ejb.CreateException JavaDoc;
14
15 import com.sun.ebank.ejb.account.AccountController;
16 import com.sun.ebank.ejb.account.AccountControllerHome;
17 import com.sun.ebank.util.AccountDetails;
18
19 public class TellerBean
20     implements SessionBean JavaDoc
21 {
22     public TellerBean() {
23     }
24
25     private AccountController getController()
26     throws RemoteException JavaDoc,
27            NamingException JavaDoc,
28            CreateException JavaDoc
29     {
30     InitialContext JavaDoc ctx = new InitialContext JavaDoc();
31     AccountControllerHome home = (AccountControllerHome)
32         ctx.lookup("java:comp/env/ejb/account");
33     
34     return home.create();
35     }
36
37     public BigDecimal JavaDoc getAccountBalance(String JavaDoc accountID) {
38     try {
39         AccountController mgr = getController();
40         AccountDetails details = mgr.getDetails(accountID);
41
42         return details.getBalance();
43     } catch (Exception JavaDoc e) {
44         e.printStackTrace();
45         return new BigDecimal JavaDoc(0);
46     }
47     }
48
49     public String JavaDoc[] getAccountsOfCustomer(String JavaDoc customerId)
50     {
51     try {
52         AccountController mgr = getController();
53     
54         ArrayList JavaDoc list = getController().getAccountsOfCustomer(customerId);
55
56         String JavaDoc[] res = new String JavaDoc[list.size()];
57         Iterator JavaDoc it_list = list.iterator();
58         for (int i=0; it_list.hasNext(); i++) {
59         AccountDetails details = (AccountDetails) it_list.next();
60         res[i] = details.getAccountId();
61         }
62
63         return res;
64     } catch (Exception JavaDoc e) {
65         e.printStackTrace();
66         return new String JavaDoc[0];
67     }
68     }
69
70
71     public void ejbCreate() { }
72     public void ejbRemove() { }
73     
74     public void ejbActivate() { }
75     public void ejbPassivate() { }
76
77     public void setSessionContext(SessionContext JavaDoc sc) { }
78 }
79
Popular Tags