1 package com.jboss.ebank; 2 3 import java.math.BigDecimal ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 7 import javax.naming.InitialContext ; 8 import javax.naming.NamingException ; 9 import java.rmi.RemoteException ; 10 11 import javax.ejb.SessionBean ; 12 import javax.ejb.SessionContext ; 13 import javax.ejb.CreateException ; 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 21 { 22 public TellerBean() { 23 } 24 25 private AccountController getController() 26 throws RemoteException , 27 NamingException , 28 CreateException 29 { 30 InitialContext ctx = new InitialContext (); 31 AccountControllerHome home = (AccountControllerHome) 32 ctx.lookup("java:comp/env/ejb/account"); 33 34 return home.create(); 35 } 36 37 public BigDecimal getAccountBalance(String accountID) { 38 try { 39 AccountController mgr = getController(); 40 AccountDetails details = mgr.getDetails(accountID); 41 42 return details.getBalance(); 43 } catch (Exception e) { 44 e.printStackTrace(); 45 return new BigDecimal (0); 46 } 47 } 48 49 public String [] getAccountsOfCustomer(String customerId) 50 { 51 try { 52 AccountController mgr = getController(); 53 54 ArrayList list = getController().getAccountsOfCustomer(customerId); 55 56 String [] res = new String [list.size()]; 57 Iterator 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 e) { 65 e.printStackTrace(); 66 return new String [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 sc) { } 78 } 79 | Popular Tags |