/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.jfox.jdbc.datasource;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class DataSourceObjectFactory implements ObjectFactory {

    /**
   * Method that inherited from ObjectFactory.
   * @param obj
   * @param name
   * @param nameCtx
   * @param environment
   * @return
   * @throws Exception
   */
  public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
    Object result = null;
    Reference ref = (Reference) obj;
    if (ref.getClassName().equals(PoolDataSource.class.getName())) {
      String _dbDriver = (String) ref.get("dbDriver").getContent();
      String _dbURL = (String) ref.get("dbURL").getContent();
      String _user = (String) ref.get("user").getContent();
      String _password = (String) ref.get("password").getContent();
      PoolDataSource pds = new PoolDataSource(_dbDriver, _dbURL, _user, _password);
      pds.init();
      result = pds;
    }
    return result;
  }
  
  public static void main(String[] args) {

  }
}