Example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory getType

List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getType

Introduction

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

Prototype

@Nullable
Class<?> getType(String name) throws NoSuchBeanDefinitionException;

Source Link

Document

Determine the type of the bean with the given name.

Usage

From source file:org.springframework.beans.factory.config.DeprecatedBeanWarner.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (isLogEnabled()) {
        String[] beanNames = beanFactory.getBeanDefinitionNames();
        for (String beanName : beanNames) {
            String nameToLookup = beanName;
            if (beanFactory.isFactoryBean(beanName)) {
                nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
            }/*w w w  . ja  v a 2 s.  com*/
            Class<?> beanType = beanFactory.getType(nameToLookup);
            if (beanType != null) {
                Class<?> userClass = ClassUtils.getUserClass(beanType);
                if (userClass.isAnnotationPresent(Deprecated.class)) {
                    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
                    logDeprecatedBean(beanName, beanType, beanDefinition);
                }
            }
        }
    }
}

From source file:org.springframework.flex.config.RemotingAnnotationPostProcessor.java

/**
 * Helper that searches the BeanFactory for beans annotated with @RemotingDestination, being careful not to force
 * eager creation of the beans if it can be avoided.
 * //from ww w .j  av a 2  s . c  o  m
 * @param beanFactory the BeanFactory to search
 * @return a set of collected RemotingDestinationMetadata
 */
private Set<RemotingDestinationMetadata> findRemotingDestinations(ConfigurableListableBeanFactory beanFactory) {
    Set<RemotingDestinationMetadata> remotingDestinations = new HashSet<RemotingDestinationMetadata>();
    Set<String> beanNames = new HashSet<String>();
    beanNames.addAll(Arrays.asList(beanFactory.getBeanDefinitionNames()));
    if (beanFactory.getParentBeanFactory() instanceof ListableBeanFactory) {
        beanNames.addAll(Arrays
                .asList(((ListableBeanFactory) beanFactory.getParentBeanFactory()).getBeanDefinitionNames()));
    }
    for (String beanName : beanNames) {
        if (beanName.startsWith("scopedTarget.")) {
            continue;
        }
        RemotingDestination remotingDestination = null;
        BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
        if (bd.isAbstract() || bd.isLazyInit()) {
            continue;
        }
        if (bd instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
            if (abd.hasBeanClass()) {
                Class<?> beanClass = abd.getBeanClass();
                remotingDestination = AnnotationUtils.findAnnotation(beanClass, RemotingDestination.class);
                if (remotingDestination != null) {
                    remotingDestinations
                            .add(new RemotingDestinationMetadata(remotingDestination, beanName, beanClass));
                    continue;
                }
            }
        }
        Class<?> handlerType = beanFactory.getType(beanName);
        if (handlerType != null) {
            remotingDestination = AnnotationUtils.findAnnotation(handlerType, RemotingDestination.class);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Could not get type of bean '" + beanName + "' from bean factory.");
            }
        }
        if (remotingDestination != null) {
            remotingDestinations
                    .add(new RemotingDestinationMetadata(remotingDestination, beanName, handlerType));
        }
    }
    return remotingDestinations;
}

From source file:org.springframework.integration.flow.config.FlowUtils.java

private static void _getReferencedMessageChannels(ConfigurableListableBeanFactory beanFactory, String[] beans,
        Set<String> messageChannels) {

    for (String bean : beans) {
        if (!bean.startsWith("(inner bean)") && !bean.equals("nullChannel")) {
            Class<?> clazz = null;
            if (beanFactory.containsBean(bean)) {
                clazz = beanFactory.getType(bean);
            }/*  ww  w  . j  av a  2s . c  o  m*/

            if (clazz != null) {
                if (MessageChannel.class.isAssignableFrom(clazz)) {
                    messageChannels.add(bean);
                }
                String[] dependencies = beanFactory.getDependenciesForBean(bean);
                if (dependencies.length > 0) {
                    _getReferencedMessageChannels(beanFactory, dependencies, messageChannels);
                }
            }
        }
    }
}