// Path: commons/src/main/java/org/nesty/commons/constant/http/RequestMethod.java
// public enum RequestMethod {
//     GET, POST, PUT, DELETE, UNKOWN
// }
// 
// Path: core/src/main/java/org/nesty/core/server/rest/controller/URLController.java
// public class URLController extends Hitcounter {
// 
//     // target class
//     private ControllerClassDescriptor provider;
//     // target method
//     private ControllerMethodDescriptor procedure;
//     // internal controller sign. only for root-path
//     private boolean internal = false;
// 
//     private URLController() {
// 
//     }
// 
//     public static URLController fromProvider(String URI, Class<?> providerClass, Method procedure) {
//         URLController handler = new URLController();
//         handler.provider = new ControllerClassDescriptor(providerClass);
//         handler.procedure = new ControllerMethodDescriptor(URI, handler.provider, procedure);
//         return handler;
//     }
// 
//     public URLController internal() {
//         this.internal = true;
//         return this;
//     }
// 
//     public boolean isInternal() {
//         return this.internal;
//     }
// 
//     public HttpResult call(HttpContext context) {
//         /**
//          * make new controller class instance with every http request. because
//          * of we desire every request may has own context variables and status.
//          *
//          * TODO : This newInstance() need a empty param default constructor.
//          *
//          */
// 
//         try {
//             Object result = procedure.invoke(context);
//             if (result != null && !result.getClass().isPrimitive())
//                 return new HttpResult(ResultCode.SUCCESS, result);
//             else
//                 return new HttpResult(ResultCode.RESPONSE_NOT_VALID);
//         } catch (ControllerParamsNotMatchException e) {
//             return new HttpResult(ResultCode.PARAMS_NOT_MATCHED);
//         } catch (ControllerParamsParsedException e) {
//             return new HttpResult(ResultCode.PARAMS_CONVERT_ERROR);
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("provider=%s, procedure=%s", provider.getClazz().getCanonicalName(), procedure.getMethod().getName());
//     }
// }


import org.nesty.commons.constant.http.RequestMethod;
import org.nesty.core.server.rest.controller.URLController;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
package org.nesty.core.server.rest;



/**
 * Routeable Controller mapping
 *
 * Author : Michael
 * Date : March 07, 2016
 */
public class ControllerRouter {

    /**
     * first index layer. indexd by HttpMethod and URL terms length
     *
     * our max supportted URL terms is 512
     */
    private final URLMapper[][] mapper = new URLMapper[RequestMethod.UNKOWN.ordinal()][512];

    /**
     * get specified resource's controller or null if it don't exist
     *
     * @param resource url anaylzed resource
     * @return controller instance or null if it don't exist
     */
// Path: commons/src/main/java/org/nesty/commons/constant/http/RequestMethod.java
// public enum RequestMethod {
//     GET, POST, PUT, DELETE, UNKOWN
// }
// 
// Path: core/src/main/java/org/nesty/core/server/rest/controller/URLController.java
// public class URLController extends Hitcounter {
// 
//     // target class
//     private ControllerClassDescriptor provider;
//     // target method
//     private ControllerMethodDescriptor procedure;
//     // internal controller sign. only for root-path
//     private boolean internal = false;
// 
//     private URLController() {
// 
//     }
// 
//     public static URLController fromProvider(String URI, Class<?> providerClass, Method procedure) {
//         URLController handler = new URLController();
//         handler.provider = new ControllerClassDescriptor(providerClass);
//         handler.procedure = new ControllerMethodDescriptor(URI, handler.provider, procedure);
//         return handler;
//     }
// 
//     public URLController internal() {
//         this.internal = true;
//         return this;
//     }
// 
//     public boolean isInternal() {
//         return this.internal;
//     }
// 
//     public HttpResult call(HttpContext context) {
//         /**
//          * make new controller class instance with every http request. because
//          * of we desire every request may has own context variables and status.
//          *
//          * TODO : This newInstance() need a empty param default constructor.
//          *
//          */
// 
//         try {
//             Object result = procedure.invoke(context);
//             if (result != null && !result.getClass().isPrimitive())
//                 return new HttpResult(ResultCode.SUCCESS, result);
//             else
//                 return new HttpResult(ResultCode.RESPONSE_NOT_VALID);
//         } catch (ControllerParamsNotMatchException e) {
//             return new HttpResult(ResultCode.PARAMS_NOT_MATCHED);
//         } catch (ControllerParamsParsedException e) {
//             return new HttpResult(ResultCode.PARAMS_CONVERT_ERROR);
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("provider=%s, procedure=%s", provider.getClazz().getCanonicalName(), procedure.getMethod().getName());
//     }
// }


// Path: core/src/main/java/org/nesty/core/server/rest/ControllerRouter.java
import org.nesty.commons.constant.http.RequestMethod;
import org.nesty.core.server.rest.controller.URLController;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

package org.nesty.core.server.rest;



/**
 * Routeable Controller mapping
 *
 * Author : Michael
 * Date : March 07, 2016
 */
public class ControllerRouter {

    /**
     * first index layer. indexd by HttpMethod and URL terms length
     *
     * our max supportted URL terms is 512
     */
    private final URLMapper[][] mapper = new URLMapper[RequestMethod.UNKOWN.ordinal()][512];

    /**
     * get specified resource's controller or null if it don't exist
     *
     * @param resource url anaylzed resource
     * @return controller instance or null if it don't exist
     */
    public URLController findURLController(URLResource resource) {