1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.config.property; |
17 | |
|
18 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
19 | |
import org.kuali.rice.core.api.config.property.Config; |
20 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
21 | |
import org.springframework.beans.factory.FactoryBean; |
22 | |
|
23 | |
import java.util.List; |
24 | |
|
25 | 0 | public class ConfigFactoryBean implements FactoryBean<org.kuali.rice.core.api.config.property.Config> { |
26 | |
|
27 | |
private List<String> configLocations; |
28 | 0 | private boolean initialize = false; |
29 | |
|
30 | |
public static String CONFIG_OVERRIDE_LOCATION; |
31 | |
|
32 | |
@Override |
33 | |
public org.kuali.rice.core.api.config.property.Config getObject() throws Exception { |
34 | |
|
35 | 0 | org.kuali.rice.core.api.config.property.Config oldConfig = null; |
36 | |
|
37 | 0 | if (getConfigLocations() == null) { |
38 | 0 | throw new ConfigurationException("No config locations declared, at least one is required"); |
39 | |
} |
40 | |
|
41 | 0 | if (ConfigContext.getCurrentContextConfig() != null) { |
42 | 0 | oldConfig = ConfigContext.getCurrentContextConfig(); |
43 | |
} |
44 | |
|
45 | 0 | JAXBConfigImpl config = null; |
46 | 0 | if (CONFIG_OVERRIDE_LOCATION != null) { |
47 | 0 | config = new JAXBConfigImpl(CONFIG_OVERRIDE_LOCATION, oldConfig); |
48 | |
} else { |
49 | 0 | config = new JAXBConfigImpl(getConfigLocations(), oldConfig); |
50 | |
} |
51 | |
|
52 | 0 | config.parseConfig(); |
53 | |
|
54 | 0 | if (initialize) { |
55 | 0 | ConfigContext.init(config); |
56 | |
} |
57 | |
|
58 | 0 | return config; |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public Class<Config> getObjectType() { |
63 | 0 | return org.kuali.rice.core.api.config.property.Config.class; |
64 | |
} |
65 | |
|
66 | |
@Override |
67 | |
public boolean isSingleton() { |
68 | 0 | return true; |
69 | |
} |
70 | |
|
71 | |
public List<String> getConfigLocations() { |
72 | 0 | return this.configLocations; |
73 | |
} |
74 | |
|
75 | |
public void setConfigLocations(List<String> configLocations) { |
76 | 0 | this.configLocations = configLocations; |
77 | 0 | } |
78 | |
|
79 | |
public void setInitialize(boolean initialize) { |
80 | 0 | this.initialize = initialize; |
81 | 0 | } |
82 | |
|
83 | |
} |