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

📄 contextloader.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * or not.     *      * @param servletContext     *            The servlet context     */    private void validateFacesConfiguration(final ServletContext servletContext) {        servletContext.log("Validating faces configuration");        String message = "Faces configuration not loaded yet. "                + "Please configure your faces implementation before jsf-spring starts its configuration!";        Assert.notNull(FactoryFinder                .getFactory(FactoryFinder.LIFECYCLE_FACTORY), message);        Assert.notNull(FactoryFinder                .getFactory(FactoryFinder.APPLICATION_FACTORY), message);        Assert.notNull(FactoryFinder                .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY), message);        Assert.notNull(FactoryFinder                .getFactory(FactoryFinder.RENDER_KIT_FACTORY), message);    }    /**     * Template method with default implementation (which may be overridden by a     * subclass), to load or obtain an ApplicationContext instance which will be     * used as the parent context of the root WebApplicationContext. If the     * return value from the method is null, no parent context is set.     * <p>     * The default implementation uses ContextSingletonBeanFactoryLocator,     * configured via {@link #LOCATOR_FACTORY_SELECTOR_PARAM} and     * {@link #LOCATOR_FACTORY_KEY_PARAM}, to load a parent context which will     * be shared by all other users of ContextsingletonBeanFactoryLocator which     * also use the same configuration parameters, or if     * {@link #LOCATOR_FACTORY_KEY_PARAM} is not set a parent context obtained     * by     * {@link WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)}.     * </p>     *      * @param servletContext     *            current servlet context     * @return the parent application context, or <code>null</code> if none     * @throws org.springframework.beans.BeansException     *             if the context couldn't be initialized     * @see org.springframework.beans.factory.access.BeanFactoryLocator     * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator     */    protected ApplicationContext loadParentContext(            final ServletContext servletContext) {        ApplicationContext parentContext = null;        String locatorFactorySelector = servletContext                .getInitParameter(LOCATOR_FACTORY_SELECTOR_PARAM);        String parentContextKey = servletContext                .getInitParameter(LOCATOR_FACTORY_KEY_PARAM);        if (locatorFactorySelector != null) {            BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator                    .getInstance(locatorFactorySelector);            if (logger.isInfoEnabled()) {                logger                        .info("Getting parent context definition: using parent context key of '"                                + parentContextKey                                + "' with BeanFactoryLocator");            }            this.parentContextRef = locator.useBeanFactory(parentContextKey);            parentContext = (ApplicationContext) this.parentContextRef                    .getFactory();        }        if (parentContext == null) {            parentContext = WebApplicationContextUtils                    .getWebApplicationContext(servletContext);        }        return parentContext;    }    /**     * Creates and returns a {@link WebApplicationContext}.     *      * @param servletContext     *            the servlet context     * @param parent     *            parent application context     * @return a new ConfigWebApplicationContext     * @throws org.springframework.beans.BeansException     *             in cases of errors     */    protected WebApplicationContext createWebApplicationContext(            final ServletContext servletContext, final ApplicationContext parent) {        Class contextClass = determineContextClass(servletContext);        if (!FacesWebApplicationContext.class.isAssignableFrom(contextClass)) {            throw new ApplicationContextException("Custom context class ["                    + contextClass.getName()                    + "] is not of type FacesWebApplicationContext");        }        FacesWebApplicationContext wac = (FacesWebApplicationContext) BeanUtils                .instantiateClass(contextClass);        wac.setParent(parent);        wac.setServletContext(servletContext);        String configLocation = servletContext                .getInitParameter(FacesServlet.CONFIG_FILES_ATTR);        if (configLocation != null) {            wac                    .setConfigLocations(StringUtils                            .tokenizeToStringArray(                                    configLocation,                                    ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));        }        configLocation = servletContext                .getInitParameter(CONTEXT_LOCATION_PARAM);        if (configLocation != null) {            wac                    .setFacesSpringConfigLocations(StringUtils                            .tokenizeToStringArray(                                    configLocation,                                    ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));        }        wac.refresh();        return wac;    }    /**     * Returns the WebApplicationContext implementation class to use, either the     * default FacesWebApplicationContext or a custom context class if     * specified.     *      * @param servletContext     *            current servlet context     * @return the WebApplicationContext implementation class to use     * @throws ApplicationContextException     *             if the context class couldn't be loaded     * @see #CONTEXT_CLASS_PARAM     * @see org.springframework.web.context.support.XmlWebApplicationContext     */    protected final Class determineContextClass(            final ServletContext servletContext) {        String contextClassName = servletContext                .getInitParameter(CONTEXT_CLASS_PARAM);        Class contextClass = null;        if (contextClassName == null) {            contextClassName = DEFAULT_STRATEGIES                    .getProperty(FacesWebApplicationContext.class.getName());            try {                contextClass = ClassUtils.forName(contextClassName);            } catch (ClassNotFoundException ex) {                throw new ApplicationContextException(                        "Failed to load default context class ["                                + contextClassName + "]", ex);            }        } else {            try {                contextClass = ClassUtils.forName(contextClassName);            } catch (ClassNotFoundException ex) {                throw new ApplicationContextException(                        "Failed to load custom context class ["                                + contextClassName + "]", ex);            }        }        return contextClass;    }    /**     * Closes the web application context for the given servlet context.     *      * @param servletContext     *            the servlet context     */    public final void closeWebApplicationContext(            final ServletContext servletContext) {        servletContext.log("Closing ConfigWebApplicationContext");        try {            if (this.context instanceof ConfigurableWebApplicationContext) {                ((ConfigurableWebApplicationContext) this.context).close();            }        } finally {            if (this.parentContextRef != null) {                this.parentContextRef.release();            } else if (this.context != null) {                closeParentApplicationContext(servletContext, this.context                        .getParent());            }        }    }    /**     * Closes the parent web application context of <em>jsf-spring</em> web     * application context for the given servlet context. If overriding     * {@link #loadParentContext(ServletContext)}, you may have to override     * this method as well.     *      * @param servletContext     *            the servlet context     * @param parent     *            parent ApplicationContext     */    protected void closeParentApplicationContext(            final ServletContext servletContext, final ApplicationContext parent) {    }}

⌨️ 快捷键说明

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