JHomeHandleIIOP.java

00001 
00026 package org.objectweb.jonas_ejb.svc;
00027 
00028 import java.io.IOException;
00029 import java.io.Serializable;
00030 import java.rmi.RemoteException;
00031 
00032 import javax.ejb.EJBHome;
00033 import javax.ejb.HomeHandle;
00034 import javax.ejb.spi.HandleDelegate;
00035 import java.util.logging.Level;
00036 import java.util.logging.Logger;
00037 
00038 import javax.naming.NamingException;
00039 import javax.rmi.PortableRemoteObject;
00040 import javax.rmi.CORBA.Util;
00041 
00042 import org.omg.PortableServer.Servant;
00043 
00044 
00051 public class JHomeHandleIIOP implements HomeHandle, Serializable {
00052 
00056     private static Logger logger = Logger.getLogger("org.objectweb.jonas_ejb.svc");
00057 
00062     private String ior = null;
00063 
00067     private ClassLoader cl = null;
00068 
00072     private EJBHome ejbHome = null;
00073 
00079     public JHomeHandleIIOP(EJBHome h, ClassLoader cl) {
00080         logger.log(Level.FINE, "h=" + h);
00081         try {
00082             Servant servant = (Servant) Util.getTie(h);
00083             org.omg.CORBA.Object o = servant._this_object();
00084             this.ior = Utility.getORB().object_to_string(o);
00085             this.cl = cl;
00086             logger.log(Level.FINE, "ior=" + ior);
00087         } catch (Exception e) {
00088             logger.log(Level.SEVERE, "cannot get Handle: ", e);
00089         }
00090     }
00091 
00092     // -----------------------------------------------------------------------
00093     // HomeHandle implementation
00094     // -----------------------------------------------------------------------
00095 
00102     public EJBHome getEJBHome() throws RemoteException {
00103         logger.log(Level.FINE, "");
00104         ClassLoader old = Thread.currentThread().getContextClassLoader();
00105         logger.log(Level.FINE, "");
00106         if (ejbHome == null) {
00107             try {
00108                 Thread.currentThread().setContextClassLoader(cl);
00109                 ejbHome = (EJBHome) PortableRemoteObject.narrow(Utility.getORB().string_to_object(ior), EJBHome.class);
00110             } catch (NamingException e) {
00111                 throw new RemoteException("getEJBHome:" + e);
00112             } finally {
00113                 // reset
00114                 Thread.currentThread().setContextClassLoader(old);
00115             }
00116         }
00117         return ejbHome;
00118     }
00119 
00126     private void writeObject(java.io.ObjectOutputStream out)
00127     throws IOException {
00128         logger.log(Level.FINE, "");
00129         HandleDelegate hdld;
00130         try {
00131             hdld = Utility.getHandleDelegate();
00132         } catch (NamingException e) {
00133             throw new IOException("Cannot get HandleDelegate");
00134         }
00135         hdld.writeEJBHome(getEJBHome(), out);
00136     }
00137 
00145     private void readObject(java.io.ObjectInputStream in)
00146     throws IOException, ClassNotFoundException {
00147         logger.log(Level.FINE, "");
00148         HandleDelegate hdld;
00149         try {
00150             hdld = Utility.getHandleDelegate();
00151         } catch (NamingException e) {
00152             throw new IOException("Cannot get HandleDelegate");
00153         }
00154         try {
00155             ejbHome = hdld.readEJBHome(in);
00156         } catch (ClassNotFoundException e) {
00157             logger.log(Level.SEVERE, "Cant read EJBHome:" + e);
00158             throw e;
00159         } catch (IOException e) {
00160             logger.log(Level.SEVERE, "Cant read EJBHome:" + e);
00161             throw e;
00162         }
00163     }
00164 
00165 }
00166 

Generated on Tue Feb 15 15:05:49 2005 for JOnAS by  doxygen 1.3.9.1