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: TargetSL.java 7105 2005-07-26 15:09:56Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.local;
027:
028: import javax.ejb.CreateException;
029: import javax.ejb.SessionBean;
030: import javax.ejb.SessionContext;
031: import javax.naming.InitialContext;
032: import javax.transaction.UserTransaction;
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
040: * @author Philippe Durieux, Philippe Coq
041: */
042: public class TargetSL implements SessionBean {
043:
044: static protected Logger logger = null;
045: SessionContext ejbContext;
046:
047: public String string;
048: public int number;
049: public boolean createdViaCreateXX;
050: public boolean createdViaCreateYY;
051: private int[] inttable = new int[30];
052:
053: // ------------------------------------------------------------------
054: // SessionBean implementation
055: // ------------------------------------------------------------------
056:
057: /**
058: * Set the associated session context. The container calls this method
059: * after the instance creation.
060: * The enterprise Bean instance should store the reference to the context
061: * object in an instance variable.
062: * This method is called with no transaction context.
063: *
064: * @param sessionContext A SessionContext interface for the instance.
065: * @throws EJBException Thrown by the method to indicate a failure caused by
066: * a system-level error.
067: */
068: public void setSessionContext(SessionContext ctx) {
069: if (logger == null) {
070: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
071: }
072: logger.log(BasicLevel.DEBUG, "");
073: ejbContext = ctx;
074: }
075:
076: /**
077: * A container invokes this method before it ends the life of the session object.
078: * This happens as a result of a client's invoking a remove operation, or when a
079: * container decides to terminate the session object after a timeout.
080: * This method is called with no transaction context.
081: *
082: * @throws EJBException Thrown by the method to indicate a failure caused by
083: * a system-level error.
084: */
085: public void ejbRemove() {
086: logger.log(BasicLevel.DEBUG, "");
087: }
088:
089: /**
090: * Check allowed and disallowed methods (See spec EJB 2.1 p 100)
091: * @throws CreateException Failure to create a session EJB object.
092: */
093: public void ejbCreate() throws CreateException {
094: logger.log(BasicLevel.DEBUG, "");
095:
096: // These operations are allowed
097: ejbContext.getEJBHome();
098: ejbContext.getEJBLocalHome();
099: ejbContext.getEJBObject();
100: ejbContext.getEJBLocalObject();
101: ejbContext.getTimerService();
102:
103: try {
104: // Must access java:comp/env
105: InitialContext ictx = new InitialContext();
106: ictx.lookup("java:comp/env/myname");
107: } catch (Exception e) {
108: logger.log(BasicLevel.ERROR,
109: "Cannot lookup java:comp/env/myname: " + e);
110: throw new CreateException(
111: "Cannot lookup java:comp/env/myname: " + e);
112: }
113:
114: // These operations are disallowed
115: try {
116: ejbContext.getCallerPrincipal();
117: throw new CreateException("getCallerPrincipal disallowed");
118: } catch (IllegalStateException e) {
119: logger.log(BasicLevel.DEBUG,
120: "getCallerPrincipal disallowed");
121: }
122: try {
123: ejbContext.isCallerInRole("");
124: throw new CreateException("isCallerInRole disallowed");
125: } catch (IllegalStateException e) {
126: logger.log(BasicLevel.DEBUG, "isCallerInRole disallowed");
127: }
128: }
129:
130: /**
131: * A container invokes this method on an instance before the instance
132: * becomes disassociated with a specific EJB object.
133: */
134: public void ejbPassivate() {
135: logger.log(BasicLevel.DEBUG, "");
136: }
137:
138: /**
139: * A container invokes this method when the instance is taken out of
140: * the pool of available instances to become associated with a specific
141: * EJB object.
142: */
143: public void ejbActivate() {
144: logger.log(BasicLevel.DEBUG, "");
145: }
146:
147: // ------------------------------------------------------------------
148: // LocalInterface implementation
149: // ------------------------------------------------------------------
150:
151: /**
152: * getTwenty
153: */
154: public int getTwenty() {
155: logger.log(BasicLevel.DEBUG, "");
156: return 20;
157: }
158:
159: /**
160: * lmethod2
161: */
162: public void lmethod2(java.lang.String s) {
163: logger.log(BasicLevel.DEBUG, "");
164: }
165:
166: // ------------------------------------------------------------------
167: // Target implementation
168: // ------------------------------------------------------------------
169:
170: /**
171: * getTen
172: */
173: public int getTen() {
174: logger.log(BasicLevel.DEBUG, "");
175: return 10;
176: }
177:
178: /**
179: * method2
180: */
181: public void method2(java.lang.String s) {
182: logger.log(BasicLevel.DEBUG, "");
183: }
184:
185: /**
186: * getNumber
187: * Not called
188: */
189: public int getNumber() {
190: logger.log(BasicLevel.DEBUG, "");
191: return 0;
192: }
193:
194: /**
195: * getString
196: * Not called
197: */
198: public String getString() {
199: logger.log(BasicLevel.DEBUG, "");
200: return null;
201: }
202:
203: /**
204: * isCreatedViaCreateXX
205: * Not called
206: */
207: public boolean isCreatedViaCreateXX() {
208: logger.log(BasicLevel.DEBUG, "");
209: return false;
210: }
211:
212: }
|