KickJava   Java API By Example, From Geeks To Geeks.

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


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: JEntityRemote.java,v 1.11 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.EJBException JavaDoc;
32 import javax.ejb.EJBHome JavaDoc;
33 import javax.ejb.EJBObject JavaDoc;
34
35 import org.objectweb.carol.rmi.exception.RmiUtility;
36
37 import org.objectweb.jonas_ejb.lib.EJBInvocation;
38
39 import org.objectweb.util.monolog.api.BasicLevel;
40
41 /**
42  * Generic part of the EJBObject implementation
43  * @author Philippe Coq
44  * @author Philippe Durieux
45  */

46 public abstract class JEntityRemote extends JRemote implements Remote JavaDoc {
47
48     protected JEntityFactory ebf;
49
50     protected JEntitySwitch bs;
51
52     /**
53      * constructor
54      * @param bf The Entity Factory
55      */

56     public JEntityRemote(JEntityFactory bf) throws RemoteException JavaDoc {
57         super(bf);
58         if (TraceEjb.isDebugIc()) {
59             TraceEjb.interp.log(BasicLevel.DEBUG, "");
60         }
61         this.ebf = bf;
62     }
63
64     /**
65      * finish initialization
66      * @param bs The Entity Bean Switch
67      */

68     public void setEntitySwitch(JEntitySwitch bs) {
69         if (TraceEjb.isDebugIc()) {
70             TraceEjb.interp.log(BasicLevel.DEBUG, "");
71         }
72         this.bs = bs;
73     }
74
75     // --------------------------------------------------------------------------
76
// EJBObject implementation
77
// remove() is implemented in the generated part.
78
// --------------------------------------------------------------------------
79

80     /**
81      * @return the enterprise Bean's home interface.
82      */

83     public EJBHome JavaDoc getEJBHome() {
84         if (TraceEjb.isDebugIc()) {
85             TraceEjb.interp.log(BasicLevel.DEBUG, "");
86         }
87
88         /*
89          * try/catch block is commented because the encapsulated code don't
90          * throw a RemoteException for the moment
91          * If the code changes and throws a such exception, let's think
92          * to uncomment it
93          *
94          * try {
95          */

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

107
108     }
109
110     /**
111      * @return the Primary Key for this EJBObject
112      * @throws EJBException Bean has no primary key yet.
113      */

114     public Object JavaDoc getPrimaryKey() {
115         if (TraceEjb.isDebugIc()) {
116             TraceEjb.interp.log(BasicLevel.DEBUG, "");
117         }
118         /*
119          * try/catch block is commented because the encapsulated code don't
120          * throw a RemoteException for the moment
121          * If the code changes and throws a such exception, let's think
122          * to uncomment it
123          *
124          * try {
125          */

126
127         if (bs == null) {
128             throw new EJBException JavaDoc("No Primary Key yet");
129         }
130         return bs.getPrimaryKey();
131
132         /*
133          * } catch (RemoteException e) {
134          * // check if rmi exception mapping is needed - if yes the method rethrows it
135          * RmiUtility.rethrowRmiException(e);
136          * // if not, throws the exception just as it is
137          * throw e;
138          * }
139          */

140
141     }
142
143     /**
144      * Tests if a given EJB is identical to the invoked EJB object.
145      * @param obj - An object to test for identity with the invoked object.
146      * @return True if the given EJB object is identical to the invoked object.
147      * @throws RemoteException Thrown when the method failed due to a
148      * system-level failure.
149      */

150     public boolean isIdentical(EJBObject JavaDoc obj) throws RemoteException JavaDoc {
151         if (TraceEjb.isDebugIc()) {
152             TraceEjb.interp.log(BasicLevel.DEBUG, "");
153         }
154
155         try {
156
157             boolean ret = false;
158
159             if (obj != null) { // Get the home class name
160
String JavaDoc homeClassName = getEJBHome().getEJBMetaData().getHomeInterfaceClass().getName();
161                 String JavaDoc objHomeClassName = obj.getEJBHome().getEJBMetaData().getHomeInterfaceClass().getName();
162
163                 // Tests the home equality and the primary key equality
164
ret = ((obj.equals(this)) || ((objHomeClassName.equals(homeClassName)) && (obj.getPrimaryKey()
165                         .equals(getPrimaryKey()))));
166             }
167
168             return ret;
169
170         } catch (RemoteException JavaDoc e) {
171          // check if rmi exception mapping is needed - if yes the method rethrows it
172
RmiUtility.rethrowRmiException(e);
173          // if not, throws the exception just as it is
174
throw e;
175          }
176
177     }
178
179     // ---------------------------------------------------------------
180
// other public methods, for internal use.
181
// ---------------------------------------------------------------
182

183     /**
184      * preInvoke is called before any request.
185      * @param txa Transaction Attribute (Supports, Required, ...)
186      * @return A RequestCtx object
187      * @throws RemoteException
188      */

189     public RequestCtx preInvoke(int txa) throws RemoteException JavaDoc {
190         if (TraceEjb.isDebugIc()) {
191             TraceEjb.interp.log(BasicLevel.DEBUG, "");
192         }
193         return bf.preInvokeRemote(txa);
194     }
195
196     /**
197      * Check if the access to the bean is authorized
198      * @param ejbInv object containing security signature of the method, args of
199      * method, etc
200      */

201      public void checkSecurity(EJBInvocation ejbInv) {
202          if (TraceEjb.isDebugIc()) {
203              TraceEjb.interp.log(BasicLevel.DEBUG, "");
204          }
205          bf.checkSecurity(ejbInv);
206      }
207
208      /**
209      * postInvoke is called after any request.
210      * @param rctx The RequestCtx that was returned at preInvoke()
211      * @throws RemoteException
212      */

213     public void postInvoke(RequestCtx rctx) throws RemoteException JavaDoc {
214         if (TraceEjb.isDebugIc()) {
215             TraceEjb.interp.log(BasicLevel.DEBUG, "");
216         }
217         try {
218             bf.postInvokeRemote(rctx);
219         } finally {
220             if (rctx.sysExc != null) {
221                 bs.discardICtx(rctx.currTx);
222             } else {
223                 bs.releaseICtx(rctx.currTx);
224             }
225         }
226     }
227
228 }
Popular Tags