1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.aop.framework.adapter;
  17. import org.springframework.beans.BeansException;
  18. import org.springframework.beans.factory.config.BeanPostProcessor;
  19. /**
  20. * BeanPostProcessor implementation that "registers" instances of any
  21. * non-default AdvisorAdapters with GlobalAdvisorAdapterRegistry.
  22. *
  23. * <p>The only requirement for it to work is that it needs to be defined
  24. * in application context along with any arbitrary "non-native" Spring
  25. * AdvisorAdapters that need to be "recognized" by Spring's AOP framework.
  26. *
  27. * @author Dmitriy Kopylenko
  28. * @version $Id: AdvisorAdapterRegistrationManager.java,v 1.4 2004/05/23 20:13:03 jhoeller Exp $
  29. */
  30. public class AdvisorAdapterRegistrationManager implements BeanPostProcessor {
  31. private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
  32. /**
  33. * Specify the AdvisorAdapterRegistry to use.
  34. * Default is the global AdvisorAdapterRegistry.
  35. * @see org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry
  36. */
  37. public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) {
  38. this.advisorAdapterRegistry = advisorAdapterRegistry;
  39. }
  40. public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
  41. return bean;
  42. }
  43. public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
  44. if (bean instanceof AdvisorAdapter){
  45. this.advisorAdapterRegistry.registerAdvisorAdapter((AdvisorAdapter) bean);
  46. }
  47. return bean;
  48. }
  49. }