Example usage for org.springframework.beans.factory.support GenericBeanDefinition GenericBeanDefinition

List of usage examples for org.springframework.beans.factory.support GenericBeanDefinition GenericBeanDefinition

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support GenericBeanDefinition GenericBeanDefinition.

Prototype

public GenericBeanDefinition(BeanDefinition original) 

Source Link

Document

Create a new GenericBeanDefinition as deep copy of the given bean definition.

Usage

From source file:com.github.persapiens.jsfboot.annotations.JsfCdiToSpringScopeMetadadaResolverIT.java

public void testGenericBeanDefinition() {
    AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(SessionScopedClass.class);
    AnnotatedBeanDefinition annotatedBeanDefinition = new AnnotatedGenericBeanDefinition(annotationMetadata);
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition(annotatedBeanDefinition);
    AnnotationScopeMetadataResolver annotationScopeMetadataResolver = new JsfCdiToSpringScopeMetadataResolver();

    ScopeMetadata scopeMetadata = annotationScopeMetadataResolver.resolveScopeMetadata(beanDefinition);

    assertThat(scopeMetadata.getScopeName()).isEqualTo(JsfCdiToSpring.SINGLETON);
}

From source file:com.github.persapiens.jsfboot.annotations.JsfCdiToSpringBeanNameGeneratorIT.java

public void testGenericBeanDefinition() {
    AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(SessionScopedClass.class);
    AnnotatedBeanDefinition annotatedBeanDefinition = new AnnotatedGenericBeanDefinition(annotationMetadata);
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition(annotatedBeanDefinition);

    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();

    AnnotationBeanNameGenerator annotationBeanNameGeneratorannotationScopeMetadataResolver = new JsfCdiToSpringBeanNameGenerator();

    annotationBeanNameGeneratorannotationScopeMetadataResolver.generateBeanName(beanDefinition, registry);

    assertThat(beanDefinition.getScope()).isEmpty();
}

From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java

/**
 * Create a bean definition for the scripted object, based on the given script
 * definition, extracting the definition data that is relevant for the scripted
 * object (that is, everything but bean class and constructor arguments).
 * @param bd the full script bean definition
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptSource the ScriptSource for the scripted bean
 * @param interfaces the interfaces that the scripted bean is supposed to implement
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory#getScriptedObject
 *//*from w w  w .j a  v a2  s .  com*/
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName,
        ScriptSource scriptSource, Class<?>[] interfaces) {

    GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
    objectBd.setFactoryBeanName(scriptFactoryBeanName);
    objectBd.setFactoryMethodName("getScriptedObject");
    objectBd.getConstructorArgumentValues().clear();
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
    return objectBd;
}

From source file:org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator.java

@Override
@Nullable//w  w  w  . ja  v a2s  .  c o  m
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
    AbstractBeanFactoryBasedTargetSource targetSource = createBeanFactoryBasedTargetSource(beanClass, beanName);
    if (targetSource == null) {
        return null;
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Configuring AbstractBeanFactoryBasedTargetSource: " + targetSource);
    }

    DefaultListableBeanFactory 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 = this.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;
}

From source file:org.springframework.scripting.support.ScriptFactoryPostProcessor.java

/**
 * Create a bean definition for the scripted object, based on the given script
 * definition, extracting the definition data that is relevant for the scripted
 * object (that is, everything but bean class and constructor arguments).
 * @param bd the full script bean definition
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptSource the ScriptSource for the scripted bean
 * @param interfaces the interfaces that the scripted bean is supposed to implement
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory#getScriptedObject
 *//*from  w w  w . j  a v  a  2 s.c  o m*/
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName,
        ScriptSource scriptSource, @Nullable Class<?>[] interfaces) {

    GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
    objectBd.setFactoryBeanName(scriptFactoryBeanName);
    objectBd.setFactoryMethodName("getScriptedObject");
    objectBd.getConstructorArgumentValues().clear();
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
    return objectBd;
}