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.StaticApplicationContext; 26 import org.springframework.core.io.Resource; 27 import org.springframework.core.io.support.ResourcePatternResolver; 28 import org.springframework.web.context.WebApplicationContext; 29 import org.springframework.web.context.request.RequestScope; 30 import org.springframework.web.context.request.SessionScope; 31 32 51 public class StaticPortletApplicationContext extends StaticApplicationContext 52 implements ConfigurablePortletApplicationContext { 53 54 private ServletContext servletContext; 55 56 private PortletContext portletContext; 57 58 private PortletConfig portletConfig; 59 60 private String namespace; 61 62 63 public StaticPortletApplicationContext() { 64 setDisplayName("Root Portlet ApplicationContext"); 65 } 66 67 public void setParent(ApplicationContext parent) { 68 super.setParent(parent); 69 if (parent instanceof WebApplicationContext) { 70 this.servletContext = ((WebApplicationContext) parent).getServletContext(); 71 } 72 } 73 74 public ServletContext getServletContext() { 75 return this.servletContext; 76 } 77 78 public void setPortletContext(PortletContext portletContext) { 79 this.portletContext = portletContext; 80 } 81 82 public PortletContext getPortletContext() { 83 return this.portletContext; 84 } 85 86 public void setPortletConfig(PortletConfig portletConfig) { 87 this.portletConfig = portletConfig; 88 if (portletConfig != null && this.portletContext == null) { 89 this.portletContext = portletConfig.getPortletContext(); 90 } 91 } 92 93 public PortletConfig getPortletConfig() { 94 return this.portletConfig; 95 } 96 97 public void setNamespace(String namespace) { 98 this.namespace = namespace; 99 if (namespace != null) { 100 setDisplayName("Portlet ApplicationContext for namespace '" + namespace + "'"); 101 } 102 } 103 104 public String getNamespace() { 105 return this.namespace; 106 } 107 108 public void setConfigLocations(String [] configLocations) { 109 throw new UnsupportedOperationException ("StaticPortletApplicationContext does not support config locations"); 110 } 111 112 public String [] getConfigLocations() { 113 return null; 114 } 115 116 117 120 protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { 121 beanFactory.registerScope(SCOPE_REQUEST, new RequestScope()); 122 beanFactory.registerScope(SCOPE_SESSION, new SessionScope(false)); 123 beanFactory.registerScope(SCOPE_GLOBAL_SESSION, new SessionScope(true)); 124 125 beanFactory.addBeanPostProcessor(new PortletContextAwareProcessor(this.portletContext, this.portletConfig)); 126 beanFactory.ignoreDependencyInterface(PortletContextAware.class); 127 beanFactory.ignoreDependencyInterface(PortletConfigAware.class); 128 } 129 130 134 protected Resource getResourceByPath(String path) { 135 return new PortletContextResource(this.portletContext, path); 136 } 137 138 142 protected ResourcePatternResolver getResourcePatternResolver() { 143 return new PortletContextResourcePatternResolver(this); 144 } 145 146 } 147 | Popular Tags |