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

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

Introduction

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

Prototype

String[] getBeanNamesForType(ResolvableType type);

Source Link

Document

Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:com.gzj.tulip.jade.context.spring.JadeBeanFactoryPostProcessor.java

public String getStatementWrapperProvider(ConfigurableListableBeanFactory beanFactory) {
    if (statmentWrapperProviderName == null) {
        String[] names = beanFactory.getBeanNamesForType(StatementWrapperProvider.class);
        if (names.length == 0) {
            statmentWrapperProviderName = "none";
        } else if (names.length == 1) {
            statmentWrapperProviderName = names[0];
        } else {//from w ww .ja  v a2 s.  co m
            String topPriority = "jade.statmentWrapperProvider";
            if (ArrayUtils.contains(names, topPriority)) {
                statmentWrapperProviderName = topPriority;
            } else {
                throw new IllegalStateException(
                        "required not more than 1 StatmentWrapperProvider, but found " + names.length);
            }
        }
    }
    return "none".equals(statmentWrapperProviderName) ? null : statmentWrapperProviderName;
}

From source file:org.jnap.core.persistence.factory.DaoFactory.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    Assert.isAssignable(DefaultListableBeanFactory.class, beanFactory.getClass(),
            "The DaoFactory only works within a DefaultListableBeanFactory capable "
                    + "BeanFactory. Your BeanFactory is " + beanFactory.getClass());
    this.beanFactory = beanFactory;
    final DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) beanFactory;

    String[] factoryNames = beanFactory.getBeanNamesForType(EntityManagerFactory.class);
    Set<EntityManagerFactory> factories = new HashSet<EntityManagerFactory>(factoryNames.length);
    for (String factoryName : factoryNames) {
        factories.add(beanFactory.getBean(factoryName, EntityManagerFactory.class));
    }//from   w  ww .j  a  v  a2  s  .  com

    for (EntityManagerFactory factory : factories) {
        factory.getMetamodel().getEntities();
        for (EntityType<?> entityMetadata : factory.getMetamodel().getEntities()) {
            Class<? extends PersistentModel> entityClass = (Class<? extends PersistentModel>) entityMetadata
                    .getJavaType();
            if (entityClass != null && !isDaoDefinedForEntity(beanFactory, entityClass)) {
                String daoName = buildDaoName(entityClass);
                listableBeanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, factory));
                daoNameCache.put(entityClass, daoName);
            }
        }
    }

    factories.clear();
    factories = null;
}

From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java

public void initZookeeperAddressIfNecessary(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        if (com.alibaba.dubbo.config.RegistryConfig.class.getName().equals(beanDef.getBeanClassName())) {
            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue protpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_PROTOCOL);
            PropertyValue addrpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_ADDRESS);

            String protocol = null;
            String address = null;
            if (addrpv == null) {
                throw new FatalBeanException("zookeeper address cannot be null!"); // should never happen
            } else if (protpv == null) {
                String value = String.valueOf(addrpv.getValue());
                try {
                    URL url = new URL(null, value, this);
                    protocol = url.getProtocol();
                    address = url.getAuthority();
                } catch (Exception ex) {
                    throw new FatalBeanException("Unsupported format!");
                }// w w  w  .j a  v  a2s .c  om
            } else {
                protocol = String.valueOf(protpv.getValue());
                String value = StringUtils.trimToEmpty(String.valueOf(addrpv.getValue()));
                int index = value.indexOf(protocol);
                if (index == -1) {
                    address = value;
                } else if (index == 0) {
                    String str = StringUtils.trimToEmpty(value.substring(protocol.length()));
                    if (str.startsWith("://")) {
                        address = StringUtils.trimToEmpty(str.substring(3));
                    } else {
                        throw new FatalBeanException("Unsupported format!");
                    }
                } else {
                    throw new FatalBeanException("Unsupported format!");
                }
            }

            if (KEY_DUBBO_REGISTRY_ZOOKEEPER.equalsIgnoreCase(protocol) == false) {
                throw new FatalBeanException("Unsupported protocol!");
            }

            String addrKey = "zookeeperAddr";
            String[] watcherBeanArray = beanFactory
                    .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class);
            BeanDefinition watcherBeanDef = beanFactory.getBeanDefinition(watcherBeanArray[0]);
            MutablePropertyValues warcherMpv = watcherBeanDef.getPropertyValues();
            PropertyValue warcherPv = warcherMpv.getPropertyValue(addrKey);
            if (warcherPv == null) {
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            } else {
                warcherMpv.removePropertyValue(addrKey);
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            }

        }
    }
}

From source file:org.bytesoft.bytetcc.supports.dubbo.CompensableCoordinatorProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

    String application = null;/* w  w  w . java 2  s .co  m*/
    String[] appBeanNameArray = beanFactory.getBeanNamesForType(ApplicationConfig.class);
    if (appBeanNameArray != null && appBeanNameArray.length == 1) {
        String beanName = appBeanNameArray[0];
        BeanDefinition beanDef = registry.getBeanDefinition(beanName);
        MutablePropertyValues values = beanDef.getPropertyValues();
        String propertyName = "name";
        PropertyValue pv = values.getPropertyValue(propertyName);
        application = pv == null ? null : (String) pv.getValue();
    }

    if (StringUtils.isBlank(application)) {
        throw new FatalBeanException(
                "There is no application name specified, or there is more than one application name!");
    }

    String[] coordinatorNameArray = beanFactory.getBeanNamesForType(TransactionCoordinator.class);
    if (coordinatorNameArray != null && coordinatorNameArray.length == 1) {
        String beanName = coordinatorNameArray[0];

        GenericBeanDefinition beanDef = new GenericBeanDefinition();
        beanDef.setBeanClass(com.alibaba.dubbo.config.spring.ServiceBean.class);
        MutablePropertyValues values = beanDef.getPropertyValues();
        values.addPropertyValue("group", application);
        values.addPropertyValue("interface", TransactionCoordinator.class.getName());
        values.addPropertyValue("ref", new RuntimeBeanReference(beanName));
        values.addPropertyValue("retries", "0");
        values.addPropertyValue("timeout", String.valueOf(1000L * 6));
        registry.registerBeanDefinition(String.format("%s@%s", beanName, application), beanDef);
    } else {
        throw new FatalBeanException("No available(or redundant) org.bytesoft.bytetcc.TransactionCoordinator!");
    }

}

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

public static void displayBeansGraph(ConfigurableListableBeanFactory beanFactory) {
    String[] beans = beanFactory.getBeanNamesForType(Object.class);
    _displayDependencies(beanFactory, beans, 0);
}

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

public static Set<String> getReferencedMessageChannels(ConfigurableListableBeanFactory beanFactory) {
    String[] beans = beanFactory.getBeanNamesForType(Object.class);
    Set<String> messageChannels = new HashSet<String>();
    _getReferencedMessageChannels(beanFactory, beans, messageChannels);
    return Collections.unmodifiableSet(messageChannels);
}