1 22 package org.jboss.proxy.ejb.handle; 23 24 import javax.ejb.HomeHandle ; 25 import javax.ejb.EJBHome ; 26 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import java.rmi.ServerException ; 30 import java.rmi.RemoteException ; 31 import java.io.ObjectStreamField ; 32 import java.io.ObjectInputStream ; 33 import java.io.IOException ; 34 import java.io.ObjectOutputStream ; 35 import java.util.Hashtable ; 36 import org.jboss.naming.NamingContextFactory; 37 38 39 46 public class HomeHandleImpl 47 implements HomeHandle 48 { 49 51 52 static final long serialVersionUID = 208629381571948124L; 53 54 private static final ObjectStreamField [] serialPersistentFields = 55 new ObjectStreamField [] 56 { 57 new ObjectStreamField ("jndiName", String .class), 58 new ObjectStreamField ("jndiEnv", Hashtable .class) 59 }; 60 61 62 private String jndiName; 63 64 private Hashtable jndiEnv; 65 66 68 70 78 public HomeHandleImpl(String jndiName) 79 { 80 this.jndiName = jndiName; 81 this.jndiEnv = (Hashtable ) NamingContextFactory.lastInitialContextEnv.get(); 82 } 83 84 86 88 96 public EJBHome getEJBHome() throws RemoteException 97 { 98 try 99 { 100 InitialContext ic = null; 101 if( jndiEnv != null ) 102 ic = new InitialContext (jndiEnv); 103 else 104 ic = new InitialContext (); 105 EJBHome home = (EJBHome ) ic.lookup(jndiName); 106 return home; 107 } 108 catch (NamingException e) 109 { 110 throw new ServerException ("Could not get EJBHome", e); 111 } 112 } 113 114 117 public String getJNDIName() 118 { 119 return jndiName; 120 } 121 122 private void readObject(ObjectInputStream ois) 123 throws IOException , ClassNotFoundException 124 { 125 ObjectInputStream.GetField getField = ois.readFields(); 126 jndiName = (String ) getField.get("jndiName", null); 127 jndiEnv = (Hashtable ) getField.get("jndiEnv", null); 128 } 129 130 private void writeObject(ObjectOutputStream oos) 131 throws IOException 132 { 133 ObjectOutputStream.PutField putField = oos.putFields(); 134 putField.put("jndiName", jndiName); 135 putField.put("jndiEnv", jndiEnv); 136 oos.writeFields(); 137 } 138 } 139 140 | Popular Tags |