Package dovetaildb

Source Code of dovetaildb.Main

package dovetaildb;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import com.sun.grizzly.comet.CometAsyncFilter;
import com.sun.grizzly.cometd.standalone.CometdAdapter;
import com.sun.grizzly.http.embed.GrizzlyWebServer;
import com.sun.grizzly.http.servlet.ServletAdapter;

import dovetaildb.scriptbridge.RhinoScriptBridge;
import dovetaildb.scriptbridge.ScriptEnv;
import dovetaildb.servlet.DovetaildbServlet;
import dovetaildb.util.Pair;
import dovetaildb.util.Util;

public class Main {

  private static void error(String s) {
    System.err.println(s);
    System.exit(1);
  }
 
  public static void main(String[] argv) throws Exception {
   
    RhinoScriptBridge rhino = new RhinoScriptBridge();
    if (argv.length < 2) error("Specify a configuration file as the first argument");
    String configFilename = argv[1];
    String configContent = Util.readFully(new File(configFilename));
    Collection<Pair<String,String>> codeFiles = Util.literalList().a(
        new Pair<String,String>(configFilename, configContent)
    );

    //GrizzlyWebServer ws = new GrizzlyWebServer("/var/www");
    GrizzlyWebServer ws = new GrizzlyWebServer();
    DovetaildbServlet ddbServlet = new DovetaildbServlet();

    ServletAdapter sa = new ServletAdapter();
    sa.setServletInstance(ddbServlet);
    ws.addGrizzlyAdapter(sa, new String[]{"/"});

    Map<String,Object> env = Util.literalMap()
      .p("server", ws)
      .p("servlet", ddbServlet);
    rhino.makeEnvFromCodeExecution(codeFiles, env);

    /*
    // Add Comet Support
    ws.addAsyncFilter(new CometAsyncFilter());

    //Add Bayeux support
    CometdAdapter cometdAdapter = new CometdAdapter();
    ws.addGrizzlyAdapter(cometdAdapter, new String[]{"/foobar"});

    */

    ws.start();
  }
}
 
TOP

Related Classes of dovetaildb.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.