KickJava   Java API By Example, From Geeks To Geeks.

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


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: JHandleIIOP.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.Remote JavaDoc;
31 import java.rmi.RemoteException JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 import java.util.logging.Logger JavaDoc;
34
35 import javax.ejb.EJBObject JavaDoc;
36 import javax.ejb.Handle JavaDoc;
37 import javax.ejb.spi.HandleDelegate JavaDoc;
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  * This class implements javax.ejb.Handle interface.
45  * @author Philippe Coq
46  */

47 public class JHandleIIOP implements Handle JavaDoc, Serializable JavaDoc {
48
49     /**
50      * JDK logger to be portable
51      */

52     private static Logger JavaDoc logger = Logger.getLogger("org.objectweb.jonas_ejb.svc");
53
54     /**
55      * CORBA ref
56      * @serial
57      */

58     private String JavaDoc ior = null;
59
60    /**
61      * constructor
62      * @param r remote ref
63      */

64     public JHandleIIOP(Remote JavaDoc r) {
65         try {
66             logger.log(Level.FINE, "r=" + r);
67             Servant JavaDoc servant = (Servant JavaDoc) Util.getTie(r);
68             org.omg.CORBA.Object JavaDoc o = servant._this_object();
69             this.ior = Utility.getORB().object_to_string(o);
70             logger.log(Level.FINE, "ior=" + ior);
71         } catch (Exception JavaDoc e) {
72             logger.log(Level.SEVERE, "cannot get Handle: ", e);
73         }
74     }
75
76     /**
77      * Obtains the EJB object represented by this handle.
78      * @return The EJB object
79      * @throws RemoteException The EJB object could not be obtained because of a
80      * system-level failure.
81      */

82     public EJBObject JavaDoc getEJBObject() throws RemoteException JavaDoc {
83         logger.log(Level.FINE, "");
84         try {
85             return (EJBObject JavaDoc) PortableRemoteObject.narrow(Utility.getORB().string_to_object(ior), EJBObject JavaDoc.class);
86         } catch (Exception JavaDoc e) {
87             throw new RemoteException JavaDoc("JHandle.getEJBObject(): " + e, e);
88         }
89     }
90
91     /**
92      * Specific implementation of serialization.
93      * Must call HandleDelegate.writeEJBObject, as specified in 19.5.5.1 of spec EJB 2.1
94      * @param out The output stream used to write object
95      * @throws IOException error when writing object.
96      */

97     private void writeObject(java.io.ObjectOutputStream JavaDoc out)
98     throws IOException JavaDoc {
99         HandleDelegate JavaDoc hdld;
100         logger.log(Level.FINE, "");
101         try {
102             hdld = Utility.getHandleDelegate();
103         } catch (NamingException JavaDoc e) {
104             throw new IOException JavaDoc("Cannot get HandleDelegate");
105         }
106         hdld.writeEJBObject(getEJBObject(), out);
107     }
108
109     /**
110      * Specific implementation of deserialization.
111      * Must call HandleDelegate.readEJBObject, as specified in 19.5.5.1 of spec EJB 2.1
112      * @param in The input Stream from where is read the object.
113      * @throws IOException error when reading object.
114      * @throws ClassNotFoundException -
115      */

116     private void readObject(java.io.ObjectInputStream JavaDoc in)
117     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
118         HandleDelegate JavaDoc hdld;
119         logger.log(Level.FINE, "");
120         try {
121             hdld = Utility.getHandleDelegate();
122         } catch (NamingException JavaDoc e) {
123             throw new IOException JavaDoc("Cannot get HandleDelegate");
124         }
125         EJBObject JavaDoc obj = hdld.readEJBObject(in);
126         try {
127             this.ior = Utility.getORB().object_to_string((org.omg.CORBA.Object JavaDoc) obj);
128
129         } catch (Exception JavaDoc e) {
130             throw new RemoteException JavaDoc("JHandle.readObject(): " + e, e);
131         }
132     }
133
134 }
135
136
Popular Tags