01: package org.riotfamily.common.web.servlet;
02:
03: import java.io.IOException;
04: import java.util.ArrayList;
05: import java.util.List;
06:
07: import org.springframework.beans.factory.BeanDefinitionStoreException;
08: import org.springframework.beans.factory.support.DefaultListableBeanFactory;
09: import org.springframework.beans.factory.xml.ResourceEntityResolver;
10: import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
11: import org.springframework.core.io.Resource;
12: import org.springframework.web.context.support.XmlWebApplicationContext;
13: import org.xml.sax.InputSource;
14:
15: /**
16: * XmlWebApplicationContext that is aware of all resources that are used
17: * to configure the context, including resources referenced via
18: * <code><import resource="..." /></code> tags.
19: *
20: * @author Felix Gnass [fgnass at neteye dot de]
21: */
22: public class ResourceAwareContext extends XmlWebApplicationContext {
23:
24: private ArrayList configResources;
25:
26: protected void loadBeanDefinitions(
27: DefaultListableBeanFactory beanFactory) throws IOException {
28:
29: configResources = new ArrayList();
30:
31: XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(
32: beanFactory) {
33:
34: protected int doLoadBeanDefinitions(
35: InputSource inputSource, Resource resource)
36: throws BeanDefinitionStoreException {
37:
38: configResources.add(resource);
39: return super .doLoadBeanDefinitions(inputSource,
40: resource);
41: }
42: };
43:
44: beanDefinitionReader.setResourceLoader(this );
45: beanDefinitionReader
46: .setEntityResolver(new ResourceEntityResolver(this ));
47: initBeanDefinitionReader(beanDefinitionReader);
48: loadBeanDefinitions(beanDefinitionReader);
49: }
50:
51: public List getConfigResources() {
52: return configResources;
53: }
54:
55: }
|