KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > svc > JHomeHandleIIOP


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: JHomeHandleIIOP.java,v 1.1 2005/01/12 14:40:21 pelletib Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.svc;
27
28 import java.io.IOException JavaDoc;
29 import java.io.Serializable JavaDoc;
30 import java.rmi.RemoteException JavaDoc;
31
32 import javax.ejb.EJBHome JavaDoc;
33 import javax.ejb.HomeHandle JavaDoc;
34 import javax.ejb.spi.HandleDelegate JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37
38 import javax.naming.NamingException JavaDoc;
39 import javax.rmi.PortableRemoteObject JavaDoc;
40 import javax.rmi.CORBA.Util JavaDoc;
41
42 import org.omg.PortableServer.Servant JavaDoc;
43
44
45 /**
46  * This class implements javax.ejb.HomeHandle interface. A handle is an
47  * abstraction of a network reference to a home object. A handle is intended to
48  * be used as a "robust" persistent reference to a home object.
49  * @author Philippe Durieux, Philippe Coq
50  */

51 public class JHomeHandleIIOP implements HomeHandle JavaDoc, Serializable JavaDoc {
52
53     /**
54      * JDK logger to be portable
55      */

56     private static Logger JavaDoc logger = Logger.getLogger("org.objectweb.jonas_ejb.svc");
57
58     /**
59      * CORBA ref
60      * @serial
61      */

62     private String JavaDoc ior = null;
63
64     /**
65      * Classloader of EJB
66      */

67     private ClassLoader JavaDoc cl = null;
68
69     /**
70      * EjbHome class
71      */

72     private EJBHome JavaDoc ejbHome = null;
73
74     /**
75      * constructor
76      * @param h EJBHome
77      * @param cl classloader used for EJB
78      */

79     public JHomeHandleIIOP(EJBHome JavaDoc h, ClassLoader JavaDoc cl) {
80         logger.log(Level.FINE, "h=" + h);
81         try {
82             Servant JavaDoc servant = (Servant JavaDoc) Util.getTie(h);
83             org.omg.CORBA.Object JavaDoc o = servant._this_object();
84             this.ior = Utility.getORB().object_to_string(o);
85             this.cl = cl;
86             logger.log(Level.FINE, "ior=" + ior);
87         } catch (Exception JavaDoc e) {
88             logger.log(Level.SEVERE, "cannot get Handle: ", e);
89         }
90     }
91
92     // -----------------------------------------------------------------------
93
// HomeHandle implementation
94
// -----------------------------------------------------------------------
95

96     /**
97      * Obtains the home object represented by this handle.
98      * @throws RemoteException The home object could not be obtained because of
99      * a system-level failure.
100      * @return The EJBHome object
101      */

102     public EJBHome JavaDoc getEJBHome() throws RemoteException JavaDoc {
103         logger.log(Level.FINE, "");
104         ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
105         logger.log(Level.FINE, "");
106         if (ejbHome == null) {
107             try {
108                 Thread.currentThread().setContextClassLoader(cl);
109                 ejbHome = (EJBHome JavaDoc) PortableRemoteObject.narrow(Utility.getORB().string_to_object(ior), EJBHome JavaDoc.class);
110             } catch (NamingException JavaDoc e) {
111                 throw new RemoteException JavaDoc("getEJBHome:" + e);
112             } finally {
113                 // reset
114
Thread.currentThread().setContextClassLoader(old);
115             }
116         }
117         return ejbHome;
118     }
119
120     /**
121      * Specific implementation of serialization.
122      * Must call HandleDelegate.writeEJBObject, as specified in 19.5.5.1 of spec EJB 2.1
123      * @param out The output stream used to write object
124      * @throws IOException error when writing object.
125      */

126     private void writeObject(java.io.ObjectOutputStream JavaDoc out)
127     throws IOException JavaDoc {
128         logger.log(Level.FINE, "");
129         HandleDelegate JavaDoc hdld;
130         try {
131             hdld = Utility.getHandleDelegate();
132         } catch (NamingException JavaDoc e) {
133             throw new IOException JavaDoc("Cannot get HandleDelegate");
134         }
135         hdld.writeEJBHome(getEJBHome(), out);
136     }
137
138     /**
139      * Specific implementation of deserialization.
140      * Must call HandleDelegate.readEJBObject, as specified in 19.5.5.1 of spec EJB 2.1
141      * @param in The input Stream from where is read the object.
142      * @throws IOException error when reading object.
143      * @throws ClassNotFoundException -
144      */

145     private void readObject(java.io.ObjectInputStream JavaDoc in)
146     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
147         logger.log(Level.FINE, "");
148         HandleDelegate JavaDoc hdld;
149         try {
150             hdld = Utility.getHandleDelegate();
151         } catch (NamingException JavaDoc e) {
152             throw new IOException JavaDoc("Cannot get HandleDelegate");
153         }
154         try {
155             ejbHome = hdld.readEJBHome(in);
156         } catch (ClassNotFoundException JavaDoc e) {
157             logger.log(Level.SEVERE, "Cant read EJBHome:" + e);
158             throw e;
159         } catch (IOException JavaDoc e) {
160             logger.log(Level.SEVERE, "Cant read EJBHome:" + e);
161             throw e;
162         }
163     }
164
165 }
166
167
Popular Tags