Example usage for org.springframework.beans.factory.config BeanDefinition getRole

List of usage examples for org.springframework.beans.factory.config BeanDefinition getRole

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config BeanDefinition getRole.

Prototype

int getRole();

Source Link

Document

Get the role hint for this BeanDefinition .

Usage

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

private boolean hasGreaterRoleThanInfrastructure(BeanDefinition definition) {
    return definition.getRole() < BeanDefinition.ROLE_INFRASTRUCTURE;
}

From source file:org.spring.guice.module.SpringModule.java

@Override
public void configure(Binder binder) {
    for (String name : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(name);
        if (definition.isAutowireCandidate()
                && definition.getRole() == AbstractBeanDefinition.ROLE_APPLICATION) {
            Class<?> type = beanFactory.getType(name);
            @SuppressWarnings("unchecked")
            final Class<Object> cls = (Class<Object>) type;
            final String beanName = name;
            Provider<Object> provider = new BeanFactoryProvider(beanFactory, beanName, type);
            if (!cls.isInterface() && !ClassUtils.isCglibProxyClass(cls)) {
                bindConditionally(binder, name, cls, provider);
            }//from w ww .ja  va  2s.  c  om
            for (Class<?> iface : ClassUtils.getAllInterfacesForClass(cls)) {
                @SuppressWarnings("unchecked")
                Class<Object> unchecked = (Class<Object>) iface;
                bindConditionally(binder, name, unchecked, provider);
            }
        }
    }
}

From source file:org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.java

protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String beanName) {
    if (!this.registry.containsBeanDefinition(beanName)) {
        return false;
    }/*from  www  .j  a v  a2 s  . c o  m*/
    BeanDefinition existingBeanDef = this.registry.getBeanDefinition(beanName);

    // Is the existing bean definition one that was created from a configuration class?
    // -> allow the current bean method to override, since both are at second-pass level.
    // However, if the bean method is an overloaded case on the same configuration class,
    // preserve the existing bean definition.
    if (existingBeanDef instanceof ConfigurationClassBeanDefinition) {
        ConfigurationClassBeanDefinition ccbd = (ConfigurationClassBeanDefinition) existingBeanDef;
        return ccbd.getMetadata().getClassName()
                .equals(beanMethod.getConfigurationClass().getMetadata().getClassName());
    }

    // A bean definition resulting from a component scan can be silently overridden
    // by an @Bean method, as of 4.2...
    if (existingBeanDef instanceof ScannedGenericBeanDefinition) {
        return false;
    }

    // Has the existing bean definition bean marked as a framework-generated bean?
    // -> allow the current bean method to override it, since it is application-level
    if (existingBeanDef.getRole() > BeanDefinition.ROLE_APPLICATION) {
        return false;
    }

    // At this point, it's a top-level override (probably XML), just having been parsed
    // before configuration class processing kicks in...
    if (this.registry instanceof DefaultListableBeanFactory
            && !((DefaultListableBeanFactory) this.registry).isAllowBeanDefinitionOverriding()) {
        throw new BeanDefinitionStoreException(
                beanMethod.getConfigurationClass().getResource().getDescription(), beanName,
                "@Bean definition illegally overridden by existing bean definition: " + existingBeanDef);
    }
    if (logger.isInfoEnabled()) {
        logger.info(String.format(
                "Skipping bean definition for %s: a definition for bean '%s' "
                        + "already exists. This top-level bean definition is considered as an override.",
                beanMethod, beanName));
    }
    return true;
}