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

📄 jsfstartupprocessor.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.factory.xml;import java.io.IOException;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Iterator;import java.util.List;import java.util.Properties;import javax.faces.FacesException;import javax.faces.FactoryFinder;import javax.faces.application.Application;import javax.faces.application.ApplicationFactory;import javax.faces.application.NavigationHandler;import javax.faces.application.StateManager;import javax.faces.application.ViewHandler;import javax.faces.el.PropertyResolver;import javax.faces.el.VariableResolver;import javax.faces.event.ActionListener;import javax.faces.event.PhaseId;import javax.faces.event.PhaseListener;import javax.faces.lifecycle.Lifecycle;import javax.faces.lifecycle.LifecycleFactory;import javax.faces.render.RenderKit;import javax.faces.render.RenderKitFactory;import org.springframework.beans.BeanUtils;import org.springframework.beans.factory.NoSuchBeanDefinitionException;import org.springframework.beans.factory.config.BeanFactoryPostProcessor;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.core.OrderComparator;import org.springframework.core.Ordered;import org.springframework.core.io.ClassPathResource;import org.springframework.core.io.support.PropertiesLoaderUtils;import org.springframework.util.Assert;import org.springframework.util.ClassUtils;import de.mindmatters.faces.application.ApplicationImpl;import de.mindmatters.faces.lifecycle.LifecycleImpl;import de.mindmatters.faces.lifecycle.Phase;import de.mindmatters.faces.spring.factory.OrderedBeanDefinitionHolder;/** * A <strong>BeanFactoryPostProcessor</strong> which initializes and configures * all relevant JSF plugins which are hosted and defined in the * {@link de.mindmatters.faces.spring.context.FacesWebApplicationContext}. *  * <p> * The following plugins will be configured and registered at the underlying JSF * implementation: * <ol> * <li>the JSF-Spring specific {@link Lifecycle} of type {@link LifecycleImpl} * with the id {@link LifecycleImpl#JSF_SPRING_LIFECYCLE_ID} and the defined * {@link Phase}s (or default phases if the appropriate phase ist not * configured in the * {@link de.mindmatters.faces.spring.context.FacesWebApplicationContext})</li> * <li>the JSF-Spring specific {@link Application} of type * {@link ApplicationImpl}</li> * <li>the {@link javax.faces.event.PhaseListener}s for the appropriate * {@link Lifecycle}</li> * <li>the {@link ActionListener}s</li> * <li>the {@link NavigationHandler}s</li> * <li>the {@link PropertyResolver}s</li> * <li>the {@link StateManager}s</li> * <li>the {@link VariableResolver}s</li> * <li>the {@link ViewHandler}s</li> * <li>the {@link RenderKit}s with the appropriate * {@link javax.faces.render.Renderer}s</li> * </ol> * </p> *  * <p> * <strong>Note: The <code>JsfStartupProcessor</code> will be automatically * registered!</strong> * </p> *  * @author Andreas Kuhrwahl *  */public final class JsfStartupProcessor implements BeanFactoryPostProcessor,        Ordered {    /**     * Name of the class path resource (relative to the JsfStartupProcessor     * class) that defines JsfStartupProcessor's default strategy names.     */    private static final String DEFAULT_STRATEGIES_PATH = "startup.properties";    /** The default strategies. */    private static final Properties DEFAULT_STRATEGIES;    static {        // Load default strategy implementations from properties file.        // This is currently strictly internal and not meant to be customized        // by application developers.        try {            ClassPathResource resource = new ClassPathResource(                    DEFAULT_STRATEGIES_PATH, JsfStartupProcessor.class);            DEFAULT_STRATEGIES = PropertiesLoaderUtils.loadProperties(resource);        } catch (IOException ex) {            throw new IllegalStateException(                    "Could not load 'ContextLoader.properties': "                            + ex.getMessage());        }    }    /** The order of this {@link BeanFactoryPostProcessor}. */    private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 2;    /**     * {@inheritDoc}     */    public void postProcessBeanFactory(            final ConfigurableListableBeanFactory beanFactory) {        configureJsfSpringLifecycle(beanFactory);        configureApplication(beanFactory);        configurePhaseListeners(beanFactory);        Application application = ((ApplicationFactory) FactoryFinder                .getFactory(FactoryFinder.APPLICATION_FACTORY))                .getApplication();        configureActionListeners(beanFactory, application);        configureNavigationHandlers(beanFactory, application);        configurePropertyResolvers(beanFactory, application);        configureStateManagers(beanFactory, application);        configureVariableResolvers(beanFactory, application);        configureViewHandlers(beanFactory, application);        configureRenderKits(beanFactory);    }    /**     * Configures the specific JSF-Spring {@link Lifecycle}.     *      * @param beanFactory     *            the {@link org.springframework.beans.factory.BeanFactory}     */    private void configureJsfSpringLifecycle(            final ConfigurableListableBeanFactory beanFactory) {        LifecycleFactory factory = (LifecycleFactory) FactoryFinder                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);        Lifecycle jsfSpringLifecycle = new LifecycleImpl(new Phase[] {                getPhase(beanFactory, PhaseId.RESTORE_VIEW),                getPhase(beanFactory, PhaseId.APPLY_REQUEST_VALUES),                getPhase(beanFactory, PhaseId.PROCESS_VALIDATIONS),                getPhase(beanFactory, PhaseId.UPDATE_MODEL_VALUES),                getPhase(beanFactory, PhaseId.INVOKE_APPLICATION) }, getPhase(                beanFactory, PhaseId.RENDER_RESPONSE));        Lifecycle defaultLifecycle = factory                .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);        PhaseListener[] defaultPhaseListeners = defaultLifecycle                .getPhaseListeners();        for (int i = 0; i < defaultPhaseListeners.length; i++) {            jsfSpringLifecycle.addPhaseListener((PhaseListener) BeanUtils                    .instantiateClass(defaultPhaseListeners[i].getClass()));        }        factory.addLifecycle(LifecycleImpl.JSF_SPRING_LIFECYCLE_ID,                jsfSpringLifecycle);    }    /**     * Resturns the appropriate {@link Phase}.     *      * @param beanFactory     *            the {@link org.springframework.beans.factory.BeanFactory}     * @param phaseId     *            the phase id     * @return the phase     * @throws FacesException     *             in case of errors     */    private Phase getPhase(final ConfigurableListableBeanFactory beanFactory,            final PhaseId phaseId) {        String phaseName = Phase.PhaseIdName.valueOf(phaseId);        Assert.notNull(phaseName);        Phase phase = null;        try {            phase = (Phase) beanFactory.getBean(phaseName, Phase.class);        } catch (NoSuchBeanDefinitionException ex) {            phase = null;        }        if (phase == null) {            String phaseClassName = DEFAULT_STRATEGIES.getProperty(phaseName);            try {                Class phaseClass = ClassUtils.forName(phaseClassName);                phase = (Phase) BeanUtils.instantiateClass(phaseClass);            } catch (Exception ex) {                throw new FacesException("Failed to load default phase class ["                        + phaseClassName + "]", ex);            }        }        return phase;    }    /**     * Configures the JSF-Spring specific {@link Application}.     *      * @param beanFactory     *            the {@link org.springframework.beans.factory.BeanFactory}     */    private void configureApplication(            final ConfigurableListableBeanFactory beanFactory) {        ApplicationFactory factory = (ApplicationFactory) FactoryFinder                .getFactory(FactoryFinder.APPLICATION_FACTORY);        factory.setApplication(new ApplicationImpl(factory.getApplication(),                beanFactory));

⌨️ 快捷键说明

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