package javakurs.musterloesung.uebung07;

import java.io.IOException;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.webserver.WebServer;

/**
 * {@link XmlRpcFridgeServer} provides some of the {@link FridgeEx2} methods as
 * remote XML RPC access.
 *
 * @author Joerg Steffen, DFKI
 * @version $Id: XmlRpcFridgeServer.java,v 1.1 2010/12/13 13:15:55 steffen Exp $
 */
public final class XmlRpcFridgeServer {

  /**
   * This would create a new instance of {@link XmlRpcFridgeServer}. Not to be
   * used.
   */
  private XmlRpcFridgeServer() {

    // private constructor to enforce noninstantiability
  }


  /**
   * This is the main method. It requires no arguments.
   *
   * @param args
   *          the arguments; not used here
   */
  public static void main(String[] args) {

    try {
      // init web server
      WebServer webServer = new WebServer(16384);
      XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

      // init property handler and add our fridge
      PropertyHandlerMapping phm = new PropertyHandlerMapping();
      phm.addHandler("servedFridge", FridgeEx2.class);
      xmlRpcServer.setHandlerMapping(phm);

      webServer.start();
      System.out.println("server started");
    } catch (XmlRpcException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
