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

📄 scopeadjuster.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.core.Ordered;/** * Adjusts the scope attribute that means * {@link ManagedBeanFactory#SCOPE_APPLICATION} is treated like a singleton and * {@link ManagedBeanFactory#SCOPE_NONE} is treated like a prototype. *  * @author Andreas Kuhrwahl */public final class ScopeAdjuster implements BeanNameAware, BeanFactoryAware,        BeanFactoryPostProcessor, Ordered {    /** The order of this {@link BeanFactoryPostProcessor}. */    private static final int ORDER = Ordered.HIGHEST_PRECEDENCE;    /**     * Visitor class for traversing BeanDefinition objects and the     * MutablePropertyValues and ConstructorArgumentValues contained in them to     * resolve the approbiate scopes.     *      * @author Andreas Kuhrwahl     *      */    private class ScopeAdjusterBeanDefinitionVisitor extends            BeanDefinitionVisitor {        /**         * {@inheritDoc}         */        protected String resolveStringValue(final String strVal) {            return strVal;        }        /**         * {@inheritDoc}         */        protected void visitScope(final BeanDefinition beanDefinition) {            String scope = beanDefinition.getScope();            if (ManagedBeanFactory.SCOPE_APPLICATION.equals(scope)) {                beanDefinition.setScope(ManagedBeanFactory.SCOPE_SINGLETON);            } else if (ManagedBeanFactory.SCOPE_NONE.equals(scope)) {                beanDefinition.setScope(ManagedBeanFactory.SCOPE_PROTOTYPE);            } else {                super.visitScope(beanDefinition);            }        }    }    /** 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 ScopeAdjusterBeanDefinitionVisitor();        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 + -