Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.BeanPostProcessor


   * {@link org.apache.myfaces.orchestra.conversation.ConversationAware} interface.
   */
  public void setBeanFactory(BeanFactory beanFactory) throws BeansException
  {
    ((ConfigurableBeanFactory) beanFactory).addBeanPostProcessor(
      new BeanPostProcessor()
      {
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
        {
          if (bean instanceof ConversationAware)
          {
View Full Code Here


     * Include BeanPostProcessor to deal with SCA Annotations in Spring Bean
     */
    private void includeAnnotationProcessors(ConfigurableListableBeanFactory beanFactory) {
       
        // Processor to deal with @Init and @Destroy SCA Annotations
        BeanPostProcessor initDestroyProcessor = new InitDestroyAnnotationProcessor();
        beanFactory.addBeanPostProcessor(initDestroyProcessor);

        // Processor to deal with @Reference SCA Annotations
        ComponentStub component = new ComponentStub(implementation.getComponentTie());
        BeanPostProcessor referenceProcessor = new ReferenceAnnotationProcessor(component);
        beanFactory.addBeanPostProcessor(referenceProcessor);
       
        // Processor to deal with @Property SCA Annotations
        PropertyValueStub pvs = new PropertyValueStub(implementation.getPropertyValueTie());
        BeanPostProcessor propertyProcessor = new PropertyAnnotationProcessor(pvs);
        beanFactory.addBeanPostProcessor(propertyProcessor);
       
        // Processor to deal with @ComponentName SCA Annotations
        BeanPostProcessor componentNameProcessor = new ComponentNameAnnotationProcessor(implementation.getComponentName());
        beanFactory.addBeanPostProcessor(componentNameProcessor);
       
        // Processor to deal with @Constructor SCA Annotations
        BeanPostProcessor constructorProcessor = new ConstructorAnnotationProcessor();
        beanFactory.addBeanPostProcessor(constructorProcessor);        
    }
View Full Code Here

     * Include BeanPostProcessor to deal with SCA Annotations in Spring Bean
     */
    private void includeAnnotationProcessors(ConfigurableListableBeanFactory beanFactory) {
       
        // Processor to deal with @Init and @Destroy SCA Annotations
        BeanPostProcessor initDestroyProcessor = new InitDestroyAnnotationProcessor();
        beanFactory.addBeanPostProcessor(initDestroyProcessor);

        // Processor to deal with @Reference SCA Annotations
        ComponentStub component = new ComponentStub(implementation.getComponentTie());
        BeanPostProcessor referenceProcessor = new ReferenceAnnotationProcessor(component);
        beanFactory.addBeanPostProcessor(referenceProcessor);
       
        // Processor to deal with @Property SCA Annotations
        PropertyValueStub pvs = new PropertyValueStub(implementation.getPropertyValueTie());
        BeanPostProcessor propertyProcessor = new PropertyAnnotationProcessor(pvs);
        beanFactory.addBeanPostProcessor(propertyProcessor);
       
        // Processor to deal with @ComponentName SCA Annotations
        BeanPostProcessor componentNameProcessor = new ComponentNameAnnotationProcessor(implementation.getComponentName());
        beanFactory.addBeanPostProcessor(componentNameProcessor);
       
        // Processor to deal with @Constructor SCA Annotations
        BeanPostProcessor constructorProcessor = new ConstructorAnnotationProcessor();
        beanFactory.addBeanPostProcessor(constructorProcessor);        
    }
View Full Code Here

    parent.registerBeanDefinition("rod", bd2);

    this.factory = new DefaultListableBeanFactory(parent);
    new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(
        new ClassPathResource("test.xml", getClass()));
    this.factory.addBeanPostProcessor(new BeanPostProcessor() {
      @Override
      public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
        if (bean instanceof TestBean) {
          ((TestBean) bean).setPostProcessed(true);
        }
View Full Code Here

    root.setPortletConfig(portletConfig);
    root.setConfigLocations(new String[] {"/org/springframework/web/portlet/context/WEB-INF/applicationContext.xml"});
    root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
      @Override
      public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
          @Override
          public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            if(bean instanceof TestBean) {
              ((TestBean) bean).getFriends().add("myFriend");
            }
View Full Code Here

    List<BeanPostProcessor> internalPostProcessors = new ArrayList<BeanPostProcessor>();
    List<String> orderedPostProcessorNames = new ArrayList<String>();
    List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
    for (String ppName : postProcessorNames) {
      if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
        BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
        priorityOrderedPostProcessors.add(pp);
        if (pp instanceof MergedBeanDefinitionPostProcessor) {
          internalPostProcessors.add(pp);
        }
      }
      else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
        orderedPostProcessorNames.add(ppName);
      }
      else {
        nonOrderedPostProcessorNames.add(ppName);
      }
    }

    // First, register the BeanPostProcessors that implement PriorityOrdered.
    OrderComparator.sort(priorityOrderedPostProcessors);
    registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);

    // Next, register the BeanPostProcessors that implement Ordered.
    List<BeanPostProcessor> orderedPostProcessors = new ArrayList<BeanPostProcessor>();
    for (String ppName : orderedPostProcessorNames) {
      BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
      orderedPostProcessors.add(pp);
      if (pp instanceof MergedBeanDefinitionPostProcessor) {
        internalPostProcessors.add(pp);
      }
    }
    OrderComparator.sort(orderedPostProcessors);
    registerBeanPostProcessors(beanFactory, orderedPostProcessors);

    // Now, register all regular BeanPostProcessors.
    List<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
    for (String ppName : nonOrderedPostProcessorNames) {
      BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
      nonOrderedPostProcessors.add(pp);
      if (pp instanceof MergedBeanDefinitionPostProcessor) {
        internalPostProcessors.add(pp);
      }
    }
View Full Code Here

  @Test
  public void testBeanPostProcessorWithWrappedObjectAndDisposableBean() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(BeanWithDisposableBean.class);
    lbf.registerBeanDefinition("test", bd);
    lbf.addBeanPostProcessor(new BeanPostProcessor() {
      @Override
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        return new TestBean();
      }
      @Override
View Full Code Here

  @Test
  public void testBeanPostProcessorWithWrappedObjectAndCloseable() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(BeanWithCloseable.class);
    lbf.registerBeanDefinition("test", bd);
    lbf.addBeanPostProcessor(new BeanPostProcessor() {
      @Override
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        return new TestBean();
      }
      @Override
View Full Code Here

  public void testBeanPostProcessorWithWrappedObjectAndDestroyMethod() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class);
    bd.setDestroyMethodName("close");
    lbf.registerBeanDefinition("test", bd);
    lbf.addBeanPostProcessor(new BeanPostProcessor() {
      @Override
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        return new TestBean();
      }
      @Override
View Full Code Here

  @Test
  public void nullReturningBeanPostProcessor() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(AutowiredConfig.class);
    context.getBeanFactory().addBeanPostProcessor(new BeanPostProcessor() {
      @Override
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        return (bean instanceof TestBean ? null : bean);
      }
      @Override
      public Object postProcessAfterInitialization(Object bean, String beanName) {
        return bean;
      }
    });
    context.getBeanFactory().addBeanPostProcessor(new BeanPostProcessor() {
      @Override
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        bean.getClass().getName();
        return bean;
      }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.BeanPostProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.