Class SpringSupport


  • public final class SpringSupport
    extends Object
    Helper class for performing some common Spring-related functions.
    • Field Detail

      • SPRING_BEANS_ELEMENT_NAME

        @Nonnull
        public static final QName SPRING_BEANS_ELEMENT_NAME
        Spring beans element name.
      • LOG

        @Nonnull
        static final org.slf4j.Logger LOG
        Logger.
    • Constructor Detail

      • SpringSupport

        private SpringSupport()
        Constructor.
    • Method Detail

      • parseCustomElements

        @Nullable
        public static void parseCustomElements​(@Nullable @NonnullElements
                                               Collection<Element> elements,
                                               @Nonnull
                                               ParserContext parserContext)
        Parse list of elements into bean definitions which are inserted into the parent context.
        Parameters:
        elements - list of elements to parse
        parserContext - current parsing context
      • parseCustomElements

        @Nullable
        public static ManagedList<BeanDefinition> parseCustomElements​(@Nullable @NonnullElements
                                                                      Collection<Element> elements,
                                                                      @Nonnull
                                                                      ParserContext parserContext,
                                                                      @Nonnull
                                                                      BeanDefinitionBuilder parentBuilder)
        Parse list of elements into bean definitions.
        Parameters:
        elements - list of elements to parse
        parserContext - current parsing context
        parentBuilder - the builder we are going to insert into
        Returns:
        list of bean definitions
      • parseLazyInitCustomElements

        @Nullable
        public static void parseLazyInitCustomElements​(@Nullable @NonnullElements
                                                       Collection<Element> elements,
                                                       @Nonnull
                                                       ParserContext parserContext)
        Parse list of elements into bean definitions and set the lazy-init flag.
        Parameters:
        elements - list of elements to parse
        parserContext - current parsing context
        Since:
        6.0.0
      • parseCustomElement

        @Nullable
        public static BeanDefinition parseCustomElement​(@Nullable
                                                        Element element,
                                                        @Nonnull
                                                        ParserContext parserContext,
                                                        @Nullable
                                                        BeanDefinitionBuilder parentBuilder,
                                                        boolean lazyInit)
        Root method for all parsing.
        Parameters:
        element - the element to parse.

        This works in two scoping modes. If the parent builder is null then this bean is to be inserted into the provided parser context, in this case the parent builder is null. If the parent builder is provided then the scope is limited and the bean definition is returned.

        parserContext - current parsing context
        parentBuilder - the parent builder (for nested building).
        lazyInit - whether this is lazy initialized;
        Returns:
        the bean definition, unless this is for a parent scoped bean
      • parseLazyInitCustomElement

        @Nullable
        public static void parseLazyInitCustomElement​(@Nullable
                                                      Element element,
                                                      @Nonnull
                                                      ParserContext parserContext)
        Parse an element into a bean definition and set the lazy-init flag.
        Parameters:
        element - the element to parse
        parserContext - current parsing context
        Since:
        6.0.0
      • parseNativeElement

        public static void parseNativeElement​(@Nonnull
                                              Element springBeans,
                                              @Nullable
                                              BeanDefinitionRegistry registry)
        Parse the provided Element into the provided registry.
        Parameters:
        springBeans - the element to parse
        registry - the registry to populate
      • createBeanFactory

        @Nonnull
        public static BeanFactory createBeanFactory​(@Nonnull
                                                    Element springBeans)
        Creates a Spring bean factory from the supplied Spring beans element.
        Parameters:
        springBeans - to create bean factory from
        Returns:
        bean factory
      • getBean

        @Nullable
        public static <T> T getBean​(@Nonnull
                                    BeanFactory beanFactory,
                                    @Nonnull
                                    Class<T> clazz)
        Retrieves the bean of the supplied type from the supplied bean factory. Returns null if no bean definition is found.
        Type Parameters:
        T - type of bean to return
        Parameters:
        beanFactory - to get the bean from
        clazz - type of the bean to retrieve
        Returns:
        spring bean
      • getAttributeValueAsList

        @Nonnull
        public static AbstractBeanDefinition getAttributeValueAsList​(@Nonnull
                                                                     Attr attribute)
        Gets the value of a list-type attribute as a BeanDefinitionBuilder.
        Parameters:
        attribute - attribute whose value will be turned into a list
        Returns:
        a bean which will generate a list of the values.
      • getStringValueAsBoolean

        @Nullable
        public static AbstractBeanDefinition getStringValueAsBoolean​(@Nullable
                                                                     String string)
        Gets the value of a boolean-type string as a (ptentially null) Boolean.
        Parameters:
        string - value will be turned into a boolean (or null) (after property replacement)
        Returns:
        a bean which will generate a list of the values.
      • getElementTextContentAsManagedList

        @Nonnull
        public static ManagedList<String> getElementTextContentAsManagedList​(@Nullable
                                                                             Collection<Element> elements)
        Gets the text content of a list of Elements as a ManagedList.
        Parameters:
        elements - the elements whose values will be turned into a list
        Returns:
        list of values, never null