View Javadoc

1   /**
2    * Copyright 2010-2013 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.common.util.spring;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import org.kuali.common.util.Assert;
24  import org.kuali.common.util.FormatUtils;
25  import org.kuali.common.util.PropertyUtils;
26  import org.kuali.common.util.property.PropertiesContext;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.springframework.beans.factory.FactoryBean;
30  import org.springframework.util.CollectionUtils;
31  
32  /**
33   * @deprecated
34   */
35  @Deprecated
36  public class ProjectPropertiesLoaderFactoryBean implements FactoryBean<Properties> {
37  
38  	private static final Logger logger = LoggerFactory.getLogger(ProjectPropertiesLoaderFactoryBean.class);
39  
40  	List<String> locations;
41  	boolean singleton = true;
42  	org.kuali.common.util.property.ProjectPropertiesComparator comparator;
43  
44  	@Override
45  	public Properties getObject() {
46  		Assert.isFalse(CollectionUtils.isEmpty(locations), "locations is empty");
47  		long start = System.currentTimeMillis();
48  		List<org.kuali.common.util.property.ProjectProperties> pps = new ArrayList<org.kuali.common.util.property.ProjectProperties>();
49  		// Extract any ProjectProperties beans anywhere in the context
50  		for (String location : locations) {
51  			Map<String, org.kuali.common.util.property.ProjectProperties> beans = SpringUtils.getAllBeans(location, org.kuali.common.util.property.ProjectProperties.class);
52  			logger.info("Located {} sets of project properties", beans.size());
53  
54  			List<org.kuali.common.util.property.ProjectProperties> list = new ArrayList<org.kuali.common.util.property.ProjectProperties>();
55  			// Add them to a list
56  			for (org.kuali.common.util.property.ProjectProperties bean : beans.values()) {
57  				list.add(bean);
58  			}
59  			// Sort them by sequence (only relevant if there is more than one which there typically is not)
60  			pps.addAll(list);
61  		}
62  
63  		// Cycle through the list we have adding in properties as we go
64  		Properties properties = new Properties();
65  		for (org.kuali.common.util.property.ProjectProperties pp : pps) {
66  			PropertiesContext ctx = pp.getPropertiesContext();
67  			Properties combined = PropertyUtils.combine(properties, ctx.getProperties());
68  			ctx.setProperties(combined);
69  			Properties loaded = PropertyUtils.load(ctx);
70  			properties.putAll(loaded);
71  		}
72  		String elapsed = FormatUtils.getTime(System.currentTimeMillis() - start);
73  		logger.info("Loaded {} properties.  Total time: {}", properties.size(), elapsed);
74  		return properties;
75  	}
76  
77  	@Override
78  	public Class<Properties> getObjectType() {
79  		return Properties.class;
80  	}
81  
82  	@Override
83  	public boolean isSingleton() {
84  		return singleton;
85  	}
86  
87  	public void setSingleton(boolean singleton) {
88  		this.singleton = singleton;
89  	}
90  
91  	public List<String> getLocations() {
92  		return locations;
93  	}
94  
95  	public void setLocations(List<String> locations) {
96  		this.locations = locations;
97  	}
98  
99  	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 }