KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > ejbql > SessionTestBean


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SessionTestBean.java,v 1.2 2004/03/19 11:57:17 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.ejbql;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.EJBException JavaDoc;
30 import javax.ejb.SessionBean JavaDoc;
31 import javax.ejb.SessionContext JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.util.monolog.api.Logger;
37
38
39 /**
40  * Stateless Session useful to do some specifics tests which local interfaces are needed.
41  * @author Helene Joanin
42  */

43 public class SessionTestBean implements SessionBean JavaDoc {
44
45     static protected Logger logger = null;
46     protected SessionContext JavaDoc ctx = null;
47     protected CustomerHomeLocal hCustomer = null;
48     protected PhoneHomeLocal hPhone = null;
49
50     // SessionBean methods implementation
51
public void setSessionContext(SessionContext JavaDoc ctx) {
52         if (logger == null) {
53             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
54         }
55         logger.log(BasicLevel.DEBUG, "");
56         this.ctx = ctx;
57         try {
58             InitialContext JavaDoc inctx = new InitialContext JavaDoc();
59             hCustomer = (CustomerHomeLocal) inctx.lookup("java:comp/env/ejb/CustomerHomeLocal");
60             hPhone = (PhoneHomeLocal) inctx.lookup("java:comp/env/ejb/PhoneHomeLocal");
61         } catch (Exception JavaDoc e) {
62             throw new javax.ejb.EJBException JavaDoc(e);
63         }
64     }
65
66     public void ejbCreate() throws CreateException JavaDoc {
67         logger.log(BasicLevel.DEBUG, "");
68     }
69
70     public void ejbRemove() {
71         logger.log(BasicLevel.DEBUG, "");
72     }
73
74     public void ejbPassivate() {
75         logger.log(BasicLevel.DEBUG, "");
76     }
77
78     public void ejbActivate() {
79         logger.log(BasicLevel.DEBUG, "");
80     }
81
82     // SessionTestRemote implementation
83
public Integer JavaDoc getCustomerWithPhone(String JavaDoc phoneNumber) throws EJBException JavaDoc {
84         try {
85             PhoneLocal phone = hPhone.findByNumber(phoneNumber);
86             CustomerLocal customer = hCustomer.findCustomerWithPhone(phone);
87             return customer.getId();
88         } catch (Exception JavaDoc e) {
89             logger.log(BasicLevel.ERROR, "Cannot get the customer with phone " + phoneNumber, e);
90             throw new EJBException JavaDoc("Cannot get the customer with phone " + phoneNumber, e);
91         }
92     }
93 }
94
95
Popular Tags