001 /* 002 * Copyright 2008-2009 the original author or authors. 003 * The contents of this file are subject to the Mozilla Public License 004 * Version 1.1 (the "License"); you may not use this file except in 005 * compliance with the License. You may obtain a copy of the License at 006 * http://www.mozilla.org/MPL/ 007 * 008 * Software distributed under the License is distributed on an "AS IS" 009 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 010 * License for the specific language governing rights and limitations 011 * under the License. 012 */ 013 014 package com.mtgi.analytics.aop.config; 015 016 import org.springframework.beans.BeansException; 017 import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 018 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 019 020 /** 021 * Re-runs all other post-processors on the given bean factory on 022 * another target bean factory, for chaining factory post-process 023 * operations across multiple unrelated factories. 024 * @see TemplateBeanDefinitionParser 025 */ 026 public class ChainingBeanFactoryPostProcessor implements BeanFactoryPostProcessor { 027 028 private ConfigurableListableBeanFactory targetFactory; 029 030 public void setTargetFactory(ConfigurableListableBeanFactory targetFactory) { 031 this.targetFactory = targetFactory; 032 } 033 034 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 035 if (!targetFactory.equals(beanFactory)) { 036 String[] bfpps = beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, false, false); 037 for (String name : bfpps) { 038 BeanFactoryPostProcessor delegate = (BeanFactoryPostProcessor)beanFactory.getBean(name); 039 if (delegate != this) 040 delegate.postProcessBeanFactory(targetFactory); 041 } 042 } 043 } 044 }