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

import java.io.IOException;
import java.util.Properties;

import org.jfox.mx.Mxable;
import org.jfox.mx.MxServer;
import org.jfox.mx.ObjectName;
import org.jfox.mx.MxRegistration;

/**
 *
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */
public class HttpAdaptorMX implements Mxable, MxRegistration {
  private WebServer ws = new WebServer();

  public int mx_getPort() {
    return ws.getPort();
  }

  public void mx_start() {
    try {
      ws.start();
    }
    catch(IOException e){
      e.printStackTrace();
    }
  }

  public void mx_stop() {
    ws.stop();
  }

  public void mx_restart() {
    try {
      ws.stop();
      ws.start();
    }
    catch(IOException e){
      e.printStackTrace();
    }
  }

  public Object getSource() {
    return ws;
  }

  public String getMxDescription() {
    return "MX http console";
  }

  public Properties getOperationDescriptions() {
    return new Properties();
  }

  public void preRegister(MxServer server, ObjectName name) throws Exception {
    ws.setMxServer(server);
  }

  public void postRegister(Boolean registrationDone) {

  }

  public void preDeregister() throws Exception {

  }

  public void postDeregister() {

  }

  public static void main(String[] args) throws Exception {
    MxServer mx = MxServer.getInstance();
    ObjectName on = new ObjectName(":Adaptor=Http");
    mx.createMX(HttpAdaptorMX.class.getName(),on);
    mx.invoke(on,"mx_start",null,null);
  }
}