01: /*
02: * Created on Mar 30, 2006
03: */
04: package uk.org.ponder.springutil;
05:
06: import org.springframework.aop.TargetSource;
07: import org.springframework.beans.BeansException;
08: import org.springframework.beans.factory.BeanFactory;
09: import org.springframework.beans.factory.BeanFactoryAware;
10:
11: /** A Spring TargetSource that is "even more lazy" than LazyInitTargetSource,
12: * in that it does not assume that the target bean reference is resolvable
13: * at the time of creation. This is necessary to support "unreasonable" models
14: * where bean definitions are being dynamically loaded, or parent containers
15: * attached.
16: * @author Antranig Basman (antranig@caret.cam.ac.uk)
17: */
18:
19: public class VeryLazyInitTargetSource implements TargetSource,
20: BeanFactoryAware {
21: private Class targetclass;
22: private BeanFactory beanFactory;
23: private String targetBeanName;
24:
25: public Class getTargetClass() {
26: return targetclass;
27: }
28:
29: public void setTargetClass(Class targetclass) {
30: this .targetclass = targetclass;
31: }
32:
33: public boolean isStatic() {
34: return false;
35: }
36:
37: public Object getTarget() throws Exception {
38: return beanFactory.getBean(targetBeanName);
39: }
40:
41: public void releaseTarget(Object target) throws Exception {
42:
43: }
44:
45: public void setTargetBeanName(String targetBeanName) {
46: this .targetBeanName = targetBeanName;
47: }
48:
49: public void setBeanFactory(BeanFactory beanFactory)
50: throws BeansException {
51: this.beanFactory = beanFactory;
52: }
53:
54: }
|