01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.rice.config.spring;
17:
18: import java.util.List;
19: import java.util.Properties;
20:
21: import org.kuali.rice.config.Config;
22: import org.kuali.rice.config.ConfigurationException;
23: import org.kuali.rice.config.SimpleConfig;
24: import org.kuali.rice.core.Core;
25: import org.springframework.beans.factory.FactoryBean;
26:
27: public class ConfigFactoryBean implements FactoryBean {
28:
29: private List<String> configLocations;
30:
31: public static String CONFIG_OVERRIDE_LOCATION;
32:
33: public Object getObject() throws Exception {
34: if (getConfigLocations() == null) {
35: throw new ConfigurationException(
36: "No config locations declared, at least one is required");
37: }
38: Properties baseProperties = new Properties();
39: if (Core.getCurrentContextConfig() != null) {
40: baseProperties = Core.getCurrentContextConfig()
41: .getProperties();
42: }
43: SimpleConfig config = null;
44: if (CONFIG_OVERRIDE_LOCATION != null) {
45: config = new SimpleConfig(CONFIG_OVERRIDE_LOCATION,
46: baseProperties);
47: } else {
48: config = new SimpleConfig(getConfigLocations(),
49: baseProperties);
50: }
51:
52: config.parseConfig();
53: return config;
54: }
55:
56: public Class getObjectType() {
57: return Config.class;
58: }
59:
60: public boolean isSingleton() {
61: return true;
62: }
63:
64: public List<String> getConfigLocations() {
65: return this .configLocations;
66: }
67:
68: public void setConfigLocations(List<String> configLocations) {
69: this.configLocations = configLocations;
70: }
71:
72: }
|