/* 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.jfox.tomcat.IntegrateTomcat3;
import org.huihoo.jfox.system.State;

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

public class IntegrateTomcatMX implements ServiceMX {
  private IntegrateTomcat3 tomcat3 = null;

  public void mx_setTomcatHome(String tomcatHome) {
    System.setProperty("tomcat.home", tomcatHome);
  }

  public String mx_getTomcatHome() {
    return System.getProperty("tomcat.home");
  }

  public void mx_start() {
    try {
      tomcat3 = new IntegrateTomcat3();
      tomcat3.init();
      tomcat3.start();
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public void mx_stop() {
    try {
      tomcat3.stop();
      tomcat3.destroy();
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
//    tomcat3 = null;
  }

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

  public Properties getOperationDescriptions() {
    return null;
  }

  public Object getSource() {
    return this;
  }

  public String getMxDescription() {
    return "Integrate Tomcat3 Web Server";
  }

  public static void main(String[] args) {

  }
}