package org.huihoo.jfox.mx;

import java.util.Properties;

import org.jfox.jetty.IntegrateJetty;
import org.huihoo.jfox.system.State;

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

public class IntegrateJettyMX implements ServiceMX {

  private IntegrateJetty jetty = null;
  private String jettyHome = "../";
  private String jettyConfig = jettyHome + "conf/jetty.xml";

  public void mx_setJettyHome(String home) {
    jettyHome = home;
  }

  public String mx_getJettyHome() {
    return System.getProperty("jetty.home");
  }

  public void mx_setJettyConfig(String conf){
    jettyConfig = conf;
  }

  public String mx_getJettyConfig(){
    return jettyConfig;
  }

  public void mx_start() {
    try {
      jetty = new IntegrateJetty();
      jetty.setJettyHome(jettyHome);
      jetty.setConfig(jettyConfig);
      jetty.init();
      jetty.start();
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

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

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

  public Properties getOperationDescriptions() {
    return null;
  }

  public Object getSource() {
    return this;
  }

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

  public static void main(String[] args) {

  }}