/* 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.huihoo.jfox.mx;

import java.util.Properties;

import org.huihoo.jfox.util.InitialContextHelper;
import org.huihoo.jfox.system.State;
import org.jfox.jdbc.datasource.PoolDataSource;

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

public class PoolDataSourceMX implements ServiceMX{
  private PoolDataSource pds = null;

  private String dbDriver; // database driver class name.
  private String dbURL; // database url
  private String user; // database user
  private String password; //database password
  private String dsName = null;
  private int initNum = 2;
  private int maxRest = 10;

  public void mx_start() {
    try {
      pds = new PoolDataSource(dbDriver,dbURL,user,password);
      pds.setInitNum(initNum);
      pds.setMaxRest(maxRest);
      pds.init();
      InitialContextHelper.getInitialConext().bind("datasource/" + dsName, pds);
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }

  public void mx_stop() {
    try {
      InitialContextHelper.getInitialConext().unbind("datasource/" + dsName);
      pds.destroy();
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }

  public String getMxDescription() {
    return null;
  }

  public Properties getOperationDescriptions() {
    return null;
  }

  public Object getSource() {
    return pds;
  }

  public String mx_getDbDriver() {
    return dbDriver;
  }

  public void mx_setDbDriver(String dbDriver) {
    this.dbDriver = dbDriver;
  }

  public String mx_getDbUrl() {
    return dbURL;
  }

  public void mx_setDbUrl(String dbURL) {
    this.dbURL = dbURL;
  }

  public void mx_setDsName(String dsName) {
    this.dsName = dsName;
  }

  public String mx_getDsName() {
    return dsName;
  }

  public String mx_getUser() {
    return user;
  }

  public void mx_setUser(String user) {
    this.user = user;
  }

  public String mx_getPassword() {
    return password;
  }

  public void mx_setPassword(String password) {
    this.password = password;
  }

  public int mx_getMaxRest() {
    return maxRest;
  }

  public int mx_getInitNum(){
    return initNum;
  }

  public void mx_setInitNum(int initNum) {
    this.initNum = initNum;
  }

  public void mx_setMaxRest(int maxRest) {
    this.maxRest = maxRest;
  }

  public State mx_getStat() {
    return pds.getState();
  }

  public static void main(String[] args) {

  }

}