KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > testCallEJB2InSB_TestingSessionBean


1 package test;
2
3 import java.util.logging.Level JavaDoc;
4 import java.util.logging.Logger JavaDoc;
5 import javax.ejb.*;
6 import javax.naming.Context JavaDoc;
7 import javax.naming.InitialContext JavaDoc;
8 import javax.naming.NamingException JavaDoc;
9 import javax.rmi.PortableRemoteObject JavaDoc;
10
11 /**
12  * This is the bean class for the TestingSessionBean enterprise bean.
13  * Created 29.4.2005 15:24:25
14  * @author lm97939
15  */

16 public class TestingSessionBean implements SessionBean, TestingSessionRemoteBusiness, TestingSessionLocalBusiness {
17     private SessionContext context;
18     
19     // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
20
// TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
21
// TODO Add business methods or web service operations
22
/**
23      * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
24      */

25     public void setSessionContext(SessionContext aContext) {
26         context = aContext;
27     }
28     
29     /**
30      * @see javax.ejb.SessionBean#ejbActivate()
31      */

32     public void ejbActivate() {
33         
34     }
35     
36     /**
37      * @see javax.ejb.SessionBean#ejbPassivate()
38      */

39     public void ejbPassivate() {
40         
41     }
42     
43     /**
44      * @see javax.ejb.SessionBean#ejbRemove()
45      */

46     public void ejbRemove() {
47         
48     }
49     // </editor-fold>
50

51     /**
52      * See section 7.10.3 of the EJB 2.0 specification
53      * See section 7.11.3 of the EJB 2.1 specification
54      */

55     public void ejbCreate() {
56         // TODO implement ejbCreate if necessary, acquire resources
57
// This method has access to the JNDI context so resource aquisition
58
// spanning all methods can be performed here such as home interfaces
59
// and data sources.
60
}
61     
62     
63     
64     // Add business logic below. (Right-click in editor and choose
65
// "EJB Methods > Add Business Method" or "Web Service > Add Operation")
66

67     public String JavaDoc testBusinessMethod1() {
68         //TODO implement testBusinessMethod1
69
return null;
70     }
71
72     public String JavaDoc testBusinessMethod2(String JavaDoc a, int b) throws Exception JavaDoc {
73         //TODO implement testBusinessMethod2
74
return null;
75     }
76
77     private TestingEntityLocalHome lookupTestingEntityBean() {
78         try {
79             Context JavaDoc c = new InitialContext JavaDoc();
80             TestingEntityLocalHome rv = (TestingEntityLocalHome) c.lookup("java:comp/env/ejb/TestingEntityBean");
81             return rv;
82         }
83         catch(NamingException JavaDoc ne) {
84             Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne);
85             throw new RuntimeException JavaDoc(ne);
86         }
87     }
88
89     private TestingEntityRemoteHome lookupMyTestingEntityBean() {
90         try {
91             Context JavaDoc c = new InitialContext JavaDoc();
92             Object JavaDoc remote = c.lookup("java:comp/env/ejb/MyTestingEntityBean");
93             TestingEntityRemoteHome rv = (TestingEntityRemoteHome) PortableRemoteObject.narrow(remote, TestingEntityRemoteHome.class);
94             return rv;
95         }
96         catch(NamingException JavaDoc ne) {
97             Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne);
98             throw new RuntimeException JavaDoc(ne);
99         }
100     }
101     
102     
103     
104 }
105
Popular Tags