1 4 package com.opensymphony.webwork.spring.lifecycle; 5 6 import com.opensymphony.xwork.config.Configuration; 7 import com.opensymphony.xwork.config.ConfigurationManager; 8 import com.opensymphony.xwork.config.ExternalReferenceResolver; 9 import com.opensymphony.xwork.config.entities.PackageConfig; 10 import org.springframework.context.ApplicationContext; 11 import org.springframework.context.ApplicationContextAware; 12 import org.springframework.web.context.support.WebApplicationContextUtils; 13 14 import javax.servlet.ServletContextEvent ; 15 import javax.servlet.ServletContextListener ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 19 28 public class SpringExternalReferenceResolverSetupListener implements 29 ServletContextListener { 30 public void contextInitialized(ServletContextEvent event) { 31 ApplicationContext appContext = WebApplicationContextUtils 32 .getWebApplicationContext(event.getServletContext()); 33 34 Configuration xworkConfig = ConfigurationManager.getConfiguration(); 35 Map packageConfigs = xworkConfig.getPackageConfigs(); 36 Iterator i = packageConfigs.values().iterator(); 37 38 while (i.hasNext()) { 39 PackageConfig packageConfig = (PackageConfig) i.next(); 40 ExternalReferenceResolver resolver = packageConfig.getExternalRefResolver(); 41 if (resolver == null || !(resolver instanceof ApplicationContextAware)) 42 continue; 43 ApplicationContextAware contextAware = (ApplicationContextAware) resolver; 44 contextAware.setApplicationContext(appContext); 45 } 46 } 47 48 public void contextDestroyed(ServletContextEvent event) { 49 } 51 52 } | Popular Tags |