View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import javax.servlet.ServletContext;
23  
24  import org.kuali.common.jdbc.project.spring.JdbcPropertyLocationsConfig;
25  import org.kuali.common.util.log.LoggerUtils;
26  import org.kuali.common.util.properties.Location;
27  import org.kuali.common.util.properties.PropertiesLocationService;
28  import org.kuali.common.util.properties.PropertiesService;
29  import org.kuali.common.util.properties.spring.DefaultPropertiesServiceConfig;
30  import org.kuali.common.util.properties.spring.PropertiesLocationServiceConfig;
31  import org.kuali.common.util.spring.service.PropertySourceConfig;
32  import org.kuali.rice.core.api.config.property.Config;
33  import org.kuali.rice.core.api.config.property.ConfigContext;
34  import org.kuali.rice.core.api.config.property.ConfigPropertySource;
35  import org.kuali.rice.sql.spring.SourceSqlPropertyLocationsConfig;
36  import org.kuali.rice.xml.ingest.RiceConfigUtils;
37  import org.kuali.rice.xml.spring.IngestXmlPropertyLocationsConfig;
38  import org.slf4j.Logger;
39  import org.springframework.beans.factory.annotation.Autowired;
40  import org.springframework.context.annotation.Bean;
41  import org.springframework.context.annotation.Configuration;
42  import org.springframework.context.annotation.Import;
43  import org.springframework.core.env.PropertySource;
44  
45  /**
46   * Holds the property source for all of the different properties needed for starting up the KRAD Sample App.
47   * 
48   * @author Kuali Rice Team (rice.collab@kuali.org)
49   */
50  @Configuration
51  @Import({ KradSampleAppProjectConfig.class, JdbcPropertyLocationsConfig.class, SourceSqlPropertyLocationsConfig.class, IngestXmlPropertyLocationsConfig.class,
52  		PropertiesLocationServiceConfig.class, DefaultPropertiesServiceConfig.class })
53  public class KradSampleAppPSC implements PropertySourceConfig {
54  
55  	private static final String KRAD_SAMPLE_APP_CONFIG = "classpath:META-INF/krad-sampleapp-config.xml";
56  
57  	private static final Logger logger = LoggerUtils.make();
58  
59  	@Autowired
60  	JdbcPropertyLocationsConfig jdbcConfig;
61  
62  	@Autowired
63  	SourceSqlPropertyLocationsConfig sourceSqlConfig;
64  
65  	@Autowired
66  	IngestXmlPropertyLocationsConfig ingestXmlConfig;
67  
68  	@Autowired
69  	PropertiesLocationService locationService;
70  
71  	@Autowired
72  	PropertiesService service;
73  
74  	@Autowired
75  	ServletContext servletContext;
76  
77  	@Override
78  	@Bean
79  	public PropertySource<?> propertySource() {
80  		// Combine locations making sure Rice properties go in last
81  		List<Location> locations = new ArrayList<Location>();
82  		locations.addAll(jdbcConfig.jdbcPropertyLocations());
83  		locations.addAll(sourceSqlConfig.riceSourceSqlPropertyLocations());
84  		locations.addAll(ingestXmlConfig.riceIngestXmlPropertyLocations());
85  
86  		// Default behavior is load->decrypt->resolve
87  		// -Dproperties.resolve=false turns off resolve
88  		Properties properties = service.getProperties(locations);
89  		logger.info("Loaded {} regular properties", properties.size());
90  
91  		// Combine normal properties with Rice properties using Rice's custom placeholder resolution logic to resolve everything
92  		Config rootCfg = RiceConfigUtils.getRootConfig(properties, KRAD_SAMPLE_APP_CONFIG, servletContext);
93  
94  		// Make sure ConfigContext.getCurrentContextConfig() return's this rootCfg object
95  		ConfigContext.init(rootCfg);
96  
97  		// Make Spring and Rice use the exact same source for obtaining property values
98  		return new ConfigPropertySource("riceConfig", rootCfg);
99  	}
100 
101 }