1 22 package org.jboss.ejb3.stateless; 23 24 import java.rmi.RemoteException ; 25 import java.rmi.ServerException ; 26 import java.lang.reflect.Method ; 27 import java.lang.reflect.Proxy ; 28 import java.io.ObjectStreamField ; 29 import java.io.ObjectInputStream ; 30 import java.io.IOException ; 31 import java.io.ObjectOutputStream ; 32 import java.util.Hashtable ; 33 34 import javax.naming.InitialContext ; 35 import javax.ejb.Handle ; 36 import javax.ejb.EJBObject ; 37 import javax.ejb.EJBHome ; 38 39 import org.jboss.naming.NamingContextFactory; 40 41 48 public class StatelessHandleImpl 49 implements Handle 50 { 51 52 static final long serialVersionUID = 3811452873535097661L; 53 private static final ObjectStreamField [] serialPersistentFields = 54 new ObjectStreamField [] 55 { 56 new ObjectStreamField ("jndiName", String .class), 57 new ObjectStreamField ("jndiEnv", Hashtable .class) 58 }; 59 60 61 public String jndiName; 62 63 private Hashtable jndiEnv; 64 65 67 public StatelessHandleImpl() 68 { 69 70 } 71 72 80 public StatelessHandleImpl(String jndiName) 81 { 82 this.jndiName = jndiName; 83 this.jndiEnv = (Hashtable ) NamingContextFactory.lastInitialContextEnv.get(); 84 } 85 86 88 public EJBObject getEJBObject() throws RemoteException 89 { 90 try 91 { 92 InitialContext ic = null; 93 if( jndiEnv != null ) 94 ic = new InitialContext (jndiEnv); 95 else 96 ic = new InitialContext (); 97 98 Proxy proxy = (Proxy ) ic.lookup(jndiName); 99 100 return (EJBObject ) proxy; 101 } 102 catch (Throwable t) 103 { 104 t.printStackTrace(); 105 throw new RemoteException ("Error during getEJBObject", t); 106 } 107 } 108 109 112 public String getJNDIName() 113 { 114 return jndiName; 115 } 116 117 private void readObject(ObjectInputStream ois) 118 throws IOException , ClassNotFoundException 119 { 120 ObjectInputStream.GetField getField = ois.readFields(); 121 jndiName = (String ) getField.get("jndiName", null); 122 jndiEnv = (Hashtable ) getField.get("jndiEnv", null); 123 } 124 125 private void writeObject(ObjectOutputStream oos) 126 throws IOException 127 { 128 ObjectOutputStream.PutField putField = oos.putFields(); 129 putField.put("jndiName", jndiName); 130 putField.put("jndiEnv", jndiEnv); 131 oos.writeFields(); 132 } 133 } 134 | Popular Tags |