Search in sources :

Example 1 with ViewControllerHandlerRegistry

use of cn.taketoday.web.registry.ViewControllerHandlerRegistry in project today-framework by TAKETODAY.

the class WebApplicationLoader method configureHandlerAdapter.

/**
 * Configure {@link HandlerAdapter}
 *
 * @param adapters {@link HandlerAdapter}s
 * @param mvcConfiguration {@link WebMvcConfiguration}
 */
protected void configureHandlerAdapter(List<HandlerAdapter> adapters, WebMvcConfiguration mvcConfiguration) {
    // 先看有的
    DispatcherHandler obtainDispatcher = obtainDispatcher();
    HandlerAdapter[] handlerAdapters = obtainDispatcher.getHandlerAdapters();
    if (handlerAdapters != null) {
        Collections.addAll(adapters, handlerAdapters);
    }
    // 添加默认的
    adapters.add(new RequestHandlerAdapter(Ordered.HIGHEST_PRECEDENCE));
    WebApplicationContext context = obtainApplicationContext();
    // ViewControllerHandlerRegistry must configured
    ViewControllerHandlerRegistry viewControllerRegistry = context.getBean(ViewControllerHandlerRegistry.class);
    if (viewControllerRegistry != null) {
        ViewControllerHandlerAdapter bean = context.getBean(ViewControllerHandlerAdapter.class);
        if (bean == null) {
            ViewControllerHandlerAdapter viewControllerHandlerAdapter = null;
            for (HandlerAdapter adapter : adapters) {
                if (adapter instanceof ViewControllerHandlerAdapter) {
                    viewControllerHandlerAdapter = (ViewControllerHandlerAdapter) adapter;
                    break;
                }
            }
            if (viewControllerHandlerAdapter == null) {
                adapters.add(new ViewControllerHandlerAdapter(Ordered.HIGHEST_PRECEDENCE));
            }
        }
    }
    // 排序
    sort(adapters);
    // apply request handler
    obtainDispatcher.setHandlerAdapters(adapters.toArray(new HandlerAdapter[adapters.size()]));
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler) ViewControllerHandlerAdapter(cn.taketoday.web.handler.ViewControllerHandlerAdapter) RequestHandlerAdapter(cn.taketoday.web.handler.RequestHandlerAdapter) HandlerAdapter(cn.taketoday.web.handler.HandlerAdapter) ViewControllerHandlerRegistry(cn.taketoday.web.registry.ViewControllerHandlerRegistry) RequestHandlerAdapter(cn.taketoday.web.handler.RequestHandlerAdapter) WebApplicationContext(cn.taketoday.web.WebApplicationContext) ViewControllerHandlerAdapter(cn.taketoday.web.handler.ViewControllerHandlerAdapter)

Example 2 with ViewControllerHandlerRegistry

use of cn.taketoday.web.registry.ViewControllerHandlerRegistry in project today-framework by TAKETODAY.

the class WebApplicationLoader method configViewControllerHandlerRegistry.

/**
 * Initialize framework.
 *
 * @throws Throwable if any Throwable occurred
 */
protected ViewControllerHandlerRegistry configViewControllerHandlerRegistry(@Nullable ViewControllerHandlerRegistry registry) throws Throwable {
    // find the configure file
    log.info("TODAY WEB Framework Is Looking For ViewController Configuration File.");
    String webMvcConfigLocation = getWebMvcConfigLocation();
    if (StringUtils.isEmpty(webMvcConfigLocation)) {
        log.info("Configuration File does not exist.");
        return registry;
    }
    if (registry == null) {
        WebApplicationContext context = obtainApplicationContext();
        context.unwrap(BeanDefinitionRegistrar.class).registerBean(ViewControllerHandlerRegistry.DEFAULT_BEAN_NAME, ViewControllerHandlerRegistry.class);
        registry = context.getBean(ViewControllerHandlerRegistry.DEFAULT_BEAN_NAME, ViewControllerHandlerRegistry.class);
    }
    registry.configure(webMvcConfigLocation);
    return registry;
}
Also used : ViewControllerHandlerRegistry(cn.taketoday.web.registry.ViewControllerHandlerRegistry) BeanDefinitionRegistrar(cn.taketoday.context.loader.BeanDefinitionRegistrar) WebApplicationContext(cn.taketoday.web.WebApplicationContext)

Aggregations

WebApplicationContext (cn.taketoday.web.WebApplicationContext)2 ViewControllerHandlerRegistry (cn.taketoday.web.registry.ViewControllerHandlerRegistry)2 BeanDefinitionRegistrar (cn.taketoday.context.loader.BeanDefinitionRegistrar)1 DispatcherHandler (cn.taketoday.web.handler.DispatcherHandler)1 HandlerAdapter (cn.taketoday.web.handler.HandlerAdapter)1 RequestHandlerAdapter (cn.taketoday.web.handler.RequestHandlerAdapter)1 ViewControllerHandlerAdapter (cn.taketoday.web.handler.ViewControllerHandlerAdapter)1