KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 package org.objectweb.jonas_ejb.container;
27
28 import java.rmi.NoSuchObjectException JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.ejb.EJBHome JavaDoc;
32 import javax.ejb.EJBMetaData JavaDoc;
33 import javax.ejb.Handle JavaDoc;
34 import javax.ejb.HomeHandle JavaDoc;
35 import javax.ejb.RemoveException JavaDoc;
36 import javax.naming.NamingException JavaDoc;
37 import javax.rmi.PortableRemoteObject JavaDoc;
38
39 import org.objectweb.carol.util.configuration.ConfigurationRepository;
40 import org.objectweb.carol.util.csiv2.SasHelper;
41
42 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
43 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
44 import org.objectweb.jonas_ejb.deployment.api.SessionDesc;
45 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
46 import org.objectweb.jonas_ejb.lib.EJBInvocation;
47 import org.objectweb.jonas_ejb.svc.JHomeHandleIIOP;
48 import org.objectweb.jonas_ejb.svc.JMetaData;
49
50 import org.objectweb.util.monolog.api.BasicLevel;
51
52 /**
53  * This class represents an EJBHome Remote Interface
54  * It is shared between Sessions and Entities.
55  * @author Philippe Coq, Philippe Durieux
56  */

57 public abstract class JHome extends PortableRemoteObject JavaDoc implements EJBHome JavaDoc {
58
59     protected JMetaData ejbMetaData = null;
60     protected BeanDesc dd;
61     protected JFactory bf;
62     protected boolean unregistered = true;
63
64     /**
65      * Constructor for the base class of the specific generated Home object.
66      * @param dd The Been Deployment Descriptor
67      * @param bf The Bean Factory
68      * @throws RemoteException exception
69      */

70     public JHome(BeanDesc dd, JFactory bf) throws RemoteException JavaDoc {
71         if (TraceEjb.isDebugIc()) {
72             TraceEjb.interp.log(BasicLevel.DEBUG, "JHome constructor");
73         }
74         this.dd = dd;
75         this.bf = bf;
76     }
77
78     // ---------------------------------------------------------------
79
// EJBHome Implementation
80
// ---------------------------------------------------------------
81

82     /**
83      * Obtains the EJBMetaData for the enterprise Bean.
84      * @return The enterprise Bean's EJBMetaData
85      * @throws RemoteException exception
86      */

87     public EJBMetaData JavaDoc getEJBMetaData() throws RemoteException JavaDoc {
88
89         if (TraceEjb.isDebugIc()) {
90             TraceEjb.interp.log(BasicLevel.DEBUG, "JHome getEJBMetaData");
91         }
92
93         /*
94          * try/catch block is commented because the encapsulated code don't
95          * throw a RemoteException
96          * If the code changes and throws a such exception, let's think
97          * to uncomment it
98          *
99          * try {
100          */

101         if (ejbMetaData == null) {
102
103             if (dd instanceof SessionDesc) {
104                 boolean isSession = true;
105                 boolean isStatelessSession = (dd instanceof SessionStatelessDesc);
106                 Class JavaDoc primaryKeyClass = null;
107                 ejbMetaData = new JMetaData(this, dd.getHomeClass(), dd.getRemoteClass(), isSession, isStatelessSession, primaryKeyClass);
108           } else if (dd instanceof EntityDesc) {
109               boolean isSession = false;
110               boolean isStatelessSession = false;
111               Class JavaDoc primaryKeyClass = ((EntityDesc) dd).getPrimaryKeyClass();
112               ejbMetaData = new JMetaData(this, dd.getHomeClass(), dd.getRemoteClass(), isSession, isStatelessSession, primaryKeyClass);
113           }
114         }
115         return ejbMetaData;
116         /*
117          * } catch (RemoteException e) {
118          * // check if rmi exception mapping is needed - if yes the method rethrows it
119          * RmiUtility.rethrowRmiException(e);
120          * // if not, throws the exception just as it is
121          * throw e;
122          * }
123          */

124     }
125
126     /**
127      * Obtain a handle for the home object. The handle can be used at later time to re-obtain a
128      * reference to the home object, possibly in a different Java Virtual Machine.
129      * @return A handle for the home object.
130      * @exception java.rmi.RemoteException - Thrown when the method failed due to a system-level
131      * failure.
132      */

133     public HomeHandle JavaDoc getHomeHandle() throws java.rmi.RemoteException JavaDoc {
134         if (TraceEjb.isDebugIc()) {
135             TraceEjb.interp.log(BasicLevel.DEBUG, "");
136         }
137
138         /*
139          * try/catch block is commented because the encapsulated code don't
140          * throw a RemoteException
141          * If the code changes and throws a such exception, let's think
142          * to uncomment it
143          *
144          * try {
145          */

146         // for iiop, a specific interoperable Handle is created with the use of
147
// HandleDelegate
148
String JavaDoc protocol = ConfigurationRepository.getCurrentConfiguration().getProtocol().getName();
149         if (TraceEjb.isDebugIc()) {
150             TraceEjb.interp.log(BasicLevel.DEBUG, "Current protocol = " + protocol);
151         }
152         if (protocol.equals("iiop")) {
153             return new JHomeHandleIIOP(this, bf.myClassLoader());
154         } else {
155             return new JHomeHandle(dd.getJndiName());
156         }
157
158         /*
159          * } catch (RemoteException e) {
160          * // check if rmi exception mapping is needed - if yes the method rethrows it
161          * RmiUtility.rethrowRmiException(e);
162          * // if not, throws the exception just as it is
163          * throw e;
164          * }
165          */

166     }
167
168     /**
169      * Removes an EJB object identified by its handle.
170      * @param handle The EJB Handle
171      * @throws RemoteException exception
172      * @throws RemoveException exception
173      *
174      */

175     public abstract void remove(Handle JavaDoc handle) throws RemoteException JavaDoc, RemoveException JavaDoc;
176
177     /**
178      * Removes an EJB object identified by its primary key.
179      * @param primaryKey The Primary Key
180      * @throws RemoteException exception
181      * @throws RemoveException exception
182      */

183     public abstract void remove(Object JavaDoc primaryKey) throws RemoteException JavaDoc, RemoveException JavaDoc;
184
185     // ---------------------------------------------------------------
186
// other public methods
187
// ---------------------------------------------------------------
188

189     /**
190      * register this bean to JNDI (rebind)
191      * @throws NamingException exception
192      */

193     protected void register() throws NamingException JavaDoc {
194         if (TraceEjb.isDebugIc()) {
195             TraceEjb.interp.log(BasicLevel.DEBUG, "");
196         }
197         String JavaDoc name = dd.getJndiName();
198
199         // register in registry
200
SasHelper.rebind(name, this, dd.getSasComponent());
201
202         unregistered = false;
203     }
204
205     /**
206      * unregister this bean in JNDI (unbind)
207      * @throws NamingException exception
208      */

209     protected void unregister() throws NamingException JavaDoc {
210         if (TraceEjb.isDebugIc()) {
211             TraceEjb.interp.log(BasicLevel.DEBUG, "");
212         }
213         String JavaDoc name = dd.getJndiName();
214         // unregister in default InitialContext
215
bf.getInitialContext().unbind(name);
216
217         try {
218             PortableRemoteObject.unexportObject(this);
219         } catch (NoSuchObjectException JavaDoc e) {
220             TraceEjb.interp.log(BasicLevel.ERROR, "unexportObject(JHome) failed", e);
221         }
222         unregistered = true;
223     }
224
225     /**
226      * Get the jndi name for the bean
227      * @return The jndi name
228      * @throws RemoteException
229      */

230     public String JavaDoc getJndiName() {
231         return dd.getJndiName();
232     }
233
234     /**
235      * preInvoke is called before any request.
236      * @param txa Transaction Attribute (Supports, Required, ...)
237      * @return A RequestCtx object
238      * @throws RemoteException unexpected exception in preinvoke
239      */

240     public RequestCtx preInvoke(int txa) throws RemoteException JavaDoc {
241         if (TraceEjb.isDebugIc()) {
242             TraceEjb.interp.log(BasicLevel.DEBUG, "");
243         }
244         return bf.preInvokeRemote(txa);
245     }
246
247     /**
248      * Check if the access to the bean is authorized
249      * @param ejbInv object containing security signature of the method, args of
250      * method, etc
251      */

252      public void checkSecurity(EJBInvocation ejbInv) {
253          if (TraceEjb.isDebugIc()) {
254              TraceEjb.interp.log(BasicLevel.DEBUG, "");
255          }
256          bf.checkSecurity(ejbInv);
257      }
258
259     /**
260      * postInvoke is called after any request.
261      * @param rctx The RequestCtx that was returned at preInvoke()
262      * @throws RemoteException unexpected exception in postinvoke
263      */

264     public void postInvoke(RequestCtx rctx) throws RemoteException JavaDoc {
265         if (TraceEjb.isDebugIc()) {
266             TraceEjb.interp.log(BasicLevel.DEBUG, "");
267         }
268         bf.postInvokeRemote(rctx);
269     }
270
271     /**
272      * @return Returns the dd.
273      */

274     public BeanDesc getDd() {
275         return dd;
276     }
277     /**
278      * @return the bean factory
279      */

280     public JFactory getBf() {
281         return bf;
282     }
283 }
284
Popular Tags