1 22 package org.jboss.resource.binding.remote; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.ObjectInputStream ; 26 import java.rmi.server.UID ; 27 import java.util.Hashtable ; 28 29 import javax.naming.BinaryRefAddr ; 30 import javax.naming.Context ; 31 import javax.naming.Name ; 32 import javax.naming.Reference ; 33 import javax.naming.StringRefAddr ; 34 import javax.naming.spi.ObjectFactory ; 35 36 import org.jboss.util.naming.NonSerializableFactory; 37 38 44 public class RemoteConnectionFactoryHelper implements ObjectFactory 45 { 46 47 public static final UID vmID = new UID (); 48 49 public Object getObjectInstance(final Object obj, final Name name, final Context ctx, final Hashtable env) throws Exception 50 { 51 52 Object instance = null; 53 54 if (obj instanceof Reference ) 55 { 56 Reference ref = (Reference ) obj; 57 BinaryRefAddr localID = (BinaryRefAddr ) ref.get("VMID"); 59 byte[] idBytes = (byte[]) localID.getContent(); 60 ByteArrayInputStream bais = new ByteArrayInputStream (idBytes); 61 ObjectInputStream ois = new ObjectInputStream (bais); 62 UID id = (UID ) ois.readObject(); 63 64 if( id.equals(vmID) == true ) 65 { 66 StringRefAddr jndiAddr = (StringRefAddr ) ref.get("JndiName"); 68 String jndiName = (String ) jndiAddr.getContent(); 69 instance = NonSerializableFactory.lookup(jndiName); 70 } 71 else 72 { 73 BinaryRefAddr proxyAddr = (BinaryRefAddr ) ref.get("ProxyData"); 75 byte[] proxyBytes = (byte[]) proxyAddr.getContent(); 76 ByteArrayInputStream bais2 = new ByteArrayInputStream (proxyBytes); 77 ObjectInputStream ois2 = new ObjectInputStream (bais2); 78 instance = ois2.readObject(); 79 } 80 } 81 return instance; 82 83 } 84 } 85 | Popular Tags |