KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > JSessionLocal


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 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: JSessionLocal.java,v 1.14 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.container;
27
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.EJBLocalHome JavaDoc;
30 import javax.ejb.EJBLocalObject JavaDoc;
31 import javax.ejb.RemoveException JavaDoc;
32
33 import org.objectweb.jonas_ejb.lib.EJBInvocation;
34
35 import org.objectweb.util.monolog.api.BasicLevel;
36
37 /**
38  * Generic part of the EJBLocalObject implementation
39  * @author Philippe Durieux
40  */

41 public abstract class JSessionLocal extends JLocal {
42
43     protected JSessionFactory bf;
44
45     protected JSessionSwitch bs;
46
47     /**
48      * constructor
49      * @param bf The Session Factory
50      */

51     public JSessionLocal(JSessionFactory bf) {
52         super(bf);
53         if (TraceEjb.isDebugIc()) {
54             TraceEjb.interp.log(BasicLevel.DEBUG, "");
55         }
56         this.bf = bf;
57     }
58
59     // --------------------------------------------------------------------------
60
// EJBLocalObject implementation
61
// remove() is implemented in the generated part.
62
// --------------------------------------------------------------------------
63

64     public abstract void remove() throws RemoveException JavaDoc;
65
66     /**
67      * @return the enterprise Bean's local home interface.
68      */

69     public EJBLocalHome JavaDoc getEJBLocalHome() {
70         return bf.getLocalHome();
71     }
72
73     /**
74      * @return the Primary Key for this EJBObject
75      * @throws EJBException Always : Session bean has no primary key
76      */

77     public Object JavaDoc getPrimaryKey() throws EJBException JavaDoc {
78         throw new EJBException JavaDoc("Session bean has no primary key");
79     }
80
81     /**
82      * Tests if a given EJB is identical to the invoked EJB object. This is
83      * different whether the bean is stateless or stateful.
84      * @param EJBLocalObject obj - An object to test for identity with the
85      * invoked object.
86      * @return True if the given EJB object is identical to the invoked object.
87      * @throws EJBException: Thrown when the method failed due to a system-level
88      * failure.
89      */

90     public boolean isIdentical(EJBLocalObject JavaDoc obj) {
91         if (TraceEjb.isDebugIc()) {
92             TraceEjb.interp.log(BasicLevel.DEBUG, "");
93         }
94         boolean ret = false;
95         JSessionFactory sf = bf;
96         if (sf.isStateful()) {
97             // For stateful sessions, just compare both objects.
98
if (obj != null) {
99                 ret = obj.equals(this);
100             }
101         } else {
102             // In case of Stateless session bean, we must compare the 2
103
// factories
104
if (obj != null) {
105                 try {
106                     //a simple cast should work on a local object
107
JSessionLocal ejb2 = (JSessionLocal) obj;
108                     JSessionSwitch bs2 = ejb2.getSessionSwitch();
109                     JSessionFactory bf2 = bs2.getBeanFactory();
110                     ret = bf2.equals(sf);
111                 } catch (Exception JavaDoc e) {
112                     TraceEjb.logger.log(BasicLevel.WARN, "exception:" + e);
113                     throw new EJBException JavaDoc("isIdentical failed", e);
114                 }
115             }
116         }
117         return ret;
118     }
119
120     // ---------------------------------------------------------------
121
// other public methods, for internal use.
122
// ---------------------------------------------------------------
123

124     /**
125      * finish initialization
126      * @param bs The Session Switch
127      */

128     public void setSessionSwitch(JSessionSwitch bs) {
129         if (TraceEjb.isDebugIc()) {
130             TraceEjb.interp.log(BasicLevel.DEBUG, "");
131         }
132         this.bs = bs;
133     }
134
135     /**
136      * @return the JSessionSwitch for this Session
137      */

138     public JSessionSwitch getSessionSwitch() {
139         return bs;
140     }
141
142     /**
143      * preInvoke is called before any request.
144      * @param txa Transaction Attribute (Supports, Required, ...)
145      * @return A RequestCtx object
146      * @throws EJBException
147      */

148     public RequestCtx preInvoke(int txa) {
149         if (TraceEjb.isDebugIc()) {
150             TraceEjb.interp.log(BasicLevel.DEBUG, "");
151         }
152         RequestCtx rctx = bf.preInvoke(txa);
153         bs.setMustCommit(rctx.mustCommit); // for remove stateful session
154
bs.enlistConnections(rctx.currTx); // Enlist connection list to tx
155
return rctx;
156     }
157
158     /**
159      * Check if the access to the bean is authorized
160      * @param ejbInv object containing security signature of the method, args of
161      * method, etc
162      */

163     public void checkSecurity(EJBInvocation ejbInv) {
164         if (TraceEjb.isDebugIc()) {
165             TraceEjb.interp.log(BasicLevel.DEBUG, "");
166         }
167         bf.checkSecurity(ejbInv);
168     }
169
170     /**
171      * postInvoke is called after any request.
172      * @param rctx The RequestCtx that was returned at preInvoke()
173      * @throws EJBException
174      */

175     public void postInvoke(RequestCtx rctx) {
176         if (TraceEjb.isDebugIc()) {
177             TraceEjb.interp.log(BasicLevel.DEBUG, "");
178         }
179         bs.delistConnections(rctx.currTx);
180         // save current tx (for Stateful Bean Managed only)
181
bs.saveBeanTx();
182         try {
183             bf.postInvoke(rctx);
184         } finally {
185             if (rctx.sysExc != null) {
186                 bs.discardICtx(rctx.currTx);
187             } else {
188                 bs.releaseICtx(rctx.currTx);
189             }
190         }
191     }
192
193 }
194
Popular Tags