com.holonplatform.spring.internal

## Class BeanRegistryUtils

- java.lang.Object
- - com.holonplatform.spring.internal.BeanRegistryUtils

- All Implemented Interfaces:
    Serializable

      public final class BeanRegistryUtils
      extends Object
      implements Serializable

  Utility class for Spring bean registration related operations.
  Since:
    5.0.0
  See Also:
    Serialized Form

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `buildBeanName(String dataContextId, String name)` Build Spring bean name using optional data context id.
    `static <T> T` | `getAnnotationValue(Map<String,Object> attributes, String key, T defaultValue)` Get the value of an annotation attribute
    `static Class<?>` | `getBeanClass(String beanName, org.springframework.beans.factory.config.BeanDefinition beanDefinition, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, ClassLoader classLoader)` Try to obtain the actual bean class of the bean with given name.
    `static List<String>` | `getBeanNames(org.springframework.beans.factory.ListableBeanFactory beanFactory, Class<?> type)` Get all the bean names of given `type` in given bean factory.
    `static Set<String>` | `getBeanNamesOfTypes(org.springframework.beans.factory.ListableBeanFactory beanFactory, Class<?>... types)` Get the bean names from provided registry of given types.
    `static List<String[]>` | `getBeanNamesWithDataContextId(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, org.springframework.beans.factory.ListableBeanFactory beanFactory, Class<?>... types)` Get the [name,data context id] pairs of the bean definition of given types.
    `static Set<String>` | `getDataContextBeanNames(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, org.springframework.beans.factory.ListableBeanFactory beanFactory, String dataContextId, Class<?>... types)` Get the bean names from provided registry of given types and associated to given data context id.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### buildBeanName

          public static String buildBeanName(String dataContextId,
                                             String name)

      Build Spring bean name using optional data context id. If the given data context id is not null/empty, the bean name is composed using default name, an underscore character and the data context id as suffix.

      For example, if default name is `myname` and the data context id is `test`, this method will return `myname_test`.

      Parameters:
        `dataContextId` - Data context id. May be null.
        `name` - Default bean name
      Returns:
        Bean name with data context id suffix (prepended by an underscore), if data context id is not `null`. Simple bean name otherwise.

    - #### getBeanNames

          public static List<String> getBeanNames(org.springframework.beans.factory.ListableBeanFactory beanFactory,
                                                  Class<?> type)

      Get all the bean names of given `type` in given bean factory.
      Parameters:
        `beanFactory` - Bean factory (not null)
        `type` - Bean type (not null)
      Returns:
        The list of all bean names of given `type` in given bean factory, an empty list if none.

    - #### getBeanNamesOfTypes

          public static Set<String> getBeanNamesOfTypes(org.springframework.beans.factory.ListableBeanFactory beanFactory,
                                                        Class<?>... types)

      Get the bean names from provided registry of given types.
      Parameters:
        `beanFactory` - Bean factory
        `types` - Bean types to take into account
      Returns:
        Names of the beans of given types, empty if none

    - #### getDataContextBeanNames

          public static Set<String> getDataContextBeanNames(org.springframework.beans.factory.support.BeanDefinitionRegistry registry,
                                                            org.springframework.beans.factory.ListableBeanFactory beanFactory,
                                                            String dataContextId,
                                                            Class<?>... types)

      Get the bean names from provided registry of given types and associated to given data context id.
      Parameters:
        `registry` - Bean registry
        `beanFactory` - Bean factory
        `dataContextId` - The data context id, if `null` the name of any bean with given types will be returned
        `types` - Bean types to take into account
      Returns:
        Names of the beans of given types associated to given data context id, empty if none

    - #### getBeanNamesWithDataContextId

          public static List<String[]> getBeanNamesWithDataContextId(org.springframework.beans.factory.support.BeanDefinitionRegistry registry,
                                                                     org.springframework.beans.factory.ListableBeanFactory beanFactory,
                                                                     Class<?>... types)

      Get the [name,data context id] pairs of the bean definition of given types.
      Parameters:
        `registry` - Bean definitions registry
        `beanFactory` - Bean factory
        `types` - Bean types to take into account
      Returns:
        A list of [name,data context id] pairs of the bean definition of given types, empty if none

    - #### getBeanClass

          public static Class<?> getBeanClass(String beanName,
                                              org.springframework.beans.factory.config.BeanDefinition beanDefinition,
                                              org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                              ClassLoader classLoader)

      Try to obtain the actual bean class of the bean with given name.
      Parameters:
        `beanName` - Bean name
        `beanDefinition` - Optional bean definition
        `beanFactory` - Bean factory (not null)
        `classLoader` - ClassLoader to use
      Returns:
        The bean class, or `null` if cannot be detected

    - #### getAnnotationValue

          public static <T> T getAnnotationValue(Map<String,Object> attributes,
                                                 String key,
                                                 T defaultValue)

      Get the value of an annotation attribute
      Type Parameters:
        `T` - Default value type
      Parameters:
        `attributes` - Annotation attributes
        `key` - Attribute name
        `defaultValue` - Default value to return when attribute has no value
      Returns:
        Annotation attribute value

Copyright © 2019 The Holon Platform. All rights reserved.