KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > common > web > servlet > ResourceAwareContext


1 package org.riotfamily.common.web.servlet;
2
3 import java.io.IOException JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.springframework.beans.factory.BeanDefinitionStoreException;
8 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
9 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 JavaDoc;
14
15 /**
16  * XmlWebApplicationContext that is aware of all resources that are used
17  * to configure the context, including resources referenced via
18  * <code>&lt;import resource="..." /&gt;</code> tags.
19  *
20  * @author Felix Gnass [fgnass at neteye dot de]
21  */

22 public class ResourceAwareContext extends XmlWebApplicationContext {
23
24     private ArrayList JavaDoc configResources;
25     
26     protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
27             throws IOException JavaDoc {
28         
29         configResources = new ArrayList JavaDoc();
30         
31         XmlBeanDefinitionReader beanDefinitionReader =
32                 new XmlBeanDefinitionReader(beanFactory) {
33             
34             protected int doLoadBeanDefinitions(InputSource JavaDoc inputSource,
35                     Resource resource) throws BeanDefinitionStoreException {
36                 
37                 configResources.add(resource);
38                 return super.doLoadBeanDefinitions(inputSource, resource);
39             }
40         };
41
42         beanDefinitionReader.setResourceLoader(this);
43         beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
44         initBeanDefinitionReader(beanDefinitionReader);
45         loadBeanDefinitions(beanDefinitionReader);
46     }
47     
48     public List JavaDoc getConfigResources() {
49         return configResources;
50     }
51     
52 }
53
Popular Tags