KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > ejb > SecurityOfficerBean


1 package test.ejb;
2
3 import test.interfaces.Customer;
4 import test.interfaces.CustomerHome;
5
6 import javax.ejb.EJBException JavaDoc;
7 import javax.ejb.FinderException JavaDoc;
8 import javax.ejb.SessionBean JavaDoc;
9 import javax.ejb.SessionContext JavaDoc;
10 import javax.naming.InitialContext JavaDoc;
11 import javax.naming.NamingException JavaDoc;
12 import java.rmi.RemoteException JavaDoc;
13 import java.util.Collection JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 /**
17  * This Bean serves as an example of a session bean that does not require a subclass to
18  * be generated, but is included in the deployment descriptor generation. It is a _very_ simple
19  * stupid example.
20  *
21  * @ejb.bean
22  * generate="false"
23  * jndi-name="ejb/bank/SecurityOfficer"
24  * name="SecurityOfficer"
25  * type="Stateless"
26  * @ejb.ejb-ref
27  * ejb-name="SecurityOfficer"
28  * @ejb.permission
29  * role-name="SecurityOfficer"
30  * @ejb.interface
31  * generate="false"
32  * @ejb.home
33  * generate="false"
34  * @ejb.util
35  * generate="false"
36  * @jboss.container-configuration
37  * name="Standard Stateless SessionBean"
38  * @jboss.ejb-ref-jndi
39  * jndi-name="ejb/bank/Customer"
40  * ref-name="bank/Customer"
41  *
42  * @jonas.bean ejb-name="SecurityOfficer"
43  * jndi-name="SecurityOfficerHome"
44  * @jonas.ejb-ref ejb-ref-name="ejb/SecurityOfficer"
45  * jndi-name="SecurityOfficer"
46  */

47 public class SecurityOfficerBean implements SessionBean JavaDoc {
48     // SessionBean implementation -----------------------------------
49

50     private SessionContext JavaDoc sessionContext;
51
52     /**
53      */

54     public void setSessionContext(SessionContext JavaDoc context) {
55         this.sessionContext = context;
56     }
57
58     /**
59      */

60     public void ejbRemove() {
61         ;
62     }
63
64     /**
65      */

66     public void ejbActivate() {
67         ;
68     }
69
70     /**
71      */

72     public void ejbPassivate() {
73         ;
74     }
75
76     /**
77      */

78     public void patrolBank() {
79         System.out.println("Patrolling bank.");
80
81         try {
82             CustomerHome home = (CustomerHome) new InitialContext JavaDoc().lookup("java:comp/env/ejb/bank/Customer");
83             Collection JavaDoc customers = home.findAll();
84             for (Iterator JavaDoc customersInBank = customers.iterator(); customersInBank.hasNext();) {
85                 Customer customer = (Customer) customersInBank.next();
86                 customer.talkTo();
87             }
88         }
89         catch (NamingException JavaDoc e) {
90             throw new EJBException JavaDoc("Unable to find any customers: " + e.getMessage());
91         }
92         catch (RemoteException JavaDoc e) {
93             throw new EJBException JavaDoc("Unable to find any customers: " + e.getMessage());
94         }
95         catch (FinderException JavaDoc e) {
96             throw new EJBException JavaDoc("Unable to find any customers: " + e.getMessage());
97         }
98     }
99
100 }
101
Popular Tags