Example usage for org.springframework.context.annotation ScopeMetadata getScopeName

List of usage examples for org.springframework.context.annotation ScopeMetadata getScopeName

Introduction

In this page you can find the example usage for org.springframework.context.annotation ScopeMetadata getScopeName.

Prototype

public String getScopeName() 

Source Link

Document

Get the name of the scope.

Usage

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

public void testViewScope() {
    AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(ViewScopedClass.class);
    AnnotatedBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(annotationMetadata);
    AnnotationScopeMetadataResolver annotationScopeMetadataResolver = new JsfCdiToSpringScopeMetadataResolver();

    ScopeMetadata scopeMetadata = annotationScopeMetadataResolver.resolveScopeMetadata(beanDefinition);

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

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

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

    ScopeMetadata scopeMetadata = annotationScopeMetadataResolver.resolveScopeMetadata(beanDefinition);

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

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

public void testNoScope() {
    AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(NoScopedClass.class);
    AnnotatedBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(annotationMetadata);
    AnnotationScopeMetadataResolver annotationScopeMetadataResolver = new JsfCdiToSpringScopeMetadataResolver();

    ScopeMetadata scopeMetadata = annotationScopeMetadataResolver.resolveScopeMetadata(beanDefinition);

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

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:br.com.caelum.vraptor.ioc.spring.SpringRegistry.java

/**
 * From org.springframework.context.annotation.ClassPathBeanDefinitionScanner#applyScope()
 * @param definition/*from   w  w  w  .j a v  a2 s .  c o m*/
 * @param scopeMetadata
 *
 * @return
 */
private BeanDefinitionHolder applyScopeOn(BeanDefinitionHolder definition, ScopeMetadata scopeMetadata) {
    String scope = scopeMetadata.getScopeName();
    ScopedProxyMode proxyMode = scopeMetadata.getScopedProxyMode();
    definition.getBeanDefinition().setScope(scope);
    if (BeanDefinition.SCOPE_SINGLETON.equals(scope) || BeanDefinition.SCOPE_PROTOTYPE.equals(scope)
            || proxyMode.equals(ScopedProxyMode.NO)) {
        return definition;
    } else {
        boolean proxyTargetClass = proxyMode.equals(ScopedProxyMode.TARGET_CLASS);
        return ScopedProxyUtils.createScopedProxy(definition, (BeanDefinitionRegistry) beanFactory,
                proxyTargetClass);
    }
}

From source file:br.com.caelum.vraptor.ioc.spring.VRaptorScopeResolverTest.java

@Test
public void shouldResolveToRequestScopeByDefault() {
    ScopeMetadata scopeMetadata = readScopeMetadata(DummyComponent.class);
    Assert.assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
    Assert.assertEquals(WebApplicationContext.SCOPE_REQUEST, scopeMetadata.getScopeName());
}

From source file:br.com.caelum.vraptor.ioc.spring.VRaptorScopeResolverTest.java

@Test
public void shouldResolveApplicationScopedAnnotationToSingletonScope() {
    ScopeMetadata scopeMetadata = readScopeMetadata(ApplicationScopedComponent.class);
    Assert.assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
    Assert.assertEquals(BeanDefinition.SCOPE_SINGLETON, scopeMetadata.getScopeName());
}

From source file:br.com.caelum.vraptor.ioc.spring.VRaptorScopeResolverTest.java

@Test
public void shouldResolveRequestScopedAnnotationToRequestScope() {
    ScopeMetadata scopeMetadata = readScopeMetadata(RequestScopedComponent.class);
    Assert.assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
    Assert.assertEquals(WebApplicationContext.SCOPE_REQUEST, scopeMetadata.getScopeName());
}

From source file:br.com.caelum.vraptor.ioc.spring.VRaptorScopeResolverTest.java

@Test
public void shouldResolveSessionScopedAnnotationToSessionScope() {
    ScopeMetadata scopeMetadata = readScopeMetadata(SessionScopedComponent.class);
    Assert.assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
    Assert.assertEquals(WebApplicationContext.SCOPE_SESSION, scopeMetadata.getScopeName());
}

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

/**
 * Discover spring scope using bean definition.
 *
 * @param definition bean definition/*  w w w . jav a2  s  . c o  m*/
 * @return scope metadata
 */
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
    ScopeMetadata metadata = new ScopeMetadata();
    if (definition instanceof AnnotatedBeanDefinition) {
        AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;

        String scopeName = JsfCdiToSpring.scopeName(annDef.getMetadata().getAnnotationTypes());
        if (scopeName != null) {
            metadata.setScopeName(scopeName);

            logger.debug(definition.getBeanClassName() + " - Scope(" + metadata.getScopeName().toUpperCase()
                    + ") - " + metadata.getScopedProxyMode().toString().toUpperCase());
        } else {
            // do the regular Spring stuff..
            metadata = super.resolveScopeMetadata(definition);
        }
    }

    return metadata;
}