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