01: /*
02: * Copyright 2002-2006 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.target.dynamic;
18:
19: import org.springframework.beans.factory.BeanFactory;
20: import org.springframework.util.Assert;
21:
22: /**
23: * Refreshable TargetSource that fetches fresh target beans from a BeanFactory.
24: *
25: * <p>Can be subclassed to override <code>requiresRefresh()</code> to suppress
26: * unnecessary refreshes. By default, a refresh will be performed every time
27: * the "refreshCheckDelay" has elapsed.
28: *
29: * @author Rob Harrop
30: * @author Rod Johnson
31: * @author Juergen Hoeller
32: * @since 2.0
33: * @see org.springframework.beans.factory.BeanFactory
34: * @see #requiresRefresh()
35: * @see #setRefreshCheckDelay
36: */
37: public class BeanFactoryRefreshableTargetSource extends
38: AbstractRefreshableTargetSource {
39:
40: private final BeanFactory beanFactory;
41:
42: private final String beanName;
43:
44: /**
45: * Create a new BeanFactoryRefreshableTargetSource for the given
46: * bean factory and bean name.
47: * <p>Note that the passed-in BeanFactory should have an appropriate
48: * bean definition set up for the given bean name.
49: * @param beanFactory the BeanFactory to fetch beans from
50: * @param beanName the name of the target bean
51: */
52: public BeanFactoryRefreshableTargetSource(BeanFactory beanFactory,
53: String beanName) {
54: Assert.notNull(beanFactory, "BeanFactory is required");
55: Assert.notNull(beanName, "Bean name is required");
56: this .beanFactory = beanFactory;
57: this .beanName = beanName;
58: }
59:
60: /**
61: * Fetch a new target bean instance from the bean factory.
62: * @see org.springframework.beans.factory.BeanFactory#getBean
63: */
64: protected Object freshTarget() {
65: return this.beanFactory.getBean(this.beanName);
66: }
67:
68: }
|