Search in sources :

Example 1 with AbstractBeanFactoryTargetSource

use of cn.taketoday.aop.target.AbstractBeanFactoryTargetSource in project today-framework by TAKETODAY.

the class AbstractBeanFactoryTargetSourceCreator method getTargetSource.

// ---------------------------------------------------------------------
// Implementation of the TargetSourceCreator interface
// ---------------------------------------------------------------------
@Override
@Nullable
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
    AbstractBeanFactoryTargetSource targetSource = createBeanFactoryTargetSource(beanClass, beanName);
    if (targetSource == null) {
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("Configuring AbstractBeanFactoryBasedTargetSource: {}", targetSource);
    }
    StandardBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);
    // We need to override just this bean definition, as it may reference other beans
    // and we're happy to take the parent's definition for those.
    // Always use prototype scope if demanded.
    BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
    GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
    if (isPrototypeBased()) {
        bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    }
    internalBeanFactory.registerBeanDefinition(beanName, bdCopy);
    // Complete configuring the PrototypeTargetSource.
    targetSource.setTargetBeanName(beanName);
    targetSource.setBeanFactory(internalBeanFactory);
    return targetSource;
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) AbstractBeanFactoryTargetSource(cn.taketoday.aop.target.AbstractBeanFactoryTargetSource) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) Nullable(cn.taketoday.lang.Nullable)

Example 2 with AbstractBeanFactoryTargetSource

use of cn.taketoday.aop.target.AbstractBeanFactoryTargetSource in project today-infrastructure by TAKETODAY.

the class AbstractBeanFactoryTargetSourceCreator method getTargetSource.

// ---------------------------------------------------------------------
// Implementation of the TargetSourceCreator interface
// ---------------------------------------------------------------------
@Override
@Nullable
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
    AbstractBeanFactoryTargetSource targetSource = createBeanFactoryTargetSource(beanClass, beanName);
    if (targetSource == null) {
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("Configuring AbstractBeanFactoryBasedTargetSource: {}", targetSource);
    }
    StandardBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);
    // We need to override just this bean definition, as it may reference other beans
    // and we're happy to take the parent's definition for those.
    // Always use prototype scope if demanded.
    BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
    GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
    if (isPrototypeBased()) {
        bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    }
    internalBeanFactory.registerBeanDefinition(beanName, bdCopy);
    // Complete configuring the PrototypeTargetSource.
    targetSource.setTargetBeanName(beanName);
    targetSource.setBeanFactory(internalBeanFactory);
    return targetSource;
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) AbstractBeanFactoryTargetSource(cn.taketoday.aop.target.AbstractBeanFactoryTargetSource) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) Nullable(cn.taketoday.lang.Nullable)

Aggregations

AbstractBeanFactoryTargetSource (cn.taketoday.aop.target.AbstractBeanFactoryTargetSource)2 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)2 GenericBeanDefinition (cn.taketoday.beans.factory.support.GenericBeanDefinition)2 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 Nullable (cn.taketoday.lang.Nullable)2