1 16 17 package org.springframework.web.jsf; 18 19 import javax.faces.context.ExternalContext; 20 import javax.faces.context.FacesContext; 21 22 import org.springframework.util.Assert; 23 import org.springframework.web.context.WebApplicationContext; 24 import org.springframework.web.util.WebUtils; 25 26 38 public abstract class FacesContextUtils { 39 40 49 public static WebApplicationContext getWebApplicationContext(FacesContext fc) { 50 Assert.notNull(fc, "FacesContext must not be null"); 51 Object attr = fc.getExternalContext().getApplicationMap().get( 52 WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); 53 if (attr == null) { 54 return null; 55 } 56 if (attr instanceof RuntimeException ) { 57 throw (RuntimeException ) attr; 58 } 59 if (attr instanceof Error ) { 60 throw (Error ) attr; 61 } 62 if (!(attr instanceof WebApplicationContext)) { 63 throw new IllegalStateException ("Root context attribute is not of type WebApplicationContext: " + attr); 64 } 65 return (WebApplicationContext) attr; 66 } 67 68 78 public static WebApplicationContext getRequiredWebApplicationContext(FacesContext fc) 79 throws IllegalStateException { 80 81 WebApplicationContext wac = getWebApplicationContext(fc); 82 if (wac == null) { 83 throw new IllegalStateException ("No WebApplicationContext found: no ContextLoaderListener registered?"); 84 } 85 return wac; 86 } 87 88 108 public static Object getSessionMutex(FacesContext fc) { 109 Assert.notNull(fc, "FacesContext must not be null"); 110 ExternalContext ec = fc.getExternalContext(); 111 Object mutex = ec.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE); 112 if (mutex == null) { 113 mutex = ec.getSession(true); 114 } 115 return mutex; 116 } 117 118 } 119 | Popular Tags |