/** * Return the current ServletContext. * @throws IllegalStateException if not running within a required ServletContext * @see #isContextRequired() */ @Nullable protected final ServletContext getServletContext() throws IllegalStateException { if (this.servletContext != null) { return this.servletContext; } ServletContext servletContext = null; WebApplicationContext wac = getWebApplicationContext(); if (wac != null) { servletContext = wac.getServletContext(); } if (servletContext == null && isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run within a ServletContext. Make sure the object is fully configured!"); } return servletContext; }
/** * Return the current application context as WebApplicationContext. * <p><b>NOTE:</b> Only use this if you actually need to access * WebApplicationContext-specific functionality. Preferably use * {@code getApplicationContext()} or {@code getServletContext()} * else, to be able to run in non-WebApplicationContext environments as well. * @throws IllegalStateException if not running in a WebApplicationContext * @see #getApplicationContext() */ @Nullable protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException { ApplicationContext ctx = getApplicationContext(); if (ctx instanceof WebApplicationContext) { return (WebApplicationContext) getApplicationContext(); } else if (isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run in a WebApplicationContext but in: " + ctx); } else { return null; } }
/** * Return the current ServletContext. * @throws IllegalStateException if not running within a required ServletContext * @see #isContextRequired() */ @Nullable protected final ServletContext getServletContext() throws IllegalStateException { if (this.servletContext != null) { return this.servletContext; } ServletContext servletContext = null; WebApplicationContext wac = getWebApplicationContext(); if (wac != null) { servletContext = wac.getServletContext(); } if (servletContext == null && isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run within a ServletContext. Make sure the object is fully configured!"); } return servletContext; }
/** * Return the current application context as WebApplicationContext. * <p><b>NOTE:</b> Only use this if you actually need to access * WebApplicationContext-specific functionality. Preferably use * {@code getApplicationContext()} or {@code getServletContext()} * else, to be able to run in non-WebApplicationContext environments as well. * @throws IllegalStateException if not running in a WebApplicationContext * @see #getApplicationContext() */ @Nullable protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException { ApplicationContext ctx = getApplicationContext(); if (ctx instanceof WebApplicationContext) { return (WebApplicationContext) getApplicationContext(); } else if (isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run in a WebApplicationContext but in: " + ctx); } else { return null; } }
/** * Return the current ServletContext. * @throws IllegalStateException if not running within a required ServletContext * @see #isContextRequired() */ @Nullable protected final ServletContext getServletContext() throws IllegalStateException { if (this.servletContext != null) { return this.servletContext; } ServletContext servletContext = null; WebApplicationContext wac = getWebApplicationContext(); if (wac != null) { servletContext = wac.getServletContext(); } if (servletContext == null && isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run within a ServletContext. Make sure the object is fully configured!"); } return servletContext; }
/** * Return the current ServletContext. * @throws IllegalStateException if not running within a required ServletContext * @see #isContextRequired() */ @Nullable protected final ServletContext getServletContext() throws IllegalStateException { if (this.servletContext != null) { return this.servletContext; } ServletContext servletContext = null; WebApplicationContext wac = getWebApplicationContext(); if (wac != null) { servletContext = wac.getServletContext(); } if (servletContext == null && isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run within a ServletContext. Make sure the object is fully configured!"); } return servletContext; }
/** * Return the current application context as WebApplicationContext. * <p><b>NOTE:</b> Only use this if you actually need to access * WebApplicationContext-specific functionality. Preferably use * {@code getApplicationContext()} or {@code getServletContext()} * else, to be able to run in non-WebApplicationContext environments as well. * @throws IllegalStateException if not running in a WebApplicationContext * @see #getApplicationContext() */ @Nullable protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException { ApplicationContext ctx = getApplicationContext(); if (ctx instanceof WebApplicationContext) { return (WebApplicationContext) getApplicationContext(); } else if (isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run in a WebApplicationContext but in: " + ctx); } else { return null; } }
/** * Return the current application context as WebApplicationContext. * <p><b>NOTE:</b> Only use this if you actually need to access * WebApplicationContext-specific functionality. Preferably use * {@code getApplicationContext()} or {@code getServletContext()} * else, to be able to run in non-WebApplicationContext environments as well. * @throws IllegalStateException if not running in a WebApplicationContext * @see #getApplicationContext() */ @Nullable protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException { ApplicationContext ctx = getApplicationContext(); if (ctx instanceof WebApplicationContext) { return (WebApplicationContext) getApplicationContext(); } else if (isContextRequired()) { throw new IllegalStateException("WebApplicationObjectSupport instance [" + this + "] does not run in a WebApplicationContext but in: " + ctx); } else { return null; } }