1 16 17 package org.springframework.web.portlet.context; 18 19 import javax.portlet.PortletContext; 20 21 import org.springframework.context.ApplicationContext; 22 import org.springframework.util.Assert; 23 import org.springframework.web.context.WebApplicationContext; 24 25 38 public abstract class PortletApplicationContextUtils { 39 40 51 public static ApplicationContext getWebApplicationContext(PortletContext pc) { 52 Assert.notNull(pc, "PortletContext must not be null"); 53 Object attr = pc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); 54 if (attr == null) { 55 return null; 56 } 57 if (attr instanceof RuntimeException ) { 58 throw (RuntimeException ) attr; 59 } 60 if (attr instanceof Error ) { 61 throw (Error ) attr; 62 } 63 if (!(attr instanceof ApplicationContext)) { 64 throw new IllegalStateException ("Root context attribute is not of type WebApplicationContext: " + attr); 65 } 66 return (ApplicationContext) attr; 67 } 68 69 81 public static ApplicationContext getRequiredWebApplicationContext(PortletContext pc) 82 throws IllegalStateException { 83 84 ApplicationContext wac = getWebApplicationContext(pc); 85 if (wac == null) { 86 throw new IllegalStateException ("No WebApplicationContext found: no ContextLoaderListener registered?"); 87 } 88 return wac; 89 } 90 91 } 92 | Popular Tags |