1 24 package org.riotfamily.common.web.servlet; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.riotfamily.common.xml.BeanConfigurationWatcher; 30 import org.riotfamily.common.xml.ConfigurableBean; 31 import org.springframework.beans.BeansException; 32 import org.springframework.beans.factory.BeanFactoryUtils; 33 import org.springframework.beans.factory.NoSuchBeanDefinitionException; 34 import org.springframework.context.ApplicationContext; 35 import org.springframework.web.servlet.DispatcherServlet; 36 37 52 public class ReloadableDispatcherServlet extends DispatcherServlet 53 implements ConfigurableBean { 54 55 private boolean reloadable = true; 56 57 private BeanConfigurationWatcher watcher = new BeanConfigurationWatcher(this); 58 59 public Class getContextClass() { 60 return ResourceAwareContext.class; 61 } 62 63 public void setReloadable(boolean reloadable) { 64 this.reloadable = reloadable; 65 } 66 67 public boolean isReloadable() { 68 return reloadable; 69 } 70 71 private void configureFromContext(ApplicationContext context) { 72 try { 73 ReloadableDispatcherServletConfig config = 74 (ReloadableDispatcherServletConfig) 75 BeanFactoryUtils.beanOfType(context, 76 ReloadableDispatcherServletConfig.class); 77 78 setReloadable(config.isReloadable()); 79 } 80 catch (NoSuchBeanDefinitionException e) { 81 } 82 } 83 84 protected void onRefresh(ApplicationContext context) throws BeansException { 85 super.onRefresh(context); 86 configureFromContext(context); 87 ResourceAwareContext ctx = (ResourceAwareContext) context; 88 watcher.setResources(ctx.getConfigResources()); 89 } 90 91 protected void doDispatch(HttpServletRequest request, 92 HttpServletResponse response) throws Exception { 93 94 watcher.checkForModifications(); 95 super.doDispatch(request, response); 96 } 97 98 public void configure() { 99 refresh(); 100 } 101 } 102 | Popular Tags |