📄 jsfcomponentstartupprocessor.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.factory.aspectj;import java.util.Collection;import java.util.Iterator;import javax.faces.FactoryFinder;import javax.faces.application.Application;import javax.faces.application.ApplicationFactory;import org.springframework.beans.FatalBeanException;import org.springframework.beans.factory.config.BeanFactoryPostProcessor;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.core.Ordered;import org.springframework.util.ClassUtils;/** * A <strong>BeanFactoryPostProcessor</strong> which initializes and configures * all relevant JSF components which are hosted and defined in the * {@link de.mindmatters.faces.spring.context.FacesWebApplicationContext}. * * <p> * The following components will be configured and registered at the underlying * JSF implementation: * <ol> * <li>the {@link javax.faces.component.UIComponent}s</li> * <li>the {@link javax.faces.validator.Validator}s</li> * <li>the {@link javax.faces.convert.Converter}s</li> * </ol> * </p> * * <p> * <strong>Note: The <code>JsfStartupProcessor</code> will be automatically * registered!</strong> * </p> * * @author Andreas Kuhrwahl * */public class JsfComponentStartupProcessor implements BeanFactoryPostProcessor, Ordered { /** The order of this {@link BeanFactoryPostProcessor}. */ private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 2; /** * {@inheritDoc} */ public void postProcessBeanFactory( final ConfigurableListableBeanFactory beanFactory) { Application application = ((ApplicationFactory) FactoryFinder .getFactory(FactoryFinder.APPLICATION_FACTORY)) .getApplication(); Collection factoryBeans = beanFactory.getBeansOfType( UIComponentDefinition.class, false, true).values(); for (Iterator i = factoryBeans.iterator(); i.hasNext();) { UIComponentDefinition factoryBean = (UIComponentDefinition) i .next(); application.addComponent(factoryBean.getComponentType(), factoryBean.getComponentClassName()); } factoryBeans = beanFactory.getBeansOfType(ValidatorDefinition.class, false, true).values(); for (Iterator i = factoryBeans.iterator(); i.hasNext();) { ValidatorDefinition factoryBean = (ValidatorDefinition) i.next(); application.addValidator(factoryBean.getValidatorId(), factoryBean .getValidatorClassName()); } factoryBeans = beanFactory.getBeansOfType(ConverterDefinition.class, false, true).values(); for (Iterator i = factoryBeans.iterator(); i.hasNext();) { ConverterDefinition factoryBean = (ConverterDefinition) i.next(); if (factoryBean.registerById()) { application.addConverter(factoryBean.getConverterRegistrar(), factoryBean.getConverterClassName()); } else { try { application.addConverter(ClassUtils.forName(factoryBean .getConverterRegistrar(), beanFactory .getBeanClassLoader()), factoryBean .getConverterClassName()); } catch (Throwable ex) { throw new FatalBeanException( "Could not register Converter '" + factoryBean.getConverterClassName() + "' for class '" + factoryBean.getConverterRegistrar() + "'", ex); } } } } /** * {@inheritDoc} */ public final int getOrder() { return ORDER; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -