KickJava   Java API By Example, From Geeks To Geeks.

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


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: JSessionRemote.java,v 1.19 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.container;
27
28 import java.rmi.Remote JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.ejb.EJBHome JavaDoc;
32 import javax.ejb.EJBObject JavaDoc;
33 import javax.ejb.Handle JavaDoc;
34 import javax.ejb.RemoveException JavaDoc;
35 import javax.rmi.PortableRemoteObject JavaDoc;
36
37 import org.objectweb.carol.rmi.exception.RmiUtility;
38 import org.objectweb.carol.util.configuration.ConfigurationRepository;
39
40 import org.objectweb.jonas_ejb.lib.EJBInvocation;
41 import org.objectweb.jonas_ejb.svc.JHandleIIOP;
42
43 import org.objectweb.util.monolog.api.BasicLevel;
44
45 /**
46  * Generic part of the EJBObject implementation
47  * @author Philippe Coq
48  * @author Philippe Durieux
49  */

50 public abstract class JSessionRemote extends JRemote implements Remote JavaDoc {
51
52
53     /**
54      * <code>bs</code>
55      */

56     protected JSessionSwitch bs;
57
58     /**
59      * constructor
60      * @param bf The Session Factory
61      * @throws RemoteException Thrown when the method failed due to a system-level failure.
62      */

63     public JSessionRemote(JSessionFactory bf) throws RemoteException JavaDoc {
64         super((JFactory) bf);
65         if (TraceEjb.isDebugIc()) {
66             TraceEjb.interp.log(BasicLevel.DEBUG, "");
67         }
68     }
69
70     // --------------------------------------------------------------------------
71
// EJBObject implementation
72
// remove() is implemented in the generated part.
73
// --------------------------------------------------------------------------
74

75     /**
76      * remove is implemented in the generated part.
77      * @throws RemoteException Thrown when the method failed due to a system-level failure.
78      * @throws RemoveException Thrown when the method failed due to remove failure.
79      */

80     public abstract void remove() throws RemoteException JavaDoc, RemoveException JavaDoc;
81
82     /**
83      * @return the enterprise Bean's home interface.
84      */

85     public EJBHome JavaDoc getEJBHome() {
86         /*
87          * try/catch block is commented because the encapsulated code don't
88          * throw a RemoteException
89          * If the code changes and throws a such exception, let's think
90          * to uncomment it
91          *
92          * try {
93          */

94
95         return bf.getHome();
96
97         /*
98          * } catch (RemoteException e) {
99          * // check if rmi exception mapping is needed - if yes the method rethrows it
100          * RmiUtility.rethrowRmiException(e);
101          * // if not, throws the exception just as it is
102          * throw e;
103          * }
104          */

105
106     }
107
108     /**
109      * @throws RemoteException Always : Session bean has never a primary key
110      * @return never carried out because a exception is thrown
111      */

112     public Object JavaDoc getPrimaryKey() throws RemoteException JavaDoc {
113
114         try {
115             throw new RemoteException JavaDoc("Session bean has no primary key");
116         } catch (RemoteException JavaDoc e) {
117             // check if rmi exception mapping is needed - if yes the method rethrows it
118
RmiUtility.rethrowRmiException(e);
119             // if not, throws the exception just as it is
120
throw e;
121             }
122     }
123
124     /**
125      * Tests if a given EJB is identical to the invoked EJB object. This is
126      * different whether the bean is stateless or stateful.
127      * @param obj - An object to test for identity with the invoked object.
128      * @return True if the given EJB object is identical to the invoked object.
129      * @throws RemoteException Thrown when the method failed due to a system-level failure.
130      */

131     public boolean isIdentical(EJBObject JavaDoc obj) throws RemoteException JavaDoc {
132         if (TraceEjb.isDebugIc()) {
133             TraceEjb.interp.log(BasicLevel.DEBUG, "");
134         }
135         try {
136         boolean ret = false;
137             JSessionFactory sf = (JSessionFactory) bf;
138             if (sf.isStateful()) {
139                 // For stateful sessions, just compare both objects.
140
if (obj != null) {
141                     ret = ((obj.equals(PortableRemoteObject.toStub(this))) || (obj.equals(this)));
142                 }
143             } else {
144                 // In case of Stateless session bean, we must compare the 2 Home
145
// We cannot cast the remote EJBObject cbecause it's a stub.
146
String JavaDoc myhome = getEJBHome().getEJBMetaData().getHomeInterfaceClass().getName();
147                 if (obj != null) {
148                     ret = obj.getEJBHome().getEJBMetaData().getHomeInterfaceClass().getName().equals(myhome);
149                 }
150             }
151             return ret;
152         } catch (RemoteException JavaDoc e) {
153             // check if rmi exception mapping is needed - if yes the method
154
// rethrows it
155
RmiUtility.rethrowRmiException(e);
156             // if not, throws the exception just as it is
157
throw e;
158         }
159     }
160
161     /**
162      * Obtains a handle for the EJB object. The handle can be used at later time
163      * to re-obtain a reference to the EJB object, possibly in a different JVM.
164      * @return A handle for the EJB object.
165      * @exception RemoteException Thrown when the method failed due to a
166      * system-level failure.
167      */

168     public Handle JavaDoc getHandle() throws RemoteException JavaDoc {
169         if (TraceEjb.isDebugIc()) {
170             TraceEjb.interp.log(BasicLevel.DEBUG, "");
171         }
172
173         /*
174          * try/catch block is commented because the encapsulated code don't
175          * throw a RemoteException
176          * If the code changes and throws a such exception, let's think
177          * to uncomment it
178          *
179          * try {
180          */

181         // for iiop, a specific interoperable Handle is created with the use of
182
// HandleDelegate
183
String JavaDoc protocol = ConfigurationRepository.getCurrentConfiguration().getProtocol().getName();
184         if (TraceEjb.interp.isLoggable(BasicLevel.DEBUG)) {
185             TraceEjb.interp.log(BasicLevel.DEBUG, "Current protocol = " + protocol);
186         }
187
188         if (protocol.equals("iiop")) {
189             return new JHandleIIOP(this);
190         } else {
191             return new JSessionHandle(this);
192         }
193
194         /*
195          * } catch (RemoteException e) {
196          * // check if rmi exception mapping is needed - if yes the method rethrows it
197          * RmiUtility.rethrowRmiException(e);
198          * // if not, throws the exception just as it is
199          * throw e;
200          * }
201          */

202
203     }
204
205     // ---------------------------------------------------------------
206
// other public methods, for internal use.
207
// ---------------------------------------------------------------
208

209     /**
210      * finish initialization
211      * @param bs the SessionSwitch
212      */

213     public void setSessionSwitch(JSessionSwitch bs) {
214         if (TraceEjb.isDebugIc()) {
215             TraceEjb.interp.log(BasicLevel.DEBUG, "");
216         }
217         this.bs = bs;
218     }
219
220     /**
221      * @return the JSessionSwitch for this Session
222      */

223     public JSessionSwitch getSessionSwitch() {
224         return bs;
225     }
226
227     /**
228      * preInvoke is called before any request.
229      * @param txa Transaction Attribute (Supports, Required, ...)
230      * @return A RequestCtx object
231      * @throws RemoteException Thrown when the method failed due to a
232      * system-level failure.
233      */

234     public RequestCtx preInvoke(int txa) throws RemoteException JavaDoc {
235         if (TraceEjb.isDebugIc()) {
236             TraceEjb.interp.log(BasicLevel.DEBUG, "");
237         }
238         RequestCtx rctx = bf.preInvokeRemote(txa);
239         bs.setMustCommit(rctx.mustCommit); // for remove stateful session
240
bs.enlistConnections(rctx.currTx); // Enlist connection list to tx
241
return rctx;
242     }
243
244     /**
245      * Check if the access to the bean is authorized
246      * @param ejbInv object containing security signature of the method, args of
247      * method, etc
248      */

249     public void checkSecurity(EJBInvocation ejbInv) {
250         if (TraceEjb.isDebugIc()) {
251             TraceEjb.interp.log(BasicLevel.DEBUG, "");
252         }
253         bf.checkSecurity(ejbInv);
254     }
255
256     /**
257      * postInvoke is called after any request.
258      * @param rctx The RequestCtx that was returned at preInvoke()
259      * @throws RemoteException Thrown when the method failed due to a
260      * system-level failure.
261      */

262     public void postInvoke(RequestCtx rctx) throws RemoteException JavaDoc {
263         if (TraceEjb.isDebugIc()) {
264             TraceEjb.interp.log(BasicLevel.DEBUG, "");
265         }
266         bs.delistConnections(rctx.currTx);
267         // save current tx (for Bean Managed only)
268
bs.saveBeanTx();
269         try {
270             bf.postInvokeRemote(rctx);
271         } finally {
272             if (rctx.sysExc != null) {
273                 bs.discardICtx(rctx.currTx);
274             } else {
275                 bs.releaseICtx(rctx.currTx);
276             }
277         }
278     }
279
280 }
281
Popular Tags