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

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

Introduction

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

Prototype

ScopeMetadata

Source Link

Usage

From source file:kzht.gm.springframework.extension.context.PrototypeScopeMetadataResolver.java

@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Default scope will be prototype.");
    }/*from www .  jav  a  2  s  .  co m*/

    ScopeMetadata metadata = new ScopeMetadata();
    metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
    return metadata;
}

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

/**
 * Discover spring scope using bean definition.
 *
 * @param definition bean definition//from   ww w  . j  a v  a 2  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;
}

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

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;
        }//w  w w.j av  a  2s. c  om
    }
    return requestScopeAsDefault();
}

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

private ScopeMetadata requestScopeAsDefault() {
    ScopeMetadata singleton = new ScopeMetadata();
    singleton.setScopeName(WebApplicationContext.SCOPE_REQUEST);
    return singleton;
}

From source file:net.wessendorf.spring.scopes.CdiScopeMetadataResolver.java

/**
 * Checks if one of the following CDI scope annoations are used and maps
 * them to their matching Spring scopes:
 * /*from   w ww  .  j  av a  2  s  .c  o m*/
 * <ul>
 * <li><code>&#064;javax.enterprise.context.RequestScoped</code></li>
 * <li><code>&#064;javax.enterprise.context.SessionScoped</code></li>
 * <li><code>&#064;javax.enterprise.context.ApplicationScoped</code></li>
 * </ul>
 * 
 * If none of them are found it delegates back to the original Spring
 * <code>AnnotationScopeMetadataResolver</code> class. 
 */
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
    ScopeMetadata metadata = new ScopeMetadata();
    if (definition instanceof AnnotatedBeanDefinition) {
        AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
        Set<String> annotationTypes = annDef.getMetadata().getAnnotationTypes();

        if (annotationTypes.contains(RequestScoped.class.getName())) {
            metadata.setScopeName(WebApplicationContext.SCOPE_REQUEST);
        } else if (annotationTypes.contains(SessionScoped.class.getName())) {
            metadata.setScopeName(WebApplicationContext.SCOPE_SESSION);
        } else if (annotationTypes.contains(ApplicationScoped.class.getName())) {
            metadata.setScopeName(WebApplicationContext.SCOPE_APPLICATION);
        } else {
            // do the regular Spring stuff..
            return super.resolveScopeMetadata(definition);
        }
    }
    return metadata;
}

From source file:org.apache.click.extras.spring.PageScopeResolver.java

/**
 * Return the scope meta data for the given bean definition. This scope meta
 * data resolver will resolve "prototype" scope for any Click Page bean
 * and will resolve "singleton" scope for other beans.
 *
 * @see ScopeMetadataResolver#resolveScopeMetadata(BeanDefinition)
 *
 * @param beanDef the component bean definition to resolve
 * @return the scope meta data for the given bean definition.
 *//*  w  ww  .j  a v a 2s.c o m*/
public ScopeMetadata resolveScopeMetadata(BeanDefinition beanDef) {
    ScopeMetadata sm = new ScopeMetadata();

    try {
        Class<?> beanClass = ClickUtils.classForName(beanDef.getBeanClassName());

        if (Page.class.isAssignableFrom(beanClass)) {
            sm.setScopeName(ConfigurableBeanFactory.SCOPE_PROTOTYPE);

        } else {
            // TODO: see whether we can determine the default scope definition
            // from the beanDef and return this instead.
            sm.setScopeName(ConfigurableBeanFactory.SCOPE_SINGLETON);
        }

        return sm;

    } catch (Exception e) {
        String msg = "Could not load class for beanDef: " + beanDef;
        throw new RuntimeException(msg, e);
    }
}