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