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

📄 valuebindingresolvingpropertyconfigurer.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.factory;import org.springframework.beans.factory.BeanDefinitionStoreException;import org.springframework.beans.factory.BeanFactory;import org.springframework.beans.factory.BeanFactoryAware;import org.springframework.beans.factory.BeanNameAware;import org.springframework.beans.factory.config.BeanDefinition;import org.springframework.beans.factory.config.BeanDefinitionVisitor;import org.springframework.beans.factory.config.BeanFactoryPostProcessor;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.beans.factory.config.ConstructorArgumentValues;import org.springframework.beans.factory.config.TypedStringValue;import org.springframework.beans.factory.support.RootBeanDefinition;import org.springframework.core.Ordered;import de.mindmatters.faces.FacesUtils;/** * A property configurer that resolves value bindings in bean property values of * context definitions. *  * <p> * The syntax follows the JSF EL style: * </p> *  * <pre> *  #{...} * </pre> *  * <p> * Example XML context definition: * </p> *  * <pre> *  &lt;bean id=&quot;myPerson&quot; class=&quot;foo.Person&quot;&gt; *    &lt;property name=&quot;firstname&quot;&gt;&lt;value&gt;John&lt;/value&gt;&lt;/property&gt; *    &lt;property name=&quot;lastname&quot;&gt;&lt;value&gt;Doe&lt;/value&gt;&lt;/property&gt; *  &lt;/bean&gt; *                                                             *  &lt;bean id=&quot;info&quot; class=&quot;foo.PersonInfo&quot;&gt; *    &lt;property name=&quot;firstnameOfPerson&quot;&gt;&lt;value&gt;#{myPerson.firstname}&lt;/value&gt;&lt;/property&gt; *    &lt;property name=&quot;lastnameOfPerson&quot;&gt;&lt;value&gt;#{myPerson.lastname}&lt;/value&gt;&lt;/property&gt; *    &lt;property name=&quot;hasPersonSecondname&quot;&gt;&lt;value&gt;#{myPerson.secondname != null}&lt;/value&gt;&lt;/property&gt; *  &lt;/bean&gt; * </pre> *  * <p> * ValueBindingResolvingPropertyConfigurer checks simple property values, lists, * maps, and props. * </p> *  * @author Andreas Kuhrwahl */public final class ValueBindingResolvingPropertyConfigurer implements        BeanNameAware, BeanFactoryAware, BeanFactoryPostProcessor, Ordered {    /** The order of this {@link BeanFactoryPostProcessor}. */    private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 1;    /**     * Visitor class for traversing BeanDefinition objects and the     * MutablePropertyValues and ConstructorArgumentValues contained in them to     * resolve value bindings.     *      * @author Andreas Kuhrwahl     *      */    private class ValueBindingResolvingBeanDefinitionVisitor extends            BeanDefinitionVisitor {        /**         * {@inheritDoc}         */        protected String resolveStringValue(final String strVal) {            return strVal;        }        /**         * {@inheritDoc}         */        protected Object resolveValue(final Object value) {            Object resolvedValue = null;            if (value instanceof TypedStringValue                    && FacesUtils.isValueReference(((TypedStringValue) value)                            .getValue())) {                resolvedValue = createELResolverFactoryBeanDefinition(((TypedStringValue) value)                        .getValue());            } else if (value instanceof String                    && FacesUtils.isValueReference((String) value)) {                resolvedValue = createELResolverFactoryBeanDefinition((String) value);            } else {                resolvedValue = super.resolveValue(value);            }            return resolvedValue;        }        /**         * Creates {@link BeanDefinition} for {@link ELResolverFactoryBean}.         *          * @param expression         *            the expression         * @return the {@link BeanDefinition}         */        private BeanDefinition createELResolverFactoryBeanDefinition(                final String expression) {            RootBeanDefinition elResolverFactoryBean = new RootBeanDefinition(                    ELResolverFactoryBean.class);            ConstructorArgumentValues cav = new ConstructorArgumentValues();            cav.addGenericArgumentValue(expression);            elResolverFactoryBean.setConstructorArgumentValues(cav);            return elResolverFactoryBean;        }    }    /** The name of this configurer. */    private String beanName;    /** The owning factory to this bean instance. */    private BeanFactory beanFactory;    /**     * {@inheritDoc}     */    public void setBeanName(final String name) {        this.beanName = name;    }    /**     * {@inheritDoc}     */    public void setBeanFactory(final BeanFactory beanFactory) {        this.beanFactory = beanFactory;    }    /**     * {@inheritDoc}     */    public void postProcessBeanFactory(            final ConfigurableListableBeanFactory beanFactoryToProcess) {        BeanDefinitionVisitor visitor = new ValueBindingResolvingBeanDefinitionVisitor();        String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();        for (int i = 0; i < beanNames.length; i++) {            if (!(beanNames[i].equals(this.beanName) && beanFactoryToProcess                    .equals(this.beanFactory))) {                BeanDefinition bd = beanFactoryToProcess                        .getBeanDefinition(beanNames[i]);                try {                    visitor.visitBeanDefinition(bd);                } catch (BeanDefinitionStoreException ex) {                    throw new BeanDefinitionStoreException(bd                            .getResourceDescription(), beanNames[i], ex                            .getMessage());                }            }        }    }    /**     * {@inheritDoc}     */    public int getOrder() {        return ORDER;    }}

⌨️ 快捷键说明

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