KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > local > TargetSL


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: TargetSL.java,v 1.9 2005/07/26 15:09:56 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.local;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.SessionBean JavaDoc;
30 import javax.ejb.SessionContext JavaDoc;
31 import javax.naming.InitialContext JavaDoc;
32 import javax.transaction.UserTransaction 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
41  * @author Philippe Durieux, Philippe Coq
42  */

43 public class TargetSL implements SessionBean JavaDoc {
44
45     static protected Logger logger = null;
46     SessionContext JavaDoc ejbContext;
47
48     public String JavaDoc string;
49     public int number;
50     public boolean createdViaCreateXX;
51     public boolean createdViaCreateYY;
52     private int [] inttable = new int[30];
53
54     // ------------------------------------------------------------------
55
// SessionBean implementation
56
// ------------------------------------------------------------------
57

58     /**
59      * Set the associated session context. The container calls this method
60      * after the instance creation.
61      * The enterprise Bean instance should store the reference to the context
62      * object in an instance variable.
63      * This method is called with no transaction context.
64      *
65      * @param sessionContext A SessionContext interface for the instance.
66      * @throws EJBException Thrown by the method to indicate a failure caused by
67      * a system-level error.
68      */

69     public void setSessionContext(SessionContext JavaDoc ctx) {
70         if (logger == null) {
71             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
72         }
73         logger.log(BasicLevel.DEBUG, "");
74         ejbContext = ctx;
75     }
76     
77     /**
78      * A container invokes this method before it ends the life of the session object.
79      * This happens as a result of a client's invoking a remove operation, or when a
80      * container decides to terminate the session object after a timeout.
81      * This method is called with no transaction context.
82      *
83      * @throws EJBException Thrown by the method to indicate a failure caused by
84      * a system-level error.
85      */

86     public void ejbRemove() {
87         logger.log(BasicLevel.DEBUG, "");
88     }
89     
90     /**
91      * Check allowed and disallowed methods (See spec EJB 2.1 p 100)
92      * @throws CreateException Failure to create a session EJB object.
93      */

94     public void ejbCreate() throws CreateException JavaDoc {
95         logger.log(BasicLevel.DEBUG, "");
96         
97         // These operations are allowed
98
ejbContext.getEJBHome();
99         ejbContext.getEJBLocalHome();
100         ejbContext.getEJBObject();
101         ejbContext.getEJBLocalObject();
102         ejbContext.getTimerService();
103         
104         try {
105             // Must access java:comp/env
106
InitialContext JavaDoc ictx = new InitialContext JavaDoc();
107             ictx.lookup("java:comp/env/myname");
108         } catch (Exception JavaDoc e) {
109             logger.log(BasicLevel.ERROR, "Cannot lookup java:comp/env/myname: " + e);
110             throw new CreateException JavaDoc("Cannot lookup java:comp/env/myname: " + e);
111         }
112         
113         // These operations are disallowed
114
try {
115             ejbContext.getCallerPrincipal();
116             throw new CreateException JavaDoc("getCallerPrincipal disallowed");
117         } catch (IllegalStateException JavaDoc e) {
118             logger.log(BasicLevel.DEBUG, "getCallerPrincipal disallowed");
119         }
120         try {
121             ejbContext.isCallerInRole("");
122             throw new CreateException JavaDoc("isCallerInRole disallowed");
123         } catch (IllegalStateException JavaDoc e) {
124             logger.log(BasicLevel.DEBUG, "isCallerInRole disallowed");
125         }
126     }
127
128     /**
129      * A container invokes this method on an instance before the instance
130      * becomes disassociated with a specific EJB object.
131      */

132     public void ejbPassivate() {
133         logger.log(BasicLevel.DEBUG, "");
134     }
135
136     /**
137      * A container invokes this method when the instance is taken out of
138      * the pool of available instances to become associated with a specific
139      * EJB object.
140      */

141     public void ejbActivate() {
142         logger.log(BasicLevel.DEBUG, "");
143     }
144     
145     // ------------------------------------------------------------------
146
// LocalInterface implementation
147
// ------------------------------------------------------------------
148

149     /**
150      * getTwenty
151      */

152     public int getTwenty() {
153         logger.log(BasicLevel.DEBUG, "");
154         return 20;
155     }
156
157     /**
158      * lmethod2
159      */

160     public void lmethod2(java.lang.String JavaDoc s) {
161         logger.log(BasicLevel.DEBUG, "");
162     }
163
164     // ------------------------------------------------------------------
165
// Target implementation
166
// ------------------------------------------------------------------
167

168     /**
169      * getTen
170      */

171     public int getTen() {
172         logger.log(BasicLevel.DEBUG, "");
173         return 10;
174     }
175
176     /**
177      * method2
178      */

179     public void method2(java.lang.String JavaDoc s) {
180         logger.log(BasicLevel.DEBUG, "");
181     }
182
183     /**
184      * getNumber
185      * Not called
186      */

187     public int getNumber() {
188         logger.log(BasicLevel.DEBUG, "");
189         return 0;
190     }
191
192     /**
193      * getString
194      * Not called
195      */

196     public String JavaDoc getString() {
197         logger.log(BasicLevel.DEBUG, "");
198         return null;
199     }
200
201     /**
202      * isCreatedViaCreateXX
203      * Not called
204      */

205     public boolean isCreatedViaCreateXX() {
206         logger.log(BasicLevel.DEBUG, "");
207         return false;
208     }
209
210
211 }
212
Popular Tags