001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.aop.framework.adapter; 018 019import org.springframework.beans.BeansException; 020import org.springframework.beans.factory.config.BeanPostProcessor; 021 022/** 023 * BeanPostProcessor that registers {@link AdvisorAdapter} beans in the BeanFactory with 024 * an {@link AdvisorAdapterRegistry} (by default the {@link GlobalAdvisorAdapterRegistry}). 025 * 026 * <p>The only requirement for it to work is that it needs to be defined 027 * in application context along with "non-native" Spring AdvisorAdapters 028 * that need to be "recognized" by Spring's AOP framework. 029 * 030 * @author Dmitriy Kopylenko 031 * @author Juergen Hoeller 032 * @since 27.02.2004 033 * @see #setAdvisorAdapterRegistry 034 * @see AdvisorAdapter 035 */ 036public class AdvisorAdapterRegistrationManager implements BeanPostProcessor { 037 038 private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance(); 039 040 041 /** 042 * Specify the AdvisorAdapterRegistry to register AdvisorAdapter beans with. 043 * Default is the global AdvisorAdapterRegistry. 044 * @see GlobalAdvisorAdapterRegistry 045 */ 046 public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) { 047 this.advisorAdapterRegistry = advisorAdapterRegistry; 048 } 049 050 051 @Override 052 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 053 return bean; 054 } 055 056 @Override 057 public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 058 if (bean instanceof AdvisorAdapter){ 059 this.advisorAdapterRegistry.registerAdvisorAdapter((AdvisorAdapter) bean); 060 } 061 return bean; 062 } 063 064}