Class ListMergeDirectiveBeanPostProcessor

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.InitializingBean
    Direct Known Subclasses:
    ListMergeDirectiveBeanPostProcessor

    public class ListMergeDirectiveBeanPostProcessor
    extends java.lang.Object
    implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.InitializingBean
    This is BeanPostProcessor for adding items into existing list.

    It creates a cache of ListMergeDirective bean definitions found in the system during its initialization. Then each bean is checked if it should be modified by any of cached directives. If yes, we use BeanDefinitionValueResolver (custom implementation of spring class) to create a object out of beanDefiniton without creating a proper ListMergeDirective bean (this is impossible at this point as it would create circular dependency). The representation of ListMergeDirective is then applied to target bean.

    Forcing this BeanPostProcessor to load all ListMergeDirective instances during its initialization (via dependency injection or by extracting them form ApplicationContext) will lead to change in order in which beans are intialized. Especially some beans will be instanciated before other BeanPostProcessors which may highly affect stability of the system, so its a bad idea.

    • Constructor Detail

      • ListMergeDirectiveBeanPostProcessor

        public ListMergeDirectiveBeanPostProcessor()
    • Method Detail

      • setBeanFactory

        public void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)
                            throws org.springframework.beans.BeansException
        Specified by:
        setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
        Throws:
        org.springframework.beans.BeansException
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Creates cache of listMergeDirective beanDefinitions.
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • isSupportedClass

        protected boolean isSupportedClass​(java.lang.String name)
      • postProcessBeforeInitialization

        public java.lang.Object postProcessBeforeInitialization​(java.lang.Object bean,
                                                                java.lang.String beanName)
                                                         throws org.springframework.beans.BeansException
        Specified by:
        postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • postProcessAfterInitialization

        public java.lang.Object postProcessAfterInitialization​(java.lang.Object bean,
                                                               java.lang.String beanName)
                                                        throws org.springframework.beans.BeansException
        Specified by:
        postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • shouldApplyMergeDirectiveBean

        protected boolean shouldApplyMergeDirectiveBean​(java.lang.String beanName)
      • processMergeDirective

        protected void processMergeDirective​(ListMergeDirective listMergeDirective,
                                             java.lang.String lmdBeanName,
                                             java.lang.Object targetBean,
                                             java.lang.String targetName)
      • resolveListBean

        protected java.util.List<java.lang.Object> resolveListBean​(ListMergeDirective lmd,
                                                                   java.lang.String directiveBeanName,
                                                                   java.lang.Object bean,
                                                                   java.lang.String beanName)
      • getListByDependency

        protected java.util.List<java.lang.Object> getListByDependency​(java.lang.Object dependency,
                                                                       java.lang.String dependencyName,
                                                                       java.lang.String directiveBeanName)
      • getListByPropertyDescriptor

        protected java.util.List<java.lang.Object> getListByPropertyDescriptor​(java.lang.Object bean,
                                                                               java.lang.String beanName,
                                                                               java.lang.String propertyDescriptor,
                                                                               java.lang.String directiveBeanName)
      • getListByReflection

        protected java.util.List<java.lang.Object> getListByReflection​(java.lang.Object bean,
                                                                       java.lang.String beanName,
                                                                       java.lang.String fieldName,
                                                                       java.lang.String directiveBeanName)