1 16 17 package org.springframework.web.portlet.context; 18 19 import javax.portlet.PortletConfig; 20 import javax.portlet.PortletContext; 21 import javax.servlet.ServletContext ; 22 23 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 24 import org.springframework.context.ApplicationContext; 25 import org.springframework.context.support.AbstractRefreshableApplicationContext; 26 import org.springframework.core.io.Resource; 27 import org.springframework.core.io.support.ResourcePatternResolver; 28 import org.springframework.util.ObjectUtils; 29 import org.springframework.web.context.ServletContextAware; 30 import org.springframework.web.context.WebApplicationContext; 31 import org.springframework.web.context.request.RequestScope; 32 import org.springframework.web.context.request.SessionScope; 33 import org.springframework.web.context.support.ServletContextAwareProcessor; 34 35 71 public abstract class AbstractRefreshablePortletApplicationContext extends AbstractRefreshableApplicationContext 72 implements WebApplicationContext, ConfigurablePortletApplicationContext { 73 74 75 private ServletContext servletContext; 76 77 78 private PortletContext portletContext; 79 80 81 private PortletConfig portletConfig; 82 83 84 private String namespace; 85 86 87 private String [] configLocations; 88 89 90 public AbstractRefreshablePortletApplicationContext() { 91 setDisplayName("Root PortletApplicationContext"); 92 } 93 94 public void setParent(ApplicationContext parent) { 95 super.setParent(parent); 96 if (parent instanceof WebApplicationContext) { 97 this.servletContext = ((WebApplicationContext) parent).getServletContext(); 98 } 99 } 100 101 public ServletContext getServletContext() { 102 return this.servletContext; 103 } 104 105 public void setPortletContext(PortletContext portletContext) { 106 this.portletContext = portletContext; 107 } 108 109 public PortletContext getPortletContext() { 110 return this.portletContext; 111 } 112 113 public void setPortletConfig(PortletConfig portletConfig) { 114 this.portletConfig = portletConfig; 115 if (portletConfig != null && this.portletContext == null) { 116 this.portletContext = portletConfig.getPortletContext(); 117 } 118 } 119 120 public PortletConfig getPortletConfig() { 121 return this.portletConfig; 122 } 123 124 public void setNamespace(String namespace) { 125 this.namespace = namespace; 126 if (namespace != null) { 127 setDisplayName("PortletApplicationContext for namespace '" + namespace + "'"); 128 } 129 } 130 131 public String getNamespace() { 132 return this.namespace; 133 } 134 135 public void setConfigLocations(String [] configLocations) { 136 this.configLocations = configLocations; 137 } 138 139 public String [] getConfigLocations() { 140 return (!ObjectUtils.isEmpty(this.configLocations) ? this.configLocations : getDefaultConfigLocations()); 141 } 142 143 150 protected String [] getDefaultConfigLocations() { 151 return null; 152 } 153 154 155 158 protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { 159 beanFactory.registerScope(SCOPE_REQUEST, new RequestScope()); 160 beanFactory.registerScope(SCOPE_SESSION, new SessionScope(false)); 161 beanFactory.registerScope(SCOPE_GLOBAL_SESSION, new SessionScope(true)); 162 163 beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext)); 164 beanFactory.addBeanPostProcessor(new PortletContextAwareProcessor(this.portletContext, this.portletConfig)); 165 beanFactory.ignoreDependencyInterface(ServletContextAware.class); 166 beanFactory.ignoreDependencyInterface(PortletContextAware.class); 167 beanFactory.ignoreDependencyInterface(PortletConfigAware.class); 168 } 169 170 174 protected Resource getResourceByPath(String path) { 175 return new PortletContextResource(this.portletContext, path); 176 } 177 178 182 protected ResourcePatternResolver getResourcePatternResolver() { 183 return new PortletContextResourcePatternResolver(this); 184 } 185 186 } 187 | Popular Tags |