01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.springframework.aop.framework.adapter;
18:
19: import org.springframework.beans.BeansException;
20: import org.springframework.beans.factory.config.BeanPostProcessor;
21:
22: /**
23: * BeanPostProcessor implementation that "registers" instances of any
24: * non-default AdvisorAdapters with GlobalAdvisorAdapterRegistry.
25: *
26: * <p>The only requirement for it to work is that it needs to be defined
27: * in application context along with any arbitrary "non-native" Spring
28: * AdvisorAdapters that need to be "recognized" by Spring's AOP framework.
29: *
30: * @author Dmitriy Kopylenko
31: * @since 27.02.2004
32: * @see AdvisorAdapter
33: * @see AdvisorAdapterRegistry
34: * @see GlobalAdvisorAdapterRegistry
35: */
36: public class AdvisorAdapterRegistrationManager implements
37: BeanPostProcessor {
38:
39: private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry
40: .getInstance();
41:
42: /**
43: * Specify the AdvisorAdapterRegistry to use.
44: * Default is the global AdvisorAdapterRegistry.
45: * @see org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry
46: */
47: public void setAdvisorAdapterRegistry(
48: AdvisorAdapterRegistry advisorAdapterRegistry) {
49: this .advisorAdapterRegistry = advisorAdapterRegistry;
50: }
51:
52: public Object postProcessBeforeInitialization(Object bean,
53: String beanName) throws BeansException {
54: return bean;
55: }
56:
57: public Object postProcessAfterInitialization(Object bean,
58: String beanName) throws BeansException {
59: if (bean instanceof AdvisorAdapter) {
60: this .advisorAdapterRegistry
61: .registerAdvisorAdapter((AdvisorAdapter) bean);
62: }
63: return bean;
64: }
65:
66: }
|