⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faceswebapplicationcontextutils.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 JAVA
字号:
/* * Copyright 2002-2004 the original author or authors. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package de.mindmatters.faces.spring.context;import java.util.Map;import javax.faces.context.FacesContext;/** * Convenience methods to retrieve the faces root FacesWebApplicationContext for * a given {@link javax.faces.context.FacesContext}. This is e.g. useful for * accessing a faces-spring context from within custom components. *  * @author Andreas Kuhrwahl *  * @see de.mindmatters.faces.spring.context.FacesWebApplicationContext */public final class FacesWebApplicationContextUtils {    /**     * Constructor (not used).     */    private FacesWebApplicationContextUtils() {        super();    }    /**     * Finds the faces root FacesWebApplicationContext for this web app, which     * is typically loaded via ContextLoaderListener.     * <p>     * Will rethrow an exception that happened on root context startup, to     * differentiate between a failed context startup and no context at all.     * </p>     *      * @param context     *            FacesContext to find the web application context for     * @return the faces root FacesWebApplicationContext for this web app, or     *         null if none     * @see FacesWebApplicationContext#ROOT_FACES_WEB_APPLICATION_CONTEXT_ATTRIBUTE     */    public static FacesWebApplicationContext getWebApplicationContext(            final FacesContext context) {        Map applicationMap = context.getExternalContext().getApplicationMap();        Object contextAttr = applicationMap                .get(FacesWebApplicationContext.ROOT_FACES_WEB_APPLICATION_CONTEXT_ATTRIBUTE);        if (contextAttr != null) {            if (contextAttr instanceof RuntimeException) {                throw (RuntimeException) contextAttr;            }            if (contextAttr instanceof Error) {                throw (Error) contextAttr;            }            if (!(contextAttr instanceof FacesWebApplicationContext)) {                throw new IllegalStateException(                        "Root context attribute is not of type FacesSpringWebApplicationContext: "                                + contextAttr);            }        }        return (FacesWebApplicationContext) contextAttr;    }    /**     * Finds the required faces root FacesWebApplicationContext for this web     * app, which is typically loaded via ContextLoaderListenr.     * <p>     * Will rethrow an exception that happened on root context startup, to     * differentiate between a failed context startup and no context at all.     * </p>     *      * @param context     *            FacesContext to find the web application context for     * @return the root WebApplicationContext for this web app     * @throws IllegalStateException     *             if the root FacesWebApplicationContext could not be found     * @see FacesWebApplicationContext#ROOT_FACES_WEB_APPLICATION_CONTEXT_ATTRIBUTE     */    public static FacesWebApplicationContext getRequiredWebApplicationContext(            final FacesContext context) {        final FacesWebApplicationContext wac = getWebApplicationContext(context);        if (wac == null) {            throw new IllegalStateException(                    "No FacesSpringWebApplicationContext found: no FacesSpringContextLoaderListener registered?");        }        return wac;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -