FileDocCategorySizeDatePackage
DataSourceFactory.javaAPI DocJBoss 4.2.13076Fri Jul 13 21:01:14 BST 2007org.jboss.resource.adapter.jdbc.remote

DataSourceFactory

public class DataSourceFactory extends Object implements ObjectFactory
A JNDI ObjectFactory for handling either the local or remote access to a JCA javax.sql.DataSource binding.
author
Scott.Stark@jboss.org
version
$Revision: 57189 $

Fields Summary
public static final UID
vmID
The class VM ID
Constructors Summary
Methods Summary
public java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context ctx, java.util.Hashtable env)


          
         
   
      Object instance = null;
      if (obj instanceof Reference)
      {
         Reference ref = (Reference) obj;
         // Check the local id
         BinaryRefAddr localID = (BinaryRefAddr) ref.get("VMID");
         byte[] idBytes = (byte[]) localID.getContent();
         ByteArrayInputStream bais = new ByteArrayInputStream(idBytes);
         ObjectInputStream ois = new ObjectInputStream(bais);
         UID id = (UID) ois.readObject();
         if( id.equals(vmID) == true )
         {
            // Use the local datasource
            StringRefAddr jndiAddr = (StringRefAddr) ref.get("JndiName");
            String jndiName = (String) jndiAddr.getContent();
            instance = NonSerializableFactory.lookup(jndiName);
         }
         else
         {
            // Use the embedded proxy
            BinaryRefAddr proxyAddr = (BinaryRefAddr) ref.get("ProxyData");
            byte[] proxyBytes = (byte[]) proxyAddr.getContent();
            ByteArrayInputStream bais2 = new ByteArrayInputStream(proxyBytes);
            ObjectInputStream ois2 = new ObjectInputStream(bais2);
            instance = ois2.readObject();
         }
      }
      return instance;