1 16 17 package org.springframework.web.portlet.context; 18 19 import javax.portlet.PortletConfig; 20 import javax.portlet.PortletContext; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.springframework.beans.BeansException; 26 import org.springframework.beans.factory.config.BeanPostProcessor; 27 28 41 public class PortletContextAwareProcessor implements BeanPostProcessor { 42 43 protected final Log logger = LogFactory.getLog(getClass()); 44 45 private PortletContext portletContext; 46 47 private PortletConfig portletConfig; 48 49 50 53 public PortletContextAwareProcessor(PortletContext portletContext) { 54 this(portletContext, null); 55 } 56 57 60 public PortletContextAwareProcessor(PortletConfig portletConfig) { 61 this(null, portletConfig); 62 } 63 64 67 public PortletContextAwareProcessor(PortletContext portletContext, PortletConfig portletConfig) { 68 this.portletContext = portletContext; 69 this.portletConfig = portletConfig; 70 if (portletContext == null && portletConfig != null) { 71 this.portletContext = portletConfig.getPortletContext(); 72 } 73 } 74 75 76 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 77 if (bean instanceof PortletContextAware) { 78 if (this.portletContext == null) { 79 throw new IllegalStateException ("Cannot satisfy PortletContextAware for bean '" + 80 beanName + "' without PortletContext"); 81 } 82 if (logger.isDebugEnabled()) { 83 logger.debug("Invoking setPortletContext on PortletContextAware bean '" + beanName + "'"); 84 } 85 ((PortletContextAware) bean).setPortletContext(this.portletContext); 86 } 87 if (bean instanceof PortletConfigAware) { 88 if (this.portletConfig == null) { 89 throw new IllegalStateException ("Cannot satisfy PortletConfigAware for bean '" + 90 beanName + "' without PortletConfig"); 91 } 92 if (logger.isDebugEnabled()) { 93 logger.debug("Invoking setPortletConfig on PortletConfigAware bean '" + beanName + "'"); 94 } 95 ((PortletConfigAware) bean).setPortletConfig(this.portletConfig); 96 } 97 return bean; 98 } 99 100 public Object postProcessAfterInitialization(Object bean, String beanName) { 101 return bean; 102 } 103 104 } 105 | Popular Tags |