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: AppliSession.java 5070 2004-07-06 09:45:43Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.applimet;
027:
028: import java.rmi.RemoteException;
029: import javax.ejb.CreateException;
030: import javax.ejb.SessionBean;
031: import javax.ejb.SessionContext;
032: import javax.naming.Context;
033: import javax.naming.InitialContext;
034: import javax.naming.NamingException;
035: import javax.rmi.PortableRemoteObject;
036: import org.objectweb.jonas.common.Log;
037: import org.objectweb.util.monolog.api.Logger;
038: import org.objectweb.util.monolog.api.BasicLevel;
039:
040: /**
041: */
042: public class AppliSession implements SessionBean {
043:
044: static protected Logger logger = null;
045: private MetHome th;
046: private Met tr;
047:
048: SessionContext ejbContext;
049:
050: public void ejbRemove() throws RemoteException {
051: logger.log(BasicLevel.DEBUG, "");
052: try {
053: tr.remove();
054: } catch (Exception e) {
055: logger.log(BasicLevel.ERROR, "Cannot remove Met:" + e);
056: throw new RemoteException("Cannot remove Met:" + e);
057: }
058: }
059:
060: public void ejbCreate() throws CreateException {
061: logger.log(BasicLevel.DEBUG, "");
062: try {
063: Context ctx = new InitialContext();
064: Object objref = ctx.lookup(MetHome.JNDI_NAME);
065: th = (MetHome) PortableRemoteObject.narrow(objref,
066: MetHome.class);
067: tr = th.create();
068: } catch (Exception e) {
069: logger.log(BasicLevel.ERROR, "Cannot create Met:" + e);
070: throw new CreateException("Cannot create Met:" + e);
071: }
072: }
073:
074: public void methodeApplicative() throws RemoteException {
075: logger.log(BasicLevel.DEBUG, "");
076: try {
077: tr.methode1();
078: } catch (Exception e) {
079: logger.log(BasicLevel.ERROR, "Cannot call Met:" + e);
080: throw new RemoteException("Cannot call Met:" + e);
081: }
082: }
083:
084: public void noTxMethod() throws RemoteException {
085: logger.log(BasicLevel.DEBUG, "");
086: try {
087: ejbContext.getRollbackOnly();
088: throw new RemoteException(
089: "Should get IllegalStateException");
090: } catch (IllegalStateException e) {
091: }
092: }
093:
094: public void ejbActivate() {
095: logger.log(BasicLevel.DEBUG, "");
096: }
097:
098: public void ejbPassivate() {
099: logger.log(BasicLevel.DEBUG, "");
100: }
101:
102: public void setSessionContext(javax.ejb.SessionContext ctx) {
103: if (logger == null) {
104: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
105: }
106: logger.log(BasicLevel.DEBUG, "");
107: ejbContext = ctx;
108: }
109:
110: public void unsetSessionContext() {
111: logger.log(BasicLevel.DEBUG, "");
112: }
113: }
|