001 /**
002 * Copyright 2010-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.spring;
017
018 import java.util.ArrayList;
019 import java.util.List;
020 import java.util.Map;
021 import java.util.Properties;
022
023 import org.kuali.common.util.Assert;
024 import org.kuali.common.util.FormatUtils;
025 import org.kuali.common.util.PropertyUtils;
026 import org.kuali.common.util.property.PropertiesContext;
027 import org.slf4j.Logger;
028 import org.slf4j.LoggerFactory;
029 import org.springframework.beans.factory.FactoryBean;
030 import org.springframework.util.CollectionUtils;
031
032 /**
033 * @deprecated
034 */
035 @Deprecated
036 public class ProjectPropertiesLoaderFactoryBean implements FactoryBean<Properties> {
037
038 private static final Logger logger = LoggerFactory.getLogger(ProjectPropertiesLoaderFactoryBean.class);
039
040 List<String> locations;
041 boolean singleton = true;
042 org.kuali.common.util.property.ProjectPropertiesComparator comparator;
043
044 @Override
045 public Properties getObject() {
046 Assert.isFalse(CollectionUtils.isEmpty(locations), "locations is empty");
047 long start = System.currentTimeMillis();
048 List<org.kuali.common.util.property.ProjectProperties> pps = new ArrayList<org.kuali.common.util.property.ProjectProperties>();
049 // Extract any ProjectProperties beans anywhere in the context
050 for (String location : locations) {
051 Map<String, org.kuali.common.util.property.ProjectProperties> beans = SpringUtils.getAllBeans(location, org.kuali.common.util.property.ProjectProperties.class);
052 logger.info("Located {} sets of project properties", beans.size());
053
054 List<org.kuali.common.util.property.ProjectProperties> list = new ArrayList<org.kuali.common.util.property.ProjectProperties>();
055 // Add them to a list
056 for (org.kuali.common.util.property.ProjectProperties bean : beans.values()) {
057 list.add(bean);
058 }
059 // Sort them by sequence (only relevant if there is more than one which there typically is not)
060 pps.addAll(list);
061 }
062
063 // Cycle through the list we have adding in properties as we go
064 Properties properties = new Properties();
065 for (org.kuali.common.util.property.ProjectProperties pp : pps) {
066 PropertiesContext ctx = pp.getPropertiesContext();
067 Properties combined = PropertyUtils.combine(properties, ctx.getProperties());
068 ctx.setProperties(combined);
069 Properties loaded = PropertyUtils.load(ctx);
070 properties.putAll(loaded);
071 }
072 String elapsed = FormatUtils.getTime(System.currentTimeMillis() - start);
073 logger.info("Loaded {} properties. Total time: {}", properties.size(), elapsed);
074 return properties;
075 }
076
077 @Override
078 public Class<Properties> getObjectType() {
079 return Properties.class;
080 }
081
082 @Override
083 public boolean isSingleton() {
084 return singleton;
085 }
086
087 public void setSingleton(boolean singleton) {
088 this.singleton = singleton;
089 }
090
091 public List<String> getLocations() {
092 return locations;
093 }
094
095 public void setLocations(List<String> locations) {
096 this.locations = locations;
097 }
098
099 public org.kuali.common.util.property.ProjectPropertiesComparator getComparator() {
100 return comparator;
101 }
102
103 public void setComparator(org.kuali.common.util.property.ProjectPropertiesComparator comparator) {
104 this.comparator = comparator;
105 }
106
107 }