Package org.springframework.context.annotation

Examples of org.springframework.context.annotation.ScopeMetadata


*/
public class VRaptorScopeResolverTest {

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


  Assert.assertEquals(WebApplicationContext.SCOPE_REQUEST, scopeMetadata.getScopeName());
  }

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

  Assert.assertEquals(WebApplicationContext.SCOPE_REQUEST, scopeMetadata.getScopeName());
  }

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

  Assert.assertEquals(WebApplicationContext.SCOPE_SESSION, scopeMetadata.getScopeName());
  }

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

    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
    scanner.setIncludeAnnotationConfig(false);
    scanner.setScopeMetadataResolver(new ScopeMetadataResolver() {
      @Override
      public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
        ScopeMetadata metadata = new ScopeMetadata();
        if (definition instanceof AnnotatedBeanDefinition) {
          AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
          for (String type : annDef.getMetadata().getAnnotationTypes()) {
            if (type.equals(javax.inject.Singleton.class.getName())) {
              metadata.setScopeName(BeanDefinition.SCOPE_SINGLETON);
              break;
            }
            else if (annDef.getMetadata().getMetaAnnotationTypes(type).contains(javax.inject.Scope.class.getName())) {
              metadata.setScopeName(type.substring(type.length() - 13, type.length() - 6).toLowerCase());
              metadata.setScopedProxyMode(scopedProxyMode);
              break;
            }
            else if (type.startsWith("javax.inject")) {
              metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
            }
          }
        }
        return metadata;
      }
View Full Code Here

  protected final Log logger = LogFactory.getLog(getClass());

  @Override
  public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
    ScopeMetadata scopeMetadata = resolveCdiScopes(definition);
    if (scopeMetadata == null)
      scopeMetadata = super.resolveScopeMetadata(definition);

    return scopeMetadata;
  }
View Full Code Here

    if (!(definition instanceof AnnotatedBeanDefinition))
      return null;

    AnnotatedBeanDefinition annotatedDefinition = (AnnotatedBeanDefinition) definition;
    AnnotationMetadata metadata = annotatedDefinition.getMetadata();
    ScopeMetadata scopeMetadata = null;

    if (metadata.isAnnotated(APPLICATION_SCOPED))
      scopeMetadata = createScopeMetadata("singleton");
    else if (metadata.isAnnotated(SESSION_SCOPED))
      scopeMetadata = createScopeMetadata("session");
View Full Code Here

        annotation.annotationType());
    return metadata.hasAnnotation(SCOPE_PROXY);
  }

  protected ScopeMetadata createScopeMetadata(String forScope) {
    ScopeMetadata scopeMetadata = new ScopeMetadata();
    scopeMetadata.setScopeName(forScope);

    return scopeMetadata;
  }
View Full Code Here

* Use this for annotation-based command scanners where you always want the commands to be prototypes.
*/
public class AlwaysPrototypeScopeResolver implements ScopeMetadataResolver {
    @Override
    public ScopeMetadata resolveScopeMetadata(BeanDefinition beanDefinition) {
        ScopeMetadata meta = new ScopeMetadata();
        meta.setScopedProxyMode(ScopedProxyMode.NO);
        meta.setScopeName("prototype");
        return meta;
    }
View Full Code Here

    public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
        AnnotationMetadata metadata = ((AnnotatedBeanDefinition) definition).getMetadata();
        for (Map.Entry<String, String> scope : scopes.entrySet()) {
            if (metadata.hasAnnotation(scope.getKey())) {
                ScopeMetadata scopeMetadata = new ScopeMetadata();
                scopeMetadata.setScopeName(scope.getValue());
                return scopeMetadata;
            }
        }
        return requestScopeAsDefault();
    }
View Full Code Here

TOP

Related Classes of org.springframework.context.annotation.ScopeMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.