📄 managedbeanfactory.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.BeanFactory;import org.springframework.beans.factory.ObjectFactory;import org.springframework.beans.factory.config.Scope;import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;import org.springframework.beans.factory.support.DefaultListableBeanFactory;import org.springframework.beans.factory.support.InstantiationStrategy;import org.springframework.beans.factory.support.RootBeanDefinition;/** * Default implementation of the ConfigurableBeanFactory interfaces: a * full-fledged bean factory based on bean definitions. * * <p> * This factory based on different types of bean definitions. In addition to the * default types of bean definitions this factory is able to handle * {@link ManagedBeanDefinition}s. * </p> * * <p> * <i>Based on * {@link org.springframework.beans.factory.support.DefaultListableBeanFactory}</i> * </p> * * @author Andreas Kuhrwahl */public class ManagedBeanFactory extends DefaultListableBeanFactory { // TODO: Hack! Warten auf Spring bugfix /** The dafault instantioation strategy. */ private InstantiationStrategy defaultInstantiationStrategy; /** * Scope identifier for application scope: "application". Similar to * standard scope "singleton". */ public static final String SCOPE_APPLICATION = "application"; /** * Scope identifier for none scope: "none". Similar to standard scope * "prototype". */ public static final String SCOPE_NONE = "none"; /** * Implements the {@link ManagedBeanDefinition} interface based on a * {@link RootBeanDefinition}. * * @author Andreas Kuhrwahl * */ private static class ManagedBeanDefinitionImpl extends RootBeanDefinition implements ManagedBeanDefinition { /** */ private static final long serialVersionUID = -8025205801094156475L; /** * Creates an instance based upon the given {@link RootBeanDefinition}. * * @param original * The {@link RootBeanDefinition} */ public ManagedBeanDefinitionImpl(final RootBeanDefinition original) { super(original); } } /** * Creates a {@link ManagedBeanDefinition} based upon a * {@link RootBeanDefinition}. * * @param beanClassName * the name of the bean class, if any * @param beanClassLoader * the ClassLoader to use for loading bean classes * @return the bean definition * @throws ClassNotFoundException * if the bean class could not be loaded * @see ManagedBeanDefinition * @see RootBeanDefinition */ public static final RootBeanDefinition createManagedBeanDefinition( final String beanClassName, final ClassLoader beanClassLoader) throws ClassNotFoundException { RootBeanDefinition bd = (RootBeanDefinition) BeanDefinitionReaderUtils .createBeanDefinition(null, beanClassName, beanClassLoader); return new ManagedBeanDefinitionImpl(bd); } /** * Creates a new DefaultConfigurableBeanFactory. */ public ManagedBeanFactory() { super(); } /** * Creates a new DefaultConfigurableBeanFactory with the given parent. * * @param parentBeanFactory * the parent */ public ManagedBeanFactory(final BeanFactory parentBeanFactory) { super(parentBeanFactory); } /** * {@inheritDoc} */ protected final void addSingleton(final String beanName, final Object sharedBean) { Scope applicationScope = getRegisteredScope(SCOPE_APPLICATION); if (applicationScope != null) { synchronized (applicationScope) { super.addSingleton(beanName, applicationScope.get(beanName, new ObjectFactory() { public Object getObject() { return sharedBean; } })); } } } /** * {@inheritDoc} */ protected final void removeSingleton(final String beanName) { Scope applicationScope = getRegisteredScope(SCOPE_APPLICATION); if (applicationScope != null) { synchronized (applicationScope) { applicationScope.remove(beanName); } super.removeSingleton(beanName); } } /** * {@inheritDoc} */ public final void destroySingletons() { Scope applicationScope = getRegisteredScope(SCOPE_APPLICATION); if (applicationScope != null && applicationScope instanceof ApplicationScope) { synchronized (applicationScope) { ((ApplicationScope) applicationScope).clear(); } super.destroySingletons(); } } /** * {@inheritDoc} */ protected final InstantiationStrategy getInstantiationStrategy() { if (this.defaultInstantiationStrategy == null) { this.defaultInstantiationStrategy = new ValueBindingResolvingInstantiationStrategy(); } return this.defaultInstantiationStrategy; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -