Fix Sonar issue: Utility classes should not have a public constructor
[ovsdb.git] / utils / config / src / main / java / org / opendaylight / ovsdb / utils / config / ConfigProperties.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Flavio Fernandes, Sam Hague, Srini Seetharaman
9  */
10
11 package org.opendaylight.ovsdb.utils.config;
12
13 import org.osgi.framework.Bundle;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.FrameworkUtil;
16
17 public class ConfigProperties {
18
19     private ConfigProperties() {
20         // empty
21     }
22
23     public static String getProperty(Class<?> classParam, final String propertyStr) {
24         return getProperty(classParam, propertyStr, null);
25     }
26
27     public static String getProperty(Class<?> classParam, final String propertyStr, final String defaultValue) {
28         String value = null;
29         Bundle bundle = FrameworkUtil.getBundle(classParam);
30
31         if (bundle != null) {
32             BundleContext bundleContext = bundle.getBundleContext();
33             if (bundleContext != null) {
34                 value = bundleContext.getProperty(propertyStr);
35             }
36         }
37         if (value == null) {
38             value = System.getProperty(propertyStr, defaultValue);
39         }
40         return value;
41     }
42 }