class RequestDispatcher {

    public void dispatch(GenericContainerRequest request, GenericContainerResponse response) {
        ApplicationContext context = ApplicationContext.getCurrent();
        String requestPath = getRequestPathWithoutMatrixParameters(context);
        List<String> parameterValues = context.getParameterValues();

        ObjectFactory<ResourceDescriptor> resourceFactory = getRootResource(parameterValues, requestPath);
        if (resourceFactory == null) {
            LOG.debug("Root resource not found for {}", requestPath);
            response.setResponse(Response.status(NOT_FOUND)
                                         .entity(String.format("There is no any resources matched to request path %s", requestPath))
                                         .type(TEXT_PLAIN)
                                         .build());
            return;
        }

        // Take the tail of the request path, the tail will be requested path
        // for lower resources, e. g. ResourceClass -> Sub-resource method/locator
        String newRequestPath = getPathTail(parameterValues);
        context.addMatchedURI(requestPath.substring(0, requestPath.lastIndexOf(newRequestPath)));
        context.setParameterNames(resourceFactory.getObjectModel().getUriPattern().getParameterNames());

        Object resource = resourceFactory.getInstance(context);
        dispatch(request, response, context, resourceFactory.getObjectModel(), resource, newRequestPath);
    }

    public  RequestDispatcher(ResourceBinder resourceBinder);

}