// Path: jflask/src/main/java/net/jflask/util/Log.java
// public class Log {
// 
//   public static final boolean DEBUG = Boolean.getBoolean("debug");
// 
//   public static void warn(Object msg) {
//     System.err.println("WARN: " + msg);
//   }
// 
//   public static void error(Object msg) {
//     System.err.println("ERROR: " + msg);
//   }
// 
//   public static void error(Object msg, Throwable t) {
//     System.err.println("ERROR: " + msg);
//     t.printStackTrace();
//   }
// 
//   public static void info(Object msg) {
//     System.err.println("INFO: " + msg);
//   }
// 
//   public static void debug(Object msg) {
//     if (DEBUG)
//       System.err.println("DEBUG: " + msg);
//   }
// 
// }


import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import net.jflask.util.Log;
package net.jflask;



/**
 * A HTTP handler that receives all requests on a given rootURI and dispatches
 * them to configured route handlers.
 *
 * @author pcdv
 */
public class Context implements HttpHandler, RequestHandler {

  private static final String[] EMPTY = {};

  private final String rootURI;

  private final List<MethodHandler> handlers = new ArrayList<>();

  final App app;

  public Context(App app, String rootURI) {
    this.app = app;
    this.rootURI = rootURI;
  }

  /**
   * Registers a java method that must be called to process requests matching
   * specified URI (relative to rootURI).
   *
   * @param uri URI schema relative to rootURI (eg. "/:name")
   * @param m a java method
   * @param obj the object on which the method must be invoked
   */
  public MethodHandler addHandler(String uri,
                                  Route route,
                                  Method m,
                                  Object obj) {
// Path: jflask/src/main/java/net/jflask/util/Log.java
// public class Log {
// 
//   public static final boolean DEBUG = Boolean.getBoolean("debug");
// 
//   public static void warn(Object msg) {
//     System.err.println("WARN: " + msg);
//   }
// 
//   public static void error(Object msg) {
//     System.err.println("ERROR: " + msg);
//   }
// 
//   public static void error(Object msg, Throwable t) {
//     System.err.println("ERROR: " + msg);
//     t.printStackTrace();
//   }
// 
//   public static void info(Object msg) {
//     System.err.println("INFO: " + msg);
//   }
// 
//   public static void debug(Object msg) {
//     if (DEBUG)
//       System.err.println("DEBUG: " + msg);
//   }
// 
// }


// Path: jflask/src/main/java/net/jflask/Context.java
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import net.jflask.util.Log;

package net.jflask;



/**
 * A HTTP handler that receives all requests on a given rootURI and dispatches
 * them to configured route handlers.
 *
 * @author pcdv
 */
public class Context implements HttpHandler, RequestHandler {

  private static final String[] EMPTY = {};

  private final String rootURI;

  private final List<MethodHandler> handlers = new ArrayList<>();

  final App app;

  public Context(App app, String rootURI) {
    this.app = app;
    this.rootURI = rootURI;
  }

  /**
   * Registers a java method that must be called to process requests matching
   * specified URI (relative to rootURI).
   *
   * @param uri URI schema relative to rootURI (eg. "/:name")
   * @param m a java method
   * @param obj the object on which the method must be invoked
   */
  public MethodHandler addHandler(String uri,
                                  Route route,
                                  Method m,
                                  Object obj) {
    Log.debug("Add handler for " + route.method() + " on " + rootURI + uri);