1 22 package org.jboss.proxy.ejb.handle; 23 24 import java.rmi.ServerException ; 25 import java.lang.reflect.Method ; 26 import java.io.ObjectStreamField ; 27 import java.io.ObjectInputStream ; 28 import java.io.IOException ; 29 import java.io.ObjectOutputStream ; 30 import java.util.Hashtable ; 31 32 import javax.naming.InitialContext ; 33 import javax.ejb.Handle ; 34 import javax.ejb.EJBObject ; 35 import javax.ejb.EJBHome ; 36 37 import org.jboss.naming.NamingContextFactory; 38 39 46 public class StatelessHandleImpl 47 implements Handle 48 { 49 50 static final long serialVersionUID = 3811452873535097661L; 51 private static final ObjectStreamField [] serialPersistentFields = 52 new ObjectStreamField [] 53 { 54 new ObjectStreamField ("jndiName", String .class), 55 new ObjectStreamField ("jndiEnv", Hashtable .class) 56 }; 57 58 59 private String jndiName; 60 61 private Hashtable jndiEnv; 62 63 65 73 public StatelessHandleImpl(String jndiName) 74 { 75 this.jndiName = jndiName; 76 this.jndiEnv = (Hashtable ) NamingContextFactory.lastInitialContextEnv.get(); 77 } 78 79 81 public EJBObject getEJBObject() 82 throws ServerException 83 { 84 try 85 { 86 InitialContext ic = null; 87 if( jndiEnv != null ) 88 ic = new InitialContext (jndiEnv); 89 else 90 ic = new InitialContext (); 91 EJBHome home = (EJBHome ) ic.lookup(jndiName); 92 Class type = home.getClass(); 93 Method method = type.getMethod("create", new Class [0]); 94 return (EJBObject ) method.invoke(home, new Object [0]); 95 } 96 catch (Exception e) 97 { 98 throw new ServerException ("Could not get EJBObject", e); 99 } 100 } 101 102 105 public String getJNDIName() 106 { 107 return jndiName; 108 } 109 110 private void readObject(ObjectInputStream ois) 111 throws IOException , ClassNotFoundException 112 { 113 ObjectInputStream.GetField getField = ois.readFields(); 114 jndiName = (String ) getField.get("jndiName", null); 115 jndiEnv = (Hashtable ) getField.get("jndiEnv", null); 116 } 117 118 private void writeObject(ObjectOutputStream oos) 119 throws IOException 120 { 121 ObjectOutputStream.PutField putField = oos.putFields(); 122 putField.put("jndiName", jndiName); 123 putField.put("jndiEnv", jndiEnv); 124 oos.writeFields(); 125 } 126 } 127 | Popular Tags |