1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.config.property; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.core.framework.config.property.SimpleConfig; |
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.util.Comparator; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.Map; |
26 | |
import java.util.Properties; |
27 | |
import java.util.Set; |
28 | |
import java.util.SortedSet; |
29 | |
import java.util.TreeSet; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
@Deprecated |
37 | |
public class ConfigParserImplConfig extends SimpleConfig { |
38 | 0 | private static final Logger LOG = Logger.getLogger(ConfigParserImplConfig.class); |
39 | |
|
40 | |
public ConfigParserImplConfig(String fileLoc) { |
41 | 0 | super(fileLoc); |
42 | 0 | } |
43 | |
|
44 | |
public ConfigParserImplConfig(Properties properties) { |
45 | 0 | super(properties); |
46 | 0 | } |
47 | |
|
48 | |
protected void parseWithConfigParserImpl() throws IOException { |
49 | 0 | ConfigParserImpl cp = new ConfigParserImpl(); |
50 | 0 | Map p = new Properties(); |
51 | 0 | p.putAll(getProperties()); |
52 | 0 | cp.parse(p, fileLocs.toArray(new String[fileLocs.size()])); |
53 | 0 | putPropertiesInPropsUsed(p, StringUtils.join(fileLocs, ", ")); |
54 | 0 | } |
55 | |
|
56 | |
protected void putPropertiesInPropsUsed(Map properties, String fileName) { |
57 | |
|
58 | 0 | Map<String, String> safeConfig = ConfigLogger.getDisplaySafeConfig(properties); |
59 | 0 | if ( LOG.isInfoEnabled() ) { |
60 | 0 | LOG.info("Loading properties for config " + fileName); |
61 | |
} |
62 | 0 | for (Iterator iterator2 = properties.entrySet().iterator(); iterator2.hasNext();) { |
63 | 0 | Map.Entry configProp = (Map.Entry) iterator2.next(); |
64 | 0 | String key = (String) configProp.getKey(); |
65 | 0 | String value = (String) configProp.getValue(); |
66 | 0 | String safeValue = safeConfig.get(key); |
67 | 0 | if ( LOG.isDebugEnabled() ) { |
68 | 0 | LOG.debug("---->Putting config Prop " + key + "=[" + safeValue + "]"); |
69 | |
} |
70 | 0 | this.propertiesUsed.put(key, value); |
71 | 0 | } |
72 | 0 | } |
73 | |
|
74 | |
public void parseConfig() throws IOException { |
75 | 0 | if ( LOG.isInfoEnabled() ) { |
76 | 0 | LOG.info("Loading Rice configs: " + StringUtils.join(fileLocs, ", ")); |
77 | |
} |
78 | 0 | Map<String, Object> baseObjects = getBaseObjects(); |
79 | 0 | if (baseObjects != null) { |
80 | 0 | this.getObjects().putAll(baseObjects); |
81 | |
} |
82 | 0 | configureBuiltIns(getProperties()); |
83 | 0 | Properties baseProperties = getBaseProperties(); |
84 | 0 | if (baseProperties != null) { |
85 | 0 | this.getProperties().putAll(baseProperties); |
86 | |
} |
87 | |
|
88 | 0 | parseWithConfigParserImpl(); |
89 | |
|
90 | |
|
91 | |
|
92 | 0 | if ( LOG.isInfoEnabled() ) { |
93 | 0 | LOG.info(""); |
94 | 0 | LOG.info("####################################"); |
95 | 0 | LOG.info("#"); |
96 | 0 | LOG.info("# Properties used after config override/replacement"); |
97 | 0 | LOG.info("# " + StringUtils.join(fileLocs, ", ")); |
98 | 0 | LOG.info("#"); |
99 | 0 | LOG.info("####################################"); |
100 | 0 | LOG.info(""); |
101 | |
} |
102 | 0 | Map<String, String> safePropsUsed = ConfigLogger.getDisplaySafeConfig(this.propertiesUsed); |
103 | 0 | Set<Map.Entry<String,String>> entrySet = safePropsUsed.entrySet(); |
104 | |
|
105 | |
SortedSet<Map.Entry<String,String>> |
106 | 0 | sorted = new TreeSet<Map.Entry<String,String>>(new Comparator<Map.Entry<String,String>>() { |
107 | |
public int compare(Map.Entry<String,String> a, Map.Entry<String,String> b) { |
108 | 0 | return a.getKey().compareTo(b.getKey()); |
109 | |
} |
110 | |
}); |
111 | 0 | sorted.addAll(entrySet); |
112 | |
|
113 | 0 | if ( LOG.isInfoEnabled() ) { |
114 | 0 | for (Map.Entry<String, String> propUsed: sorted) { |
115 | 0 | LOG.info("Using config Prop " + propUsed.getKey() + "=[" + propUsed.getValue() + "]"); |
116 | |
} |
117 | |
} |
118 | 0 | } |
119 | |
} |