01: /*
02: * Created on Nov 23, 2005
03: */
04: package uk.org.ponder.springutil;
05:
06: import org.springframework.beans.BeansException;
07: import org.springframework.context.ApplicationContext;
08: import org.springframework.context.ApplicationContextAware;
09:
10: import uk.org.ponder.saxalizer.mapping.MappingLoadManager;
11: import uk.org.ponder.saxalizer.mapping.MappingLoader;
12: import uk.org.ponder.saxalizer.mapping.MappingLoaderList;
13:
14: /** A Spring-aware loader which scours the context for all Hooznak, everywhere.
15: * More precisely, this will locate all beans of type MappingLoader and
16: * MappingLoaderList in the current ApplicationContext, and invoke them to add
17: * any mappings they define to the mapping context set as a property in its
18: * superclass.
19: * <p>Note that in general Spring requires some form of generalised
20: * object list collaboration scheme whereby this sort of task can be achieved
21: * in a more environmentally friendly way.
22: * @author Antranig Basman (antranig@caret.cam.ac.uk)
23: *
24: */
25: public class SpringXMLMappingLoader extends MappingLoadManager
26: implements ApplicationContextAware {
27: private ApplicationContext applicationContext;
28:
29: public void setApplicationContext(
30: ApplicationContext applicationContext)
31: throws BeansException {
32: this .applicationContext = applicationContext;
33: }
34:
35: public void init() {
36: MappingLoaderList loaders = new MappingLoaderList();
37: String[] names = applicationContext.getBeanNamesForType(
38: MappingLoader.class, false, false);
39: for (int i = 0; i < names.length; ++i) {
40: MappingLoader loader = (MappingLoader) applicationContext
41: .getBean(names[i]);
42: loaders.add(loader);
43: }
44: names = applicationContext.getBeanNamesForType(
45: MappingLoaderList.class, false, false);
46: for (int i = 0; i < names.length; ++i) {
47: MappingLoaderList loader = (MappingLoaderList) applicationContext
48: .getBean(names[i]);
49: loaders.addAll(loader);
50: }
51: super.setMappingLoaders(loaders);
52: }
53:
54: }
|