1 16 17 package org.springframework.web.struts; 18 19 import java.io.IOException ; 20 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.struts.action.Action; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionServlet; 28 import org.apache.struts.action.RequestProcessor; 29 import org.apache.struts.config.ModuleConfig; 30 31 import org.springframework.beans.BeansException; 32 import org.springframework.web.context.WebApplicationContext; 33 34 101 public class DelegatingRequestProcessor extends RequestProcessor { 102 103 private WebApplicationContext webApplicationContext; 104 105 106 public void init(ActionServlet actionServlet, ModuleConfig moduleConfig) throws ServletException { 107 super.init(actionServlet, moduleConfig); 108 if (actionServlet != null) { 109 this.webApplicationContext = initWebApplicationContext(actionServlet, moduleConfig); 110 } 111 } 112 113 124 protected WebApplicationContext initWebApplicationContext( 125 ActionServlet actionServlet, ModuleConfig moduleConfig) throws IllegalStateException { 126 127 return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, moduleConfig); 128 } 129 130 133 protected final WebApplicationContext getWebApplicationContext() { 134 return webApplicationContext; 135 } 136 137 138 142 protected Action processActionCreate( 143 HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) 144 throws IOException { 145 146 Action action = getDelegateAction(mapping); 147 if (action != null) { 148 return action; 149 } 150 return super.processActionCreate(request, response, mapping); 151 } 152 153 163 protected Action getDelegateAction(ActionMapping mapping) throws BeansException { 164 String beanName = determineActionBeanName(mapping); 165 if (!getWebApplicationContext().containsBean(beanName)) { 166 return null; 167 } 168 return (Action) getWebApplicationContext().getBean(beanName, Action.class); 169 } 170 171 182 protected String determineActionBeanName(ActionMapping mapping) { 183 return DelegatingActionUtils.determineActionBeanName(mapping); 184 } 185 186 } 187 | Popular Tags |