1 package test.ejb; 2 3 import test.interfaces.Customer; 4 import test.interfaces.CustomerHome; 5 6 import javax.ejb.EJBException ; 7 import javax.ejb.FinderException ; 8 import javax.ejb.SessionBean ; 9 import javax.ejb.SessionContext ; 10 import javax.naming.InitialContext ; 11 import javax.naming.NamingException ; 12 import java.rmi.RemoteException ; 13 import java.util.Collection ; 14 import java.util.Iterator ; 15 16 47 public class SecurityOfficerBean implements SessionBean { 48 50 private SessionContext sessionContext; 51 52 54 public void setSessionContext(SessionContext context) { 55 this.sessionContext = context; 56 } 57 58 60 public void ejbRemove() { 61 ; 62 } 63 64 66 public void ejbActivate() { 67 ; 68 } 69 70 72 public void ejbPassivate() { 73 ; 74 } 75 76 78 public void patrolBank() { 79 System.out.println("Patrolling bank."); 80 81 try { 82 CustomerHome home = (CustomerHome) new InitialContext ().lookup("java:comp/env/ejb/bank/Customer"); 83 Collection customers = home.findAll(); 84 for (Iterator customersInBank = customers.iterator(); customersInBank.hasNext();) { 85 Customer customer = (Customer) customersInBank.next(); 86 customer.talkTo(); 87 } 88 } 89 catch (NamingException e) { 90 throw new EJBException ("Unable to find any customers: " + e.getMessage()); 91 } 92 catch (RemoteException e) { 93 throw new EJBException ("Unable to find any customers: " + e.getMessage()); 94 } 95 catch (FinderException e) { 96 throw new EJBException ("Unable to find any customers: " + e.getMessage()); 97 } 98 } 99 100 } 101 | Popular Tags |