1 24 package org.riotfamily.common.beans; 25 26 import javax.servlet.ServletContext ; 27 28 import org.springframework.beans.factory.BeanNameAware; 29 import org.springframework.beans.factory.InitializingBean; 30 import org.springframework.context.ApplicationContext; 31 import org.springframework.context.ApplicationContextAware; 32 import org.springframework.web.context.ServletContextAware; 33 import org.springframework.web.context.support.XmlWebApplicationContext; 34 35 45 public class ChildContextLoader implements InitializingBean, 46 ApplicationContextAware, ServletContextAware, BeanNameAware { 47 48 private String displayName; 49 50 private boolean loadContext = true; 51 52 private String [] configLocations; 53 54 private XmlWebApplicationContext context; 55 56 private ServletContext servletContext; 57 58 private ApplicationContext parent; 59 60 public void setConfigLocations(String [] configLocations) { 61 this.configLocations = configLocations; 62 } 63 64 public void setLoadContext(boolean loadContext) { 65 this.loadContext = loadContext; 66 } 67 68 public void setApplicationContext(ApplicationContext applicationContext) { 69 this.parent = applicationContext; 70 } 71 72 public void setServletContext(ServletContext servletContext) { 73 this.servletContext = servletContext; 74 } 75 76 public void setBeanName(String name) { 77 this.displayName = name; 78 } 79 80 public void afterPropertiesSet() throws Exception { 81 if (loadContext) { 82 context = new XmlWebApplicationContext(); 83 context.setParent(parent); 84 context.setDisplayName(displayName); 85 context.setConfigLocations(configLocations); 86 context.setServletContext(servletContext); 87 context.refresh(); 88 } 89 } 90 91 public ApplicationContext getContext() { 92 return this.context; 93 } 94 95 } 96 | Popular Tags |