001package org.kuali.ole.sys.context; 002 003import org.kuali.rice.core.api.config.ConfigurationException; 004import org.kuali.rice.core.api.config.property.Config; 005import org.kuali.rice.core.api.config.property.ConfigContext; 006import org.kuali.rice.core.impl.config.property.ConfigFactoryBean; 007import org.kuali.rice.core.impl.config.property.JAXBConfigImpl; 008import org.springframework.beans.factory.FactoryBean; 009 010import java.util.List; 011 012/** 013 * Created with IntelliJ IDEA. 014 * User: pvsubrah 015 * Date: 6/5/13 016 * Time: 3:39 PM 017 * To change this template use File | Settings | File Templates. 018 */ 019public class OleConfigFactoryBean implements FactoryBean<Config> { 020 private List<String> configLocations; 021 private boolean initialize = false; 022 private boolean systemPropertiesAlwaysWin = true; 023 public static String CONFIG_OVERRIDE_LOCATION; 024 025 026 027 @Override 028 public org.kuali.rice.core.api.config.property.Config getObject() throws Exception { 029 030 org.kuali.rice.core.api.config.property.Config oldConfig = null; 031 032 if (getConfigLocations() == null) { 033 throw new ConfigurationException("No config locations declared, at least one is required"); 034 } 035 036 if (ConfigContext.getCurrentContextConfig() != null) { 037 oldConfig = ConfigContext.getCurrentContextConfig(); 038 } 039 //SimpleConfig config = null; 040 JAXBConfigImpl config = null; 041 if (CONFIG_OVERRIDE_LOCATION != null) { 042 config = new JAXBConfigImpl(CONFIG_OVERRIDE_LOCATION, oldConfig); 043 } else { 044 config = new JAXBConfigImpl(getConfigLocations(), oldConfig); 045 } 046 047 config.setSystemOverride(systemPropertiesAlwaysWin); 048 config.parseConfig(); 049 050 if (initialize) { 051 ConfigContext.init(config); 052 } 053 054 return config; 055 } 056 057 @Override 058 public Class<Config> getObjectType() { 059 return org.kuali.rice.core.api.config.property.Config.class; 060 } 061 062 @Override 063 public boolean isSingleton() { 064 return true; 065 } 066 067 public List<String> getConfigLocations() { 068 return this.configLocations; 069 } 070 071 public void setConfigLocations(List<String> configLocations) { 072 this.configLocations = configLocations; 073 } 074 075 public void setInitialize(boolean initialize) { 076 this.initialize = initialize; 077 } 078 079 public boolean isSystemPropertiesAlwaysWin() { 080 return systemPropertiesAlwaysWin; 081 } 082 083 public void setSystemPropertiesAlwaysWin(boolean systemPropertiesAlwaysWin) { 084 this.systemPropertiesAlwaysWin = systemPropertiesAlwaysWin; 085 } 086}