1 | |
package org.jtheque.core.managers.beans.ioc; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
import org.springframework.context.ApplicationContext; |
21 | |
import org.springframework.context.support.AbstractMessageSource; |
22 | |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collection; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public final class SpringContainer implements IocContainer { |
33 | |
private ClassPathXmlApplicationContext applicationContext; |
34 | |
|
35 | 0 | private final Collection<String> files = new ArrayList<String>(10); |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public SpringContainer() { |
41 | 0 | super(); |
42 | |
|
43 | 0 | files.add("org/jtheque/core/spring/core-beans.xml"); |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public AbstractMessageSource getResourceBundle() { |
48 | 0 | return (AbstractMessageSource) getApplicationContext().getBean("messageSource"); |
49 | |
} |
50 | |
|
51 | |
@Override |
52 | |
public ApplicationContext getApplicationContext() { |
53 | 0 | return applicationContext; |
54 | |
} |
55 | |
|
56 | |
@Override |
57 | |
public void loadContext() { |
58 | 0 | LogFactory.getLog(SpringContainer.class).debug("Load Spring with XML files : " + files); |
59 | |
|
60 | 0 | applicationContext = new ClassPathXmlApplicationContext(files.toArray(new String[files.size()])); |
61 | 0 | applicationContext.registerShutdownHook(); |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
public void destroy() { |
66 | 0 | if (applicationContext != null) { |
67 | 0 | applicationContext.destroy(); |
68 | |
} |
69 | 0 | } |
70 | |
|
71 | |
@Override |
72 | |
public void inject(Object bean) { |
73 | 0 | applicationContext.getAutowireCapableBeanFactory().autowireBean(bean); |
74 | 0 | } |
75 | |
|
76 | |
@Override |
77 | |
public void addBeansFile(String file) { |
78 | 0 | files.add(file); |
79 | 0 | } |
80 | |
} |