Interface RuntimeSpringConfiguration

  • All Known Implementing Classes:
    DefaultRuntimeSpringConfiguration

    public interface RuntimeSpringConfiguration
    A programmable runtime Spring configuration that allows a spring ApplicationContext to be constructed at runtime. Credit must go to Solomon Duskis and the article: http://jroller.com/page/Solomon?entry=programmatic_configuration_in_spring
    Since:
    0.3
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      BeanConfiguration addAbstractBean​(java.lang.String name)
      \ Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object.
      void addAlias​(java.lang.String alias, java.lang.String beanName)
      Adds an alias to a given bean name.
      void addBeanConfiguration​(java.lang.String beanName, BeanConfiguration beanConfiguration)
      Adds a bean configuration to the list of beans to be created.
      void addBeanDefinition​(java.lang.String name, org.springframework.beans.factory.config.BeanDefinition bd)
      Adds a Spring BeanDefinition.
      BeanConfiguration addPrototypeBean​(java.lang.String name)
      Adds an empty prototype bean configuration.
      BeanConfiguration addPrototypeBean​(java.lang.String name, java.lang.Class clazz)
      Adds a prototype bean definition.
      BeanConfiguration addSingletonBean​(java.lang.String name)
      Adds an empty singleton bean configuration.
      BeanConfiguration addSingletonBean​(java.lang.String name, java.lang.Class clazz)
      Adds a singleton bean definition.
      BeanConfiguration addSingletonBean​(java.lang.String name, java.lang.Class clazz, java.util.Collection args)
      Creates a new singleton bean and adds it to the list of bean references.
      boolean containsBean​(java.lang.String name)
      Returns whether the runtime spring config contains the specified bean.
      org.springframework.beans.factory.support.AbstractBeanDefinition createBeanDefinition​(java.lang.String name)
      Creates and returns the BeanDefinition that is regsitered within the given name or returns null.
      BeanConfiguration createPrototypeBean​(java.lang.String name)
      Creates a new prototype bean configuration.
      BeanConfiguration createSingletonBean​(java.lang.Class clazz)
      Creates a singleton bean configuration.
      BeanConfiguration createSingletonBean​(java.lang.Class clazz, java.util.Collection constructorArguments)
      Creates a singleton bean configuration.
      BeanConfiguration createSingletonBean​(java.lang.String name)
      Creates a new singleton bean configuration.
      org.springframework.context.ApplicationContext getApplicationContext()
      Retrieves the application context from the current state.
      BeanConfiguration getBeanConfig​(java.lang.String name)
      Returns the BeanConfiguration for the specified name.
      org.springframework.beans.factory.config.BeanDefinition getBeanDefinition​(java.lang.String beanName)
      Obtains a BeanDefinition instance for the given beanName.
      java.util.List<java.lang.String> getBeanNames()  
      org.springframework.context.ApplicationContext getUnrefreshedApplicationContext()  
      void registerBeansWithConfig​(RuntimeSpringConfiguration targetSpringConfig)
      Registers the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration.
      void registerBeansWithContext​(org.springframework.context.support.GenericApplicationContext applicationContext)
      Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext.
      void registerBeansWithRegistry​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      Registers the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry.
      void registerPostProcessor​(org.springframework.beans.factory.config.BeanFactoryPostProcessor processor)
      Registers a bean factory post processor with the context.
      void setBeanFactory​(org.springframework.beans.factory.ListableBeanFactory beanFactory)
      Sets the BeanFactory implementation to use.
    • Method Detail

      • addSingletonBean

        BeanConfiguration addSingletonBean​(java.lang.String name,
                                           java.lang.Class clazz)
        Adds a singleton bean definition.
        Parameters:
        name - The name of the bean
        clazz - The class of the bean
        Returns:
        A BeanConfiguration instance
      • getUnrefreshedApplicationContext

        org.springframework.context.ApplicationContext getUnrefreshedApplicationContext()
      • addPrototypeBean

        BeanConfiguration addPrototypeBean​(java.lang.String name,
                                           java.lang.Class clazz)
        Adds a prototype bean definition.
        Parameters:
        name - The name of the bean
        clazz - The class of the bean
        Returns:
        A BeanConfiguration instance
      • getApplicationContext

        org.springframework.context.ApplicationContext getApplicationContext()
        Retrieves the application context from the current state.
        Returns:
        The ApplicationContext instance
      • addSingletonBean

        BeanConfiguration addSingletonBean​(java.lang.String name)
        Adds an empty singleton bean configuration.
        Parameters:
        name - The name of the singleton bean
        Returns:
        A BeanConfiguration instance
      • addPrototypeBean

        BeanConfiguration addPrototypeBean​(java.lang.String name)
        Adds an empty prototype bean configuration.
        Parameters:
        name - The name of the prototype bean
        Returns:
        A BeanConfiguration instance
      • createSingletonBean

        BeanConfiguration createSingletonBean​(java.lang.Class clazz)
        Creates a singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references. Hence should be used for creating nested beans.
        Parameters:
        clazz -
        Returns:
        A BeanConfiguration instance
      • addSingletonBean

        BeanConfiguration addSingletonBean​(java.lang.String name,
                                           java.lang.Class clazz,
                                           java.util.Collection args)
        Creates a new singleton bean and adds it to the list of bean references.
        Parameters:
        name - The name of the bean
        clazz - The class of the bean
        args - The constructor arguments of the bean
        Returns:
        A BeanConfiguration instance
      • createSingletonBean

        BeanConfiguration createSingletonBean​(java.lang.Class clazz,
                                              java.util.Collection constructorArguments)
        Creates a singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references. Hence should be used for creating nested beans
        Parameters:
        clazz - The bean class
        constructorArguments - The constructor arguments
        Returns:
        A BeanConfiguration instance
      • createPrototypeBean

        BeanConfiguration createPrototypeBean​(java.lang.String name)
        Creates a new prototype bean configuration. Differs from addPrototypeBean in that it doesn't add the bean to the list of bean references to be created via the getApplicationContext() method, hence can be used for creating nested beans
        Parameters:
        name - The bean name
        Returns:
        A BeanConfiguration instance
      • createSingletonBean

        BeanConfiguration createSingletonBean​(java.lang.String name)
        Creates a new singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references to be created via the getApplicationContext() method, hence can be used for creating nested beans
        Parameters:
        name - The bean name
        Returns:
        A BeanConfiguration instance
      • addBeanConfiguration

        void addBeanConfiguration​(java.lang.String beanName,
                                  BeanConfiguration beanConfiguration)
        Adds a bean configuration to the list of beans to be created.
        Parameters:
        beanName - The name of the bean in the context
        beanConfiguration - The BeanConfiguration instance
      • addBeanDefinition

        void addBeanDefinition​(java.lang.String name,
                               org.springframework.beans.factory.config.BeanDefinition bd)
        Adds a Spring BeanDefinition. Differs from BeanConfiguration which is a factory class for creating BeanDefinition instances
        Parameters:
        name - The name of the bean
        bd - The BeanDefinition instance
      • containsBean

        boolean containsBean​(java.lang.String name)
        Returns whether the runtime spring config contains the specified bean.
        Parameters:
        name - The bean name
        Returns:
        true if it does
      • getBeanConfig

        BeanConfiguration getBeanConfig​(java.lang.String name)
        Returns the BeanConfiguration for the specified name.
        Parameters:
        name - The name of the bean configuration
        Returns:
        The BeanConfiguration
      • createBeanDefinition

        org.springframework.beans.factory.support.AbstractBeanDefinition createBeanDefinition​(java.lang.String name)
        Creates and returns the BeanDefinition that is regsitered within the given name or returns null.
        Parameters:
        name - The name of the bean definition
        Returns:
        A BeanDefinition
      • registerPostProcessor

        void registerPostProcessor​(org.springframework.beans.factory.config.BeanFactoryPostProcessor processor)
        Registers a bean factory post processor with the context.
        Parameters:
        processor - The BeanFactoryPostProcessor instance
      • getBeanNames

        java.util.List<java.lang.String> getBeanNames()
      • registerBeansWithContext

        void registerBeansWithContext​(org.springframework.context.support.GenericApplicationContext applicationContext)
        Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext.
        Parameters:
        applicationContext - The ApplicationContext instance
      • registerBeansWithRegistry

        void registerBeansWithRegistry​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
        Registers the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry.
        Parameters:
        registry - The BeanDefinitionRegistry instance
      • registerBeansWithConfig

        void registerBeansWithConfig​(RuntimeSpringConfiguration targetSpringConfig)
        Registers the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration.
        Parameters:
        targetSpringConfig - The RuntimeSpringConfiguration instance
      • addAbstractBean

        BeanConfiguration addAbstractBean​(java.lang.String name)
        \ Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object.
        Parameters:
        name - The name of the bean
        Returns:
        The BeanConfiguration object
      • addAlias

        void addAlias​(java.lang.String alias,
                      java.lang.String beanName)
        Adds an alias to a given bean name.
        Parameters:
        alias - The alias
        beanName - The bean
      • getBeanDefinition

        org.springframework.beans.factory.config.BeanDefinition getBeanDefinition​(java.lang.String beanName)
        Obtains a BeanDefinition instance for the given beanName.
        Parameters:
        beanName - The beanName
        Returns:
        The BeanDefinition or null if it doesn't exit
      • setBeanFactory

        void setBeanFactory​(org.springframework.beans.factory.ListableBeanFactory beanFactory)
        Sets the BeanFactory implementation to use.
        Parameters:
        beanFactory - The BeanFactory implementation