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.context.ApplicationContext;
22 import org.springframework.core.io.ClassPathResource;
23 import org.springframework.core.io.FileSystemResource;
24 import org.springframework.core.io.Resource;
25
26 import java.io.File;
27
28
29
30
31
32 public class JamesApplicationContext extends AvalonApplicationContext {
33
34 private static final String FILE_PROTOCOL = "file://";
35 private static final String FILE_PROTOCOL_AND_CONF = "file://conf/";
36 private static final String FILE_PROTOCOL_AND_VAR = "file://var/";
37
38 public static final String JAMES_ASSEMBLY_CONF = "james-assembly.xml";
39
40
41
42
43
44 public static JamesApplicationContext newJamesApplicationContext() {
45 return newJamesApplicationContext(SPRING_BEANS_CONF, JAMES_ASSEMBLY_CONF);
46 }
47
48 public static JamesApplicationContext newJamesApplicationContext(String containerConf, String applicationConf) {
49 return newJamesApplicationContext(new ClassPathResource(containerConf), new ClassPathResource(applicationConf));
50 }
51
52
53 public static JamesApplicationContext newJamesApplicationContext(Resource containerConfigurationResource,
54 Resource applicationConfigurationResource) {
55 JamesApplicationContext result = new JamesApplicationContext(null, containerConfigurationResource, applicationConfigurationResource);
56 result.refresh();
57 return result;
58 }
59
60
61 public JamesApplicationContext(ApplicationContext parent,
62 Resource containerConfigurationResource,
63 Resource applicationConfigurationResource) {
64 super(parent, containerConfigurationResource, applicationConfigurationResource);
65 }
66
67 public ClassLoader getClassLoader() {
68 return Thread.currentThread().getContextClassLoader();
69 }
70
71 public Resource getResource(String fileURL) {
72 Resource r = null;
73 if (fileURL.startsWith("classpath:")) {
74 String resourceName = fileURL.substring("classpath:".length());
75 r = new ClassPathResource(resourceName);
76 } else if (fileURL.startsWith(FILE_PROTOCOL)) {
77 File file = null;
78 if (fileURL.startsWith(FILE_PROTOCOL_AND_CONF)) {
79 file = new File("../conf/" + fileURL.substring(FILE_PROTOCOL_AND_CONF.length()));
80 } else if (fileURL.startsWith(FILE_PROTOCOL_AND_VAR)) {
81 file = new File("../var/" + fileURL.substring(FILE_PROTOCOL_AND_VAR.length()));
82 } else {
83 file = new File("./" + fileURL.substring(FILE_PROTOCOL.length()));
84 }
85 r = new FileSystemResource(file);
86 } else {
87 r = super.getResource(fileURL);
88 }
89 return r;
90 }
91
92
93 }