1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
56 for (org.kuali.common.util.property.ProjectProperties bean : beans.values()) {
57 list.add(bean);
58 }
59
60 pps.addAll(list);
61 }
62
63
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 }