KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > target > dynamic > BeanFactoryRefreshableTargetSource


1 /*
2  * Copyright 2002-2006 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
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 AbstractRefreshableTargetSource {
38
39     private final BeanFactory beanFactory;
40
41     private final String JavaDoc beanName;
42
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, String JavaDoc beanName) {
53         Assert.notNull(beanFactory, "BeanFactory is required");
54         Assert.notNull(beanName, "Bean name is required");
55         this.beanFactory = beanFactory;
56         this.beanName = beanName;
57     }
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 JavaDoc freshTarget() {
65         return this.beanFactory.getBean(this.beanName);
66     }
67
68 }
69
Popular Tags