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

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

Introduction

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

Prototype

String[] getBeanDefinitionNames();

Source Link

Document

Return the names of all beans defined in this factory.

Usage

From source file:com.jaspersoft.jasperserver.api.common.util.spring.BeanReferenceOverrider.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanDefinitionNames.length; i++) {
        String beanName = beanDefinitionNames[i];
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
        process(beanDefinition, beanName);
    }// ww w  .  ja va  2 s  . c  o m
}

From source file:py.una.pol.karaku.services.server.ServiceDefinitionRegister.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) {

    LOG.info("Registering @WebServices");
    String[] beans = bf.getBeanDefinitionNames();
    for (String s : beans) {
        Class<?> beanType = bf.getType(s);
        WebServiceDefinition ws = AnnotationUtils.findAnnotation(beanType, WebServiceDefinition.class);
        if (ws != null) {
            String name = getName(s);
            DefaultWsdl11Definition newWS = createWebService(name, ws.xsds());

            bf.registerSingleton(name, newWS);
            LOG.info("Web service: {} has been added", name);
        }//from w  w  w  .  j  ava  2 s  .c om
    }

}

From source file:org.joinfaces.annotations.JsfCdiToSpringBeanFactoryPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory clbf) throws BeansException {
    clbf.registerScope("view", new ViewScope());

    for (String beanName : clbf.getBeanDefinitionNames()) {
        BeanDefinition definition = clbf.getBeanDefinition(beanName);
        registerJsfCdiToSpring(definition);
    }/*from w ww .j  a  v  a  2 s  .c  om*/
}

From source file:org.brekka.stillingar.spring.pc.ConfigurationPlaceholderConfigurer.java

/**
 * Copied in its entirety from the {@link PropertyPlaceholderConfigurer} method of the same name. The only changes
 * are to the valueResolver and BeanDefinitionVisitor instances.
 *///from ww  w . ja va  2  s  . co  m
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactoryToProcess) throws BeansException {

    String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
    for (String curName : beanNames) {
        CustomStringValueResolver valueResolver = new CustomStringValueResolver(this.placeholderParser,
                this.configurationSource, this.beanFactory);

        // Check that we're not parsing our own bean definition,
        // to avoid failing on unresolvable placeholders in properties file
        // locations.
        if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
            BeanDefinition beanDef = beanFactoryToProcess.getBeanDefinition(curName);
            try {
                BeanDefinitionVisitor visitor = new CustomBeanDefinitionVisitor(curName, beanDef.isSingleton(),
                        valueResolver);
                visitor.visitBeanDefinition(beanDef);
            } catch (Exception ex) {
                throw new BeanDefinitionStoreException(beanDef.getResourceDescription(), curName, ex);
            }
        }
    }

    StringValueResolver valueResolver = new CustomStringValueResolver(this.placeholderParser,
            this.configurationSource, this.beanFactory);

    // New in Spring 2.5: resolve placeholders in alias target names and
    // aliases as well.
    beanFactoryToProcess.resolveAliases(valueResolver);

    // New in Spring 3.0: resolve placeholders in embedded values such as
    // annotation attributes.
    beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);
}

From source file:org.synyx.hades.domain.auditing.support.AuditingBeanFactoryPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {

    if (!isSpringConfigured(beanFactory)) {
        return;//  w ww.  ja v  a2s. co  m
    }

    for (String beanName : beanFactory.getBeanDefinitionNames()) {

        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);

        if (CLASSES_TO_DEPEND.contains(definition.getBeanClassName())) {
            definition.setDependsOn(
                    StringUtils.addStringToArray(definition.getDependsOn(), BEAN_CONFIGURER_ASPECT_BEAN_NAME));
        }
    }

    for (String beanName : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, AuditorAware.class,
            true, false)) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        definition.setLazyInit(true);
    }
}

From source file:org.constretto.spring.ConfigurationAnnotationConfigurer.java

@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        final BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
        final Class<?> beanType = beanFactory.getType(beanName);
        if (!configurableConstructorCache.containsKey(beanType)) {
            configurableConstructorCache.put(beanType, resolveConfigurableConstructor(beanType));
        }/*  w  w  w.j a  va 2 s. co m*/
        final Constructor<?> resolvedConstructor = configurableConstructorCache.get(beanType);
        if (resolvedConstructor != null) {
            final ConstructorArgumentValues constructorArgumentValues = beanDefinition
                    .getConstructorArgumentValues();
            final ArgumentDescription[] argumentDescriptions = ArgumentDescriptionFactory
                    .create(resolvedConstructor).resolveParameters();
            for (int i = 0; i < argumentDescriptions.length; i++) {
                ArgumentDescription argumentDescription = argumentDescriptions[i];
                if (!constructorArgumentValues.hasIndexedArgumentValue(i)) {
                    final String keyName = argumentDescription.constrettoConfigurationKeyCandidate();
                    if (configuration.hasValue(keyName)) {
                        constructorArgumentValues.addIndexedArgumentValue(i,
                                configuration.evaluateTo(argumentDescription.getType(), keyName));
                    }
                }
            }
        }

    }
}

From source file:org.bytesoft.bytejta.supports.dubbo.TransactionConfigPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();

    String applicationBeanId = null;
    String registryBeanId = null;
    String transactionBeanId = null;

    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();
        if (com.alibaba.dubbo.config.ApplicationConfig.class.getName().equals(beanClassName)) {
            if (StringUtils.isBlank(applicationBeanId)) {
                applicationBeanId = beanName;
            } else {
                throw new FatalBeanException("There are more than one application name was found!");
            }/*from   w ww  .ja v  a 2  s.c o  m*/
        } else if (org.bytesoft.bytejta.TransactionCoordinator.class.getName().equals(beanClassName)) {
            if (StringUtils.isBlank(transactionBeanId)) {
                transactionBeanId = beanName;
            } else {
                throw new FatalBeanException(
                        "There are more than one org.bytesoft.bytejta.TransactionCoordinator was found!");
            }
        } else if (org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry.class.getName()
                .equals(beanClassName)) {
            if (StringUtils.isBlank(registryBeanId)) {
                registryBeanId = beanName;
            } else {
                throw new FatalBeanException(
                        "There are more than one org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry was found!");
            }
        }
    }

    if (StringUtils.isBlank(applicationBeanId)) {
        throw new FatalBeanException("No application name was found!");
    }

    BeanDefinition beanDef = beanFactory.getBeanDefinition(applicationBeanId);
    MutablePropertyValues mpv = beanDef.getPropertyValues();
    PropertyValue pv = mpv.getPropertyValue("name");

    if (pv == null || pv.getValue() == null || StringUtils.isBlank(String.valueOf(pv.getValue()))) {
        throw new FatalBeanException("No application name was found!");
    }

    if (StringUtils.isBlank(transactionBeanId)) {
        throw new FatalBeanException(
                "No configuration of class org.bytesoft.bytejta.TransactionCoordinator was found.");
    } else if (registryBeanId == null) {
        throw new FatalBeanException(
                "No configuration of class org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry was found.");
    }

    String application = String.valueOf(pv.getValue());
    this.initializeForProvider(beanFactory, application, transactionBeanId);
    this.initializeForConsumer(beanFactory, application, registryBeanId);
}

From source file:org.nuunframework.spring.SpringModule.java

@SuppressWarnings("unchecked")
private void bindFromApplicationContext() {
    boolean debugEnabled = logger.isDebugEnabled();

    ConfigurableListableBeanFactory currentBeanFactory = this.beanFactory;
    do {/*from   ww  w  . j  av  a  2 s.  co  m*/
        for (String beanName : currentBeanFactory.getBeanDefinitionNames()) {
            BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName);
            if (!beanDefinition.isAbstract()) {
                Class<?> beanClass = classFromString(beanDefinition.getBeanClassName());
                if (beanClass == null) {
                    logger.warn("Cannot bind spring bean " + beanName + " because its class "
                            + beanDefinition.getBeanClassName() + " failed to load");
                    return;
                }

                SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName,
                        currentBeanFactory);

                // Adding bean with its base type
                addBeanDefinition(beanClass, springBeanDefinition);

                // Adding bean with its parent type if enabled
                Class<?> parentClass = beanClass.getSuperclass();
                if (parentClass != null && parentClass != Object.class)
                    addBeanDefinition(parentClass, springBeanDefinition);

                // Adding bean with its immediate interfaces if enabled
                for (Class<?> i : beanClass.getInterfaces())
                    addBeanDefinition(i, springBeanDefinition);
            }
        }
        BeanFactory factory = currentBeanFactory.getParentBeanFactory();
        if (factory != null) {
            if (factory instanceof ConfigurableListableBeanFactory)
                currentBeanFactory = (ConfigurableListableBeanFactory) factory;
            else {
                logger.info(
                        "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory");
                currentBeanFactory = null;
            }
        } else
            currentBeanFactory = null;
    } while (currentBeanFactory != null);

    for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : this.beanDefinitions.entrySet()) {
        Class<?> type = entry.getKey();
        Map<String, SpringBeanDefinition> definitions = entry.getValue();

        // Bind by name for each bean of this type and by type if there is no ambiguity
        for (SpringBeanDefinition candidate : definitions.values()) {
            if (debugEnabled)
                logger.info("Binding spring bean " + candidate.getName() + " by name and type "
                        + type.getCanonicalName());

            bind(type).annotatedWith(Names.named(candidate.getName())).toProvider(
                    new ByNameSpringContextProvider(type, candidate.getName(), candidate.getBeanFactory()));
        }
    }
}

From source file:io.nuun.plugin.spring.SpringModule.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void bindFromApplicationContext() {
    boolean debugEnabled = logger.isDebugEnabled();

    ConfigurableListableBeanFactory currentBeanFactory = beanFactory;
    do {//  w  w w.  j a va2 s. co  m
        for (String beanName : currentBeanFactory.getBeanDefinitionNames()) {
            BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName);
            if (!beanDefinition.isAbstract()) {
                Class<?> beanClass = classFromString(beanDefinition.getBeanClassName());
                if (beanClass == null) {
                    logger.warn("Cannot bind spring bean " + beanName + " because its class "
                            + beanDefinition.getBeanClassName() + " failed to load");
                    return;
                }

                SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName,
                        currentBeanFactory);

                // Adding bean with its base type
                addBeanDefinition(beanClass, springBeanDefinition);

                // Adding bean with its parent type if enabled
                Class<?> parentClass = beanClass.getSuperclass();
                if (parentClass != null && parentClass != Object.class) {
                    addBeanDefinition(parentClass, springBeanDefinition);
                }

                // Adding bean with its immediate interfaces if enabled
                for (Class<?> i : beanClass.getInterfaces()) {
                    addBeanDefinition(i, springBeanDefinition);
                }
            }
        }
        BeanFactory factory = currentBeanFactory.getParentBeanFactory();
        if (factory != null) {
            if (factory instanceof ConfigurableListableBeanFactory) {
                currentBeanFactory = (ConfigurableListableBeanFactory) factory;
            } else {
                logger.info(
                        "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory");
                currentBeanFactory = null;
            }
        } else {
            currentBeanFactory = null;
        }
    } while (currentBeanFactory != null);

    for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : beanDefinitions.entrySet()) {
        Class<?> type = entry.getKey();
        Map<String, SpringBeanDefinition> definitions = entry.getValue();

        // Bind by name for each bean of this type and by type if there is no ambiguity
        for (SpringBeanDefinition candidate : definitions.values()) {
            if (debugEnabled) {
                logger.info("Binding spring bean " + candidate.getName() + " by name and type "
                        + type.getCanonicalName());
            }

            bind(type).annotatedWith(Names.named(candidate.getName())).toProvider(
                    new ByNameSpringContextProvider(type, candidate.getName(), candidate.getBeanFactory()));
        }
    }
}

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!");
                }//from www . j  av a2 s  . 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));
            }

        }
    }
}