Jian Li
Committed by Gerrit Code Review

Refactor getIntegerProperty and isPropertyEnabled methods into Tools

- Add getIntegerProperty and isPropertyEnabled methods which take
  default value as third parameter
- Remove all duplicated code from RefactiveForwarding, GroupManager,
  FlowRuleManager, CoreManager, HostLocationProvider and ProxyArp

Change-Id: Ifc93aa813acfdd4cbac0166497d7b526b08b2090
...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.onlab.packet.Ethernet; 25 import org.onlab.packet.Ethernet;
26 import org.onlab.packet.ICMP6; 26 import org.onlab.packet.ICMP6;
27 import org.onlab.packet.IPv6; 27 import org.onlab.packet.IPv6;
28 +import org.onlab.util.Tools;
28 import org.onosproject.cfg.ComponentConfigService; 29 import org.onosproject.cfg.ComponentConfigService;
29 import org.onosproject.core.ApplicationId; 30 import org.onosproject.core.ApplicationId;
30 import org.onosproject.core.CoreService; 31 import org.onosproject.core.CoreService;
...@@ -40,7 +41,6 @@ import org.slf4j.Logger; ...@@ -40,7 +41,6 @@ import org.slf4j.Logger;
40 41
41 import java.util.Dictionary; 42 import java.util.Dictionary;
42 43
43 -import static com.google.common.base.Strings.isNullOrEmpty;
44 import static org.onlab.packet.Ethernet.TYPE_ARP; 44 import static org.onlab.packet.Ethernet.TYPE_ARP;
45 import static org.onlab.packet.Ethernet.TYPE_IPV6; 45 import static org.onlab.packet.Ethernet.TYPE_IPV6;
46 import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT; 46 import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT;
...@@ -173,7 +173,7 @@ public class ProxyArp { ...@@ -173,7 +173,7 @@ public class ProxyArp {
173 Dictionary<?, ?> properties = context.getProperties(); 173 Dictionary<?, ?> properties = context.getProperties();
174 Boolean flag; 174 Boolean flag;
175 175
176 - flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery"); 176 + flag = Tools.isPropertyEnabled(properties, "ipv6NeighborDiscovery");
177 if (flag == null) { 177 if (flag == null) {
178 log.info("IPv6 Neighbor Discovery is not configured, " + 178 log.info("IPv6 Neighbor Discovery is not configured, " +
179 "using current value of {}", ipv6NeighborDiscovery); 179 "using current value of {}", ipv6NeighborDiscovery);
...@@ -185,26 +185,6 @@ public class ProxyArp { ...@@ -185,26 +185,6 @@ public class ProxyArp {
185 } 185 }
186 186
187 /** 187 /**
188 - * Check property name is defined and set to true.
189 - *
190 - * @param properties properties to be looked up
191 - * @param propertyName the name of the property to look up
192 - * @return value when the propertyName is defined or return null
193 - */
194 - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
195 - String propertyName) {
196 - Boolean value = null;
197 - try {
198 - String s = (String) properties.get(propertyName);
199 - value = isNullOrEmpty(s) ? null : s.trim().equals("true");
200 - } catch (ClassCastException e) {
201 - // No propertyName defined.
202 - value = null;
203 - }
204 - return value;
205 - }
206 -
207 - /**
208 * Packet processor responsible for forwarding packets along their paths. 188 * Packet processor responsible for forwarding packets along their paths.
209 */ 189 */
210 private class ProxyArpProcessor implements PacketProcessor { 190 private class ProxyArpProcessor implements PacketProcessor {
......
...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
26 import org.onlab.metrics.MetricsService; 26 import org.onlab.metrics.MetricsService;
27 import org.onlab.util.SharedExecutors; 27 import org.onlab.util.SharedExecutors;
28 +import org.onlab.util.Tools;
28 import org.onosproject.app.ApplicationService; 29 import org.onosproject.app.ApplicationService;
29 import org.onosproject.cfg.ComponentConfigService; 30 import org.onosproject.cfg.ComponentConfigService;
30 import org.onosproject.core.ApplicationId; 31 import org.onosproject.core.ApplicationId;
...@@ -48,9 +49,9 @@ import java.util.List; ...@@ -48,9 +49,9 @@ import java.util.List;
48 import java.util.Set; 49 import java.util.Set;
49 50
50 import static com.google.common.base.Preconditions.checkNotNull; 51 import static com.google.common.base.Preconditions.checkNotNull;
51 -import static com.google.common.base.Strings.isNullOrEmpty;
52 import static org.onosproject.security.AppGuard.checkPermission; 52 import static org.onosproject.security.AppGuard.checkPermission;
53 -import static org.onosproject.security.AppPermission.Type.*; 53 +import static org.onosproject.security.AppPermission.Type.APP_READ;
54 +import static org.onosproject.security.AppPermission.Type.APP_WRITE;
54 55
55 56
56 /** 57 /**
...@@ -172,7 +173,7 @@ public class CoreManager implements CoreService { ...@@ -172,7 +173,7 @@ public class CoreManager implements CoreService {
172 @Modified 173 @Modified
173 public void modified(ComponentContext context) { 174 public void modified(ComponentContext context) {
174 Dictionary<?, ?> properties = context.getProperties(); 175 Dictionary<?, ?> properties = context.getProperties();
175 - Integer poolSize = getIntegerProperty(properties, "sharedThreadPoolSize"); 176 + Integer poolSize = Tools.getIntegerProperty(properties, "sharedThreadPoolSize");
176 177
177 if (poolSize != null && poolSize > 1) { 178 if (poolSize != null && poolSize > 1) {
178 sharedThreadPoolSize = poolSize; 179 sharedThreadPoolSize = poolSize;
...@@ -181,7 +182,7 @@ public class CoreManager implements CoreService { ...@@ -181,7 +182,7 @@ public class CoreManager implements CoreService {
181 log.warn("sharedThreadPoolSize must be greater than 1"); 182 log.warn("sharedThreadPoolSize must be greater than 1");
182 } 183 }
183 184
184 - Integer timeLimit = getIntegerProperty(properties, "maxEventTimeLimit"); 185 + Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit");
185 if (timeLimit != null && timeLimit > 1) { 186 if (timeLimit != null && timeLimit > 1) {
186 maxEventTimeLimit = timeLimit; 187 maxEventTimeLimit = timeLimit;
187 eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit); 188 eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit);
...@@ -189,7 +190,7 @@ public class CoreManager implements CoreService { ...@@ -189,7 +190,7 @@ public class CoreManager implements CoreService {
189 log.warn("maxEventTimeLimit must be greater than 1"); 190 log.warn("maxEventTimeLimit must be greater than 1");
190 } 191 }
191 192
192 - Boolean performanceCheck = isPropertyEnabled(properties, "sharedThreadPerformanceCheck"); 193 + Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
193 if (performanceCheck != null) { 194 if (performanceCheck != null) {
194 calculatePoolPerformance = performanceCheck; 195 calculatePoolPerformance = performanceCheck;
195 SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService); 196 SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService);
...@@ -198,48 +199,4 @@ public class CoreManager implements CoreService { ...@@ -198,48 +199,4 @@ public class CoreManager implements CoreService {
198 log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}", 199 log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}",
199 sharedThreadPoolSize, maxEventTimeLimit, calculatePoolPerformance); 200 sharedThreadPoolSize, maxEventTimeLimit, calculatePoolPerformance);
200 } 201 }
201 -
202 -
203 - /**
204 - * Get Integer property from the propertyName
205 - * Return null if propertyName is not found.
206 - *
207 - * @param properties properties to be looked up
208 - * @param propertyName the name of the property to look up
209 - * @return value when the propertyName is defined or return null
210 - */
211 - private static Integer getIntegerProperty(Dictionary<?, ?> properties,
212 - String propertyName) {
213 - Integer value;
214 - try {
215 - String s = (String) properties.get(propertyName);
216 - value = isNullOrEmpty(s) ? null : Integer.parseInt(s.trim());
217 - } catch (NumberFormatException | ClassCastException e) {
218 - value = null;
219 - }
220 - return value;
221 - }
222 -
223 - /**
224 - * Check property name is defined and set to true.
225 - *
226 - * @param properties properties to be looked up
227 - * @param propertyName the name of the property to look up
228 - * @return value when the propertyName is defined or return null
229 - */
230 - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
231 - String propertyName) {
232 - Boolean value = null;
233 - try {
234 - String s = (String) properties.get(propertyName);
235 - value = isNullOrEmpty(s) ? null : s.trim().equals("true");
236 - } catch (ClassCastException e) {
237 - // No propertyName defined.
238 - value = null;
239 - }
240 - return value;
241 - }
242 -
243 -
244 -
245 } 202 }
......
...@@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.Property; ...@@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.Property;
29 import org.apache.felix.scr.annotations.Reference; 29 import org.apache.felix.scr.annotations.Reference;
30 import org.apache.felix.scr.annotations.ReferenceCardinality; 30 import org.apache.felix.scr.annotations.ReferenceCardinality;
31 import org.apache.felix.scr.annotations.Service; 31 import org.apache.felix.scr.annotations.Service;
32 +import org.onlab.util.Tools;
32 import org.onosproject.cfg.ComponentConfigService; 33 import org.onosproject.cfg.ComponentConfigService;
33 import org.onosproject.core.ApplicationId; 34 import org.onosproject.core.ApplicationId;
34 import org.onosproject.core.CoreService; 35 import org.onosproject.core.CoreService;
...@@ -190,7 +191,7 @@ public class FlowRuleManager ...@@ -190,7 +191,7 @@ public class FlowRuleManager
190 Dictionary<?, ?> properties = context.getProperties(); 191 Dictionary<?, ?> properties = context.getProperties();
191 Boolean flag; 192 Boolean flag;
192 193
193 - flag = isPropertyEnabled(properties, "allowExtraneousRules"); 194 + flag = Tools.isPropertyEnabled(properties, "allowExtraneousRules");
194 if (flag == null) { 195 if (flag == null) {
195 log.info("AllowExtraneousRules is not configured, " + 196 log.info("AllowExtraneousRules is not configured, " +
196 "using current value of {}", allowExtraneousRules); 197 "using current value of {}", allowExtraneousRules);
...@@ -200,7 +201,7 @@ public class FlowRuleManager ...@@ -200,7 +201,7 @@ public class FlowRuleManager
200 allowExtraneousRules ? "enabled" : "disabled"); 201 allowExtraneousRules ? "enabled" : "disabled");
201 } 202 }
202 203
203 - flag = isPropertyEnabled(properties, "purgeOnDisconnection"); 204 + flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
204 if (flag == null) { 205 if (flag == null) {
205 log.info("PurgeOnDisconnection is not configured, " + 206 log.info("PurgeOnDisconnection is not configured, " +
206 "using current value of {}", purgeOnDisconnection); 207 "using current value of {}", purgeOnDisconnection);
...@@ -218,24 +219,6 @@ public class FlowRuleManager ...@@ -218,24 +219,6 @@ public class FlowRuleManager
218 } 219 }
219 } 220 }
220 221
221 - /**
222 - * Check property name is defined and set to true.
223 - *
224 - * @param properties properties to be looked up
225 - * @param propertyName the name of the property to look up
226 - * @return value when the propertyName is defined or return null
227 - */
228 - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
229 - String propertyName) {
230 - try {
231 - String s = (String) properties.get(propertyName);
232 - return isNullOrEmpty(s) ? null : s.trim().equals("true");
233 - } catch (ClassCastException e) {
234 - // No propertyName defined.
235 - return null;
236 - }
237 - }
238 -
239 @Override 222 @Override
240 public int getFlowRuleCount() { 223 public int getFlowRuleCount() {
241 checkPermission(FLOWRULE_READ); 224 checkPermission(FLOWRULE_READ);
......
...@@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Property; ...@@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Property;
23 import org.apache.felix.scr.annotations.Reference; 23 import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
26 +import org.onlab.util.Tools;
26 import org.onosproject.cfg.ComponentConfigService; 27 import org.onosproject.cfg.ComponentConfigService;
27 -import org.onosproject.net.provider.AbstractListenerProviderRegistry;
28 import org.onosproject.core.ApplicationId; 28 import org.onosproject.core.ApplicationId;
29 import org.onosproject.net.DeviceId; 29 import org.onosproject.net.DeviceId;
30 import org.onosproject.net.device.DeviceEvent; 30 import org.onosproject.net.device.DeviceEvent;
...@@ -45,6 +45,7 @@ import org.onosproject.net.group.GroupService; ...@@ -45,6 +45,7 @@ import org.onosproject.net.group.GroupService;
45 import org.onosproject.net.group.GroupStore; 45 import org.onosproject.net.group.GroupStore;
46 import org.onosproject.net.group.GroupStore.UpdateType; 46 import org.onosproject.net.group.GroupStore.UpdateType;
47 import org.onosproject.net.group.GroupStoreDelegate; 47 import org.onosproject.net.group.GroupStoreDelegate;
48 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
48 import org.onosproject.net.provider.AbstractProviderService; 49 import org.onosproject.net.provider.AbstractProviderService;
49 import org.osgi.service.component.ComponentContext; 50 import org.osgi.service.component.ComponentContext;
50 import org.slf4j.Logger; 51 import org.slf4j.Logger;
...@@ -53,10 +54,10 @@ import java.util.Collection; ...@@ -53,10 +54,10 @@ import java.util.Collection;
53 import java.util.Collections; 54 import java.util.Collections;
54 import java.util.Dictionary; 55 import java.util.Dictionary;
55 56
56 -import static com.google.common.base.Strings.isNullOrEmpty;
57 import static org.onosproject.security.AppGuard.checkPermission; 57 import static org.onosproject.security.AppGuard.checkPermission;
58 +import static org.onosproject.security.AppPermission.Type.GROUP_READ;
59 +import static org.onosproject.security.AppPermission.Type.GROUP_WRITE;
58 import static org.slf4j.LoggerFactory.getLogger; 60 import static org.slf4j.LoggerFactory.getLogger;
59 -import static org.onosproject.security.AppPermission.Type.*;
60 61
61 62
62 63
...@@ -129,7 +130,7 @@ public class GroupManager ...@@ -129,7 +130,7 @@ public class GroupManager
129 Dictionary<?, ?> properties = context.getProperties(); 130 Dictionary<?, ?> properties = context.getProperties();
130 Boolean flag; 131 Boolean flag;
131 132
132 - flag = isPropertyEnabled(properties, "purgeOnDisconnection"); 133 + flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
133 if (flag == null) { 134 if (flag == null) {
134 log.info("PurgeOnDisconnection is not configured, " + 135 log.info("PurgeOnDisconnection is not configured, " +
135 "using current value of {}", purgeOnDisconnection); 136 "using current value of {}", purgeOnDisconnection);
...@@ -141,26 +142,6 @@ public class GroupManager ...@@ -141,26 +142,6 @@ public class GroupManager
141 } 142 }
142 143
143 /** 144 /**
144 - * Check property name is defined and set to true.
145 - *
146 - * @param properties properties to be looked up
147 - * @param propertyName the name of the property to look up
148 - * @return value when the propertyName is defined or return null
149 - */
150 - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
151 - String propertyName) {
152 - Boolean value = null;
153 - try {
154 - String s = (String) properties.get(propertyName);
155 - value = isNullOrEmpty(s) ? null : s.trim().equals("true");
156 - } catch (ClassCastException e) {
157 - // No propertyName defined.
158 - value = null;
159 - }
160 - return value;
161 - }
162 -
163 - /**
164 * Create a group in the specified device with the provided parameters. 145 * Create a group in the specified device with the provided parameters.
165 * 146 *
166 * @param groupDesc group creation parameters 147 * @param groupDesc group creation parameters
......
...@@ -35,6 +35,7 @@ import org.onlab.packet.ndp.NeighborAdvertisement; ...@@ -35,6 +35,7 @@ import org.onlab.packet.ndp.NeighborAdvertisement;
35 import org.onlab.packet.ndp.NeighborSolicitation; 35 import org.onlab.packet.ndp.NeighborSolicitation;
36 import org.onlab.packet.ndp.RouterAdvertisement; 36 import org.onlab.packet.ndp.RouterAdvertisement;
37 import org.onlab.packet.ndp.RouterSolicitation; 37 import org.onlab.packet.ndp.RouterSolicitation;
38 +import org.onlab.util.Tools;
38 import org.onosproject.cfg.ComponentConfigService; 39 import org.onosproject.cfg.ComponentConfigService;
39 import org.onosproject.core.ApplicationId; 40 import org.onosproject.core.ApplicationId;
40 import org.onosproject.core.CoreService; 41 import org.onosproject.core.CoreService;
...@@ -69,7 +70,6 @@ import java.util.Dictionary; ...@@ -69,7 +70,6 @@ import java.util.Dictionary;
69 import java.util.Set; 70 import java.util.Set;
70 import java.util.concurrent.ExecutorService; 71 import java.util.concurrent.ExecutorService;
71 72
72 -import static com.google.common.base.Strings.isNullOrEmpty;
73 import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; 73 import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
74 import static org.onlab.util.Tools.groupedThreads; 74 import static org.onlab.util.Tools.groupedThreads;
75 import static org.slf4j.LoggerFactory.getLogger; 75 import static org.slf4j.LoggerFactory.getLogger;
...@@ -228,7 +228,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -228,7 +228,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
228 Dictionary<?, ?> properties = context.getProperties(); 228 Dictionary<?, ?> properties = context.getProperties();
229 Boolean flag; 229 Boolean flag;
230 230
231 - flag = isPropertyEnabled(properties, "hostRemovalEnabled"); 231 + flag = Tools.isPropertyEnabled(properties, "hostRemovalEnabled");
232 if (flag == null) { 232 if (flag == null) {
233 log.info("Host removal on port/device down events is not configured, " + 233 log.info("Host removal on port/device down events is not configured, " +
234 "using current value of {}", hostRemovalEnabled); 234 "using current value of {}", hostRemovalEnabled);
...@@ -238,7 +238,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -238,7 +238,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
238 hostRemovalEnabled ? "enabled" : "disabled"); 238 hostRemovalEnabled ? "enabled" : "disabled");
239 } 239 }
240 240
241 - flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery"); 241 + flag = Tools.isPropertyEnabled(properties, "ipv6NeighborDiscovery");
242 if (flag == null) { 242 if (flag == null) {
243 log.info("Using IPv6 Neighbor Discovery is not configured, " + 243 log.info("Using IPv6 Neighbor Discovery is not configured, " +
244 "using current value of {}", ipv6NeighborDiscovery); 244 "using current value of {}", ipv6NeighborDiscovery);
...@@ -248,7 +248,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -248,7 +248,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
248 ipv6NeighborDiscovery ? "enabled" : "disabled"); 248 ipv6NeighborDiscovery ? "enabled" : "disabled");
249 } 249 }
250 250
251 - flag = isPropertyEnabled(properties, "requestInterceptsEnabled"); 251 + flag = Tools.isPropertyEnabled(properties, "requestInterceptsEnabled");
252 if (flag == null) { 252 if (flag == null) {
253 log.info("Request intercepts is not configured, " + 253 log.info("Request intercepts is not configured, " +
254 "using current value of {}", requestInterceptsEnabled); 254 "using current value of {}", requestInterceptsEnabled);
...@@ -259,26 +259,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -259,26 +259,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
259 } 259 }
260 } 260 }
261 261
262 - /**
263 - * Check property name is defined and set to true.
264 - *
265 - * @param properties properties to be looked up
266 - * @param propertyName the name of the property to look up
267 - * @return value when the propertyName is defined or return null
268 - */
269 - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
270 - String propertyName) {
271 - Boolean value = null;
272 - try {
273 - String s = (String) properties.get(propertyName);
274 - value = isNullOrEmpty(s) ? null : s.trim().equals("true");
275 - } catch (ClassCastException e) {
276 - // No propertyName defined.
277 - value = null;
278 - }
279 - return value;
280 - }
281 -
282 @Override 262 @Override
283 public void triggerProbe(Host host) { 263 public void triggerProbe(Host host) {
284 log.info("Triggering probe on device {}", host); 264 log.info("Triggering probe on device {}", host);
......
...@@ -275,6 +275,84 @@ public abstract class Tools { ...@@ -275,6 +275,84 @@ public abstract class Tools {
275 } 275 }
276 276
277 /** 277 /**
278 + * Get Integer property from the propertyName
279 + * Return null if propertyName is not found.
280 + *
281 + * @param properties properties to be looked up
282 + * @param propertyName the name of the property to look up
283 + * @return value when the propertyName is defined or return null
284 + */
285 + public static Integer getIntegerProperty(Dictionary<?, ?> properties,
286 + String propertyName) {
287 + Integer value;
288 + try {
289 + String s = get(properties, propertyName);
290 + value = Strings.isNullOrEmpty(s) ? null : Integer.valueOf(s);
291 + } catch (NumberFormatException | ClassCastException e) {
292 + value = null;
293 + }
294 + return value;
295 + }
296 +
297 + /**
298 + * Get Integer property from the propertyName
299 + * Return default value if propertyName is not found.
300 + *
301 + * @param properties properties to be looked up
302 + * @param propertyName the name of the property to look up
303 + * @param defaultValue the default value that to be assigned
304 + * @return value when the propertyName is defined or return default value
305 + */
306 + public static int getIntegerProperty(Dictionary<?, ?> properties,
307 + String propertyName,
308 + int defaultValue) {
309 + try {
310 + String s = get(properties, propertyName);
311 + return Strings.isNullOrEmpty(s) ? defaultValue : Integer.valueOf(s);
312 + } catch (NumberFormatException | ClassCastException e) {
313 + return defaultValue;
314 + }
315 + }
316 +
317 + /**
318 + * Check property name is defined and set to true.
319 + *
320 + * @param properties properties to be looked up
321 + * @param propertyName the name of the property to look up
322 + * @return value when the propertyName is defined or return null
323 + */
324 + public static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
325 + String propertyName) {
326 + Boolean value;
327 + try {
328 + String s = get(properties, propertyName);
329 + value = Strings.isNullOrEmpty(s) ? null : Boolean.valueOf(s);
330 + } catch (ClassCastException e) {
331 + value = null;
332 + }
333 + return value;
334 + }
335 +
336 + /**
337 + * Check property name is defined as set to true.
338 + *
339 + * @param properties properties to be looked up
340 + * @param propertyName the name of the property to look up
341 + * @param defaultValue the default value that to be assigned
342 + * @return value when the propertyName is defined or return the default value
343 + */
344 + public static boolean isPropertyEnabled(Dictionary<?, ?> properties,
345 + String propertyName,
346 + boolean defaultValue) {
347 + try {
348 + String s = get(properties, propertyName);
349 + return Strings.isNullOrEmpty(s) ? defaultValue : Boolean.valueOf(s);
350 + } catch (ClassCastException e) {
351 + return defaultValue;
352 + }
353 + }
354 +
355 + /**
278 * Suspends the current thread for a specified number of millis. 356 * Suspends the current thread for a specified number of millis.
279 * 357 *
280 * @param ms number of millis 358 * @param ms number of millis
......