1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.framework.config.property; |
17 | |
|
18 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.core.api.config.property.Config; |
21 | |
import org.kuali.rice.core.api.util.RiceUtilities; |
22 | |
|
23 | |
import java.io.IOException; |
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collections; |
26 | |
import java.util.HashMap; |
27 | |
import java.util.LinkedHashMap; |
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
import java.util.Properties; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class SimpleConfig extends AbstractBaseConfig { |
38 | |
|
39 | 0 | private static final Logger LOG = Logger.getLogger(SimpleConfig.class); |
40 | |
|
41 | 0 | protected Map<String, Object> configs = new LinkedHashMap<String, Object>(); |
42 | |
|
43 | |
protected final List<String> fileLocs; |
44 | |
|
45 | 0 | protected Properties propertiesUsed = new Properties(); |
46 | |
|
47 | 0 | private Map<String, Object> objects = new LinkedHashMap<String, Object>(); |
48 | |
|
49 | 0 | private Properties baseProperties = new Properties(); |
50 | |
|
51 | 0 | private Map<String, Object> baseObjects = new HashMap<String, Object>(); |
52 | |
|
53 | 0 | public SimpleConfig() { |
54 | 0 | this.fileLocs = new ArrayList<String>(); |
55 | 0 | } |
56 | |
|
57 | |
public SimpleConfig(String fileLoc) { |
58 | 0 | this(Collections.singletonList(fileLoc)); |
59 | 0 | } |
60 | |
|
61 | 0 | public SimpleConfig(List<String> fileLocs) { |
62 | 0 | this.fileLocs = fileLocs; |
63 | 0 | } |
64 | |
|
65 | |
public SimpleConfig(Properties properties) { |
66 | 0 | this(new ArrayList<String>(), properties); |
67 | 0 | } |
68 | |
|
69 | |
public SimpleConfig(String fileLoc, Properties baseProperties) { |
70 | 0 | this(Collections.singletonList(fileLoc), baseProperties); |
71 | 0 | } |
72 | |
|
73 | |
public SimpleConfig(List<String> fileLocs, Properties baseProperties) { |
74 | 0 | this(fileLocs); |
75 | 0 | this.baseProperties = baseProperties; |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
public void parseConfig() throws IOException { |
80 | 0 | throw new UnsupportedOperationException("Parsing is no longer supported by BaseConfig, please see JAXBConfigImpl instead."); |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
protected void configureBuiltIns(Properties properties) { |
87 | 0 | properties.put("host.ip", RiceUtilities.getIpNumber()); |
88 | 0 | properties.put("host.name", RiceUtilities.getHostName()); |
89 | 0 | } |
90 | |
|
91 | |
public Map<String, Object> getBaseObjects() { |
92 | 0 | return this.baseObjects; |
93 | |
} |
94 | |
|
95 | |
public Properties getBaseProperties() { |
96 | 0 | return this.baseProperties; |
97 | |
} |
98 | |
|
99 | |
public Properties getProperties() { |
100 | 0 | return this.propertiesUsed; |
101 | |
} |
102 | |
|
103 | |
public String getProperty(String key) { |
104 | 0 | return getProperties().getProperty(key); |
105 | |
} |
106 | |
|
107 | |
public Map<String, Object> getObjects() { |
108 | 0 | return this.objects; |
109 | |
} |
110 | |
|
111 | |
public Object getObject(String key) { |
112 | 0 | return getObjects().get(key); |
113 | |
} |
114 | |
|
115 | |
public void putProperties(Properties properties) { |
116 | 0 | if (properties != null) { |
117 | 0 | getProperties().putAll(properties); |
118 | |
} |
119 | 0 | } |
120 | |
|
121 | |
public void putProperty(String key, String value) { |
122 | 0 | this.getProperties().put(key, value); |
123 | 0 | } |
124 | |
|
125 | |
public void putObject(String key, Object value) { |
126 | 0 | this.getObjects().put(key, value); |
127 | 0 | } |
128 | |
|
129 | |
public void putObjects(Map<String, Object> objects) { |
130 | 0 | if(objects != null){ |
131 | 0 | this.getObjects().putAll(objects); |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | |
public void removeObject(String key){ |
136 | 0 | this.getObjects().remove(key); |
137 | 0 | } |
138 | |
|
139 | |
public void removeProperty(String key){ |
140 | 0 | this.getProperties().remove(key); |
141 | 0 | } |
142 | |
|
143 | |
public void putConfig(Config config) { |
144 | 0 | putProperties(config.getProperties()); |
145 | 0 | putObjects(config.getObjects()); |
146 | 0 | } |
147 | |
|
148 | |
public String toString() { |
149 | 0 | return new ToStringBuilder(this).append("fileLocs", fileLocs).toString(); |
150 | |
} |
151 | |
} |