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.scripting.support;
18:
19: import org.springframework.aop.target.dynamic.BeanFactoryRefreshableTargetSource;
20: import org.springframework.beans.factory.BeanFactory;
21: import org.springframework.scripting.ScriptSource;
22: import org.springframework.util.Assert;
23:
24: /**
25: * Subclass of BeanFactoryRefreshableTargetSource that determines whether a
26: * refresh is required through the given ScriptSource.
27: *
28: * @author Rob Harrop
29: * @author Rod Johnson
30: * @author Mark Fisher
31: * @since 2.0
32: */
33: public class RefreshableScriptTargetSource extends
34: BeanFactoryRefreshableTargetSource {
35:
36: private final ScriptSource scriptSource;
37:
38: private final boolean isFactoryBean;
39:
40: /**
41: * Create a new RefreshableScriptTargetSource.
42: * @param beanFactory the BeanFactory to fetch beans from
43: * @param beanName the name of the target bean
44: * @param scriptSource the ScriptSource to delegate to
45: * for determining whether a refresh is required
46: */
47: public RefreshableScriptTargetSource(BeanFactory beanFactory,
48: String beanName, ScriptSource scriptSource,
49: boolean isFactoryBean) {
50: super (beanFactory, beanName);
51: Assert.notNull(scriptSource, "ScriptSource must not be null");
52: this .scriptSource = scriptSource;
53: this .isFactoryBean = isFactoryBean;
54: }
55:
56: /**
57: * Determine whether a refresh is required through calling
58: * ScriptSource's <code>isModified()</code> method.
59: * @see org.springframework.scripting.ScriptSource#isModified()
60: */
61: protected boolean requiresRefresh() {
62: return this .scriptSource.isModified();
63: }
64:
65: /**
66: * Obtain a fresh target object, retrieving a FactoryBean if necessary.
67: */
68: protected Object obtainFreshBean(BeanFactory beanFactory,
69: String beanName) {
70: if (isFactoryBean) {
71: beanName = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
72: }
73: return super.obtainFreshBean(beanFactory, beanName);
74: }
75:
76: }
|