01: /*
02: * Copyright 2002-2007 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.jca.context;
18:
19: import javax.resource.spi.BootstrapContext;
20:
21: import org.springframework.beans.BeansException;
22: import org.springframework.beans.factory.config.BeanPostProcessor;
23:
24: /**
25: * {@link org.springframework.beans.factory.config.BeanPostProcessor}
26: * implementation that passes the BootstrapContext to beans that implement
27: * the {@link BootstrapContextAware} interface.
28: *
29: * <p>{@link ResourceAdapterApplicationContext} automatically registers
30: * this processor with its underlying bean factory.
31: *
32: * @author Juergen Hoeller
33: * @since 2.5
34: * @see BootstrapContextAware
35: */
36: class BootstrapContextAwareProcessor implements BeanPostProcessor {
37:
38: private final BootstrapContext bootstrapContext;
39:
40: /**
41: * Create a new BootstrapContextAwareProcessor for the given context.
42: */
43: public BootstrapContextAwareProcessor(
44: BootstrapContext bootstrapContext) {
45: this .bootstrapContext = bootstrapContext;
46: }
47:
48: public Object postProcessBeforeInitialization(Object bean,
49: String beanName) throws BeansException {
50: if (this .bootstrapContext != null
51: && bean instanceof BootstrapContextAware) {
52: ((BootstrapContextAware) bean)
53: .setBootstrapContext(this .bootstrapContext);
54: }
55: return bean;
56: }
57:
58: public Object postProcessAfterInitialization(Object bean,
59: String beanName) throws BeansException {
60: return bean;
61: }
62:
63: }
|