01: /*
02: * Created on 17-Dec-2005
03: */
04: package uk.org.ponder.rsac;
05:
06: import org.springframework.aop.TargetSource;
07:
08: /**
09: * An RSAC-specific TargetSource, which will be permanently maintained in the
10: * RSAC ThreadLocal container. A sort of multi-way cross between
11: * ThreadLocalTargetSource, HotSwappableTargetSource and
12: * LazyInitTargetSource...
13: * <p>An RLTS will be automatically created for every bean in the context
14: * marked as <code>lazy-init="true"</code>, converting it into a
15: * <a href="http://www2.caret.cam.ac.uk/rsfwiki/Wiki.jsp?page=VeryLazyBeans">
16: * very lazy bean</a>
17: * <p>Note that the one exposed dependency, targetBeanName, is actually fake.
18: * Since we have only ONE RLTS per thread, the name is actually stashed by
19: * RSACBeanLocator, which on thread init creates not only a ProxyFactoryBean,
20: * but also a forked instance of this bean, with all the dependencies
21: * delivered via constructor.
22: * <p>This facility could be provided by a Spring AutoProxyCreator but there
23: * isn't time during a request cycle.
24: * @author Antranig Basman (amb26@ponder.org.uk)
25: *
26: */
27: public class RSACLazyTargetSource implements TargetSource {
28: private Class targetclass;
29: private RSACBeanLocatorImpl rsacbl;
30: private String targetbeanname;
31: private PerRequestInfo pri;
32:
33: public RSACLazyTargetSource(RSACBeanLocatorImpl rsacbl,
34: PerRequestInfo pri, Class targetclass, String targetbeanname) {
35: this .rsacbl = rsacbl;
36: this .pri = pri;
37: this .targetclass = targetclass;
38: this .targetbeanname = targetbeanname;
39: }
40:
41: public Class getTargetClass() {
42: return targetclass;
43: }
44:
45: public boolean isStatic() {
46: return false;
47: }
48:
49: public Object getTarget() {
50: return rsacbl.getBean(pri, targetbeanname, true);
51: }
52:
53: public void releaseTarget(Object target) throws Exception {
54: // Apparently nothing is necessary to do here
55: }
56:
57: }
|