1 25 26 package org.objectweb.jonas_ejb.svc; 27 28 import java.io.IOException ; 29 import java.io.Serializable ; 30 import java.rmi.RemoteException ; 31 32 import javax.ejb.EJBHome ; 33 import javax.ejb.HomeHandle ; 34 import javax.ejb.spi.HandleDelegate ; 35 import java.util.logging.Level ; 36 import java.util.logging.Logger ; 37 38 import javax.naming.NamingException ; 39 import javax.rmi.PortableRemoteObject ; 40 import javax.rmi.CORBA.Util ; 41 42 import org.omg.PortableServer.Servant ; 43 44 45 51 public class JHomeHandleIIOP implements HomeHandle , Serializable { 52 53 56 private static Logger logger = Logger.getLogger("org.objectweb.jonas_ejb.svc"); 57 58 62 private String ior = null; 63 64 67 private ClassLoader cl = null; 68 69 72 private EJBHome ejbHome = null; 73 74 79 public JHomeHandleIIOP(EJBHome h, ClassLoader cl) { 80 logger.log(Level.FINE, "h=" + h); 81 try { 82 Servant servant = (Servant ) Util.getTie(h); 83 org.omg.CORBA.Object 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 e) { 88 logger.log(Level.SEVERE, "cannot get Handle: ", e); 89 } 90 } 91 92 96 102 public EJBHome getEJBHome() throws RemoteException { 103 logger.log(Level.FINE, ""); 104 ClassLoader old = Thread.currentThread().getContextClassLoader(); 105 logger.log(Level.FINE, ""); 106 if (ejbHome == null) { 107 try { 108 Thread.currentThread().setContextClassLoader(cl); 109 ejbHome = (EJBHome ) PortableRemoteObject.narrow(Utility.getORB().string_to_object(ior), EJBHome .class); 110 } catch (NamingException e) { 111 throw new RemoteException ("getEJBHome:" + e); 112 } finally { 113 Thread.currentThread().setContextClassLoader(old); 115 } 116 } 117 return ejbHome; 118 } 119 120 126 private void writeObject(java.io.ObjectOutputStream out) 127 throws IOException { 128 logger.log(Level.FINE, ""); 129 HandleDelegate hdld; 130 try { 131 hdld = Utility.getHandleDelegate(); 132 } catch (NamingException e) { 133 throw new IOException ("Cannot get HandleDelegate"); 134 } 135 hdld.writeEJBHome(getEJBHome(), out); 136 } 137 138 145 private void readObject(java.io.ObjectInputStream in) 146 throws IOException , ClassNotFoundException { 147 logger.log(Level.FINE, ""); 148 HandleDelegate hdld; 149 try { 150 hdld = Utility.getHandleDelegate(); 151 } catch (NamingException e) { 152 throw new IOException ("Cannot get HandleDelegate"); 153 } 154 try { 155 ejbHome = hdld.readEJBHome(in); 156 } catch (ClassNotFoundException e) { 157 logger.log(Level.SEVERE, "Cant read EJBHome:" + e); 158 throw e; 159 } catch (IOException e) { 160 logger.log(Level.SEVERE, "Cant read EJBHome:" + e); 161 throw e; 162 } 163 } 164 165 } 166 167 | Popular Tags |