1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.james.container.spring.beanfactory;
20
21 import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext;
22 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
23 import org.springframework.beans.BeansException;
24 import org.springframework.core.io.Resource;
25
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.List;
29
30
31
32
33 public class AvalonWebApplicationContext extends AbstractRefreshableWebApplicationContext {
34
35 private List jamesAssemblyResources = new ArrayList();
36 private List springBeanLocations = new ArrayList();
37
38 protected void loadBeanDefinitions(DefaultListableBeanFactory defaultListableBeanFactory) throws IOException, BeansException {
39
40 if (jamesAssemblyResources.size() != 1) throw new RuntimeException("can only load one Avalon-type assembly file");
41 if (springBeanLocations.size() != 1) throw new RuntimeException("can only load one Spring bean definition file");
42 Resource springBeanResource = getResourceByPath((String) springBeanLocations.get(0));
43 Resource jamesAssemblyResource = (Resource) jamesAssemblyResources.get(0);
44 AvalonApplicationContext.loadAvalonBasedBeanDefinitions(defaultListableBeanFactory, springBeanResource, jamesAssemblyResource);
45 }
46
47 public void setConfigLocations(String[] locationStrings) {
48 if (locationStrings == null) locationStrings = new String[] {"/WEB-INF/james-assembly.xml", "/WEB-INF/spring-beans.xml"};
49 for (int i = 0; i < locationStrings.length; i++) {
50 String locationString = locationStrings[i];
51 if (locationString.indexOf("james-assembly") != -1) jamesAssemblyResources.add(getResourceByPath(locationString));
52 else springBeanLocations.add(locationString);
53 }
54 }
55 }