01: /*
02: * Created on Aug 2, 2005
03: */
04: package uk.org.ponder.springutil;
05:
06: import java.util.HashMap;
07:
08: import org.springframework.beans.BeanWrapper;
09: import org.springframework.beans.BeanWrapperImpl;
10: import org.springframework.beans.BeansException;
11: import org.springframework.beans.factory.BeanFactory;
12: import org.springframework.context.ApplicationContext;
13: import org.springframework.context.ApplicationContextAware;
14:
15: /** An obsolete attempt to remove the enormous expense of constructing
16: * Spring BeanWrapperImpl objects.
17: * @author Antranig Basman (antranig@caret.cam.ac.uk)
18: *
19: */
20: public class BeanWrapperCache implements ApplicationContextAware {
21:
22: private HashMap wrapperforpath = new HashMap();
23: private BeanFactory factory;
24:
25: public void setApplicationContext(
26: ApplicationContext applicationContext)
27: throws BeansException {
28: factory = applicationContext;
29: }
30:
31: public BeanWrapper wrapperForPath(String path) {
32: BeanWrapper wrapper = (BeanWrapper) wrapperforpath.get(path);
33: if (wrapper == null) {
34: Object bean = factory.getBean(path);
35: wrapper = new BeanWrapperImpl(bean, path, factory);
36: wrapperforpath.put(path, wrapper);
37: }
38: return wrapper;
39: }
40:
41: }
|