001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: SessionTestBean.java 4406 2004-03-19 11:57:20Z benoitf $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.ejbql;
027:
028: import javax.ejb.CreateException;
029: import javax.ejb.EJBException;
030: import javax.ejb.SessionBean;
031: import javax.ejb.SessionContext;
032: import javax.naming.InitialContext;
033:
034: import org.objectweb.jonas.common.Log;
035: import org.objectweb.util.monolog.api.BasicLevel;
036: import org.objectweb.util.monolog.api.Logger;
037:
038: /**
039: * Stateless Session useful to do some specifics tests which local interfaces are needed.
040: * @author Helene Joanin
041: */
042: public class SessionTestBean implements SessionBean {
043:
044: static protected Logger logger = null;
045: protected SessionContext ctx = null;
046: protected CustomerHomeLocal hCustomer = null;
047: protected PhoneHomeLocal hPhone = null;
048:
049: // SessionBean methods implementation
050: public void setSessionContext(SessionContext ctx) {
051: if (logger == null) {
052: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
053: }
054: logger.log(BasicLevel.DEBUG, "");
055: this .ctx = ctx;
056: try {
057: InitialContext inctx = new InitialContext();
058: hCustomer = (CustomerHomeLocal) inctx
059: .lookup("java:comp/env/ejb/CustomerHomeLocal");
060: hPhone = (PhoneHomeLocal) inctx
061: .lookup("java:comp/env/ejb/PhoneHomeLocal");
062: } catch (Exception e) {
063: throw new javax.ejb.EJBException(e);
064: }
065: }
066:
067: public void ejbCreate() throws CreateException {
068: logger.log(BasicLevel.DEBUG, "");
069: }
070:
071: public void ejbRemove() {
072: logger.log(BasicLevel.DEBUG, "");
073: }
074:
075: public void ejbPassivate() {
076: logger.log(BasicLevel.DEBUG, "");
077: }
078:
079: public void ejbActivate() {
080: logger.log(BasicLevel.DEBUG, "");
081: }
082:
083: // SessionTestRemote implementation
084: public Integer getCustomerWithPhone(String phoneNumber)
085: throws EJBException {
086: try {
087: PhoneLocal phone = hPhone.findByNumber(phoneNumber);
088: CustomerLocal customer = hCustomer
089: .findCustomerWithPhone(phone);
090: return customer.getId();
091: } catch (Exception e) {
092: logger
093: .log(BasicLevel.ERROR,
094: "Cannot get the customer with phone "
095: + phoneNumber, e);
096: throw new EJBException(
097: "Cannot get the customer with phone " + phoneNumber,
098: e);
099: }
100: }
101: }
|