2 * Copyright (c) 2014, 2016 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.utils.config;
11 import java.util.HashMap;
14 import org.osgi.framework.Bundle;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.FrameworkUtil;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public final class ConfigProperties {
21 private static final Logger LOG = LoggerFactory.getLogger(ConfigProperties.class);
22 private static final Map<String, String> OVERRIDES = new HashMap<>();
24 private ConfigProperties() {
28 public static String getProperty(Class<?> classParam, final String propertyStr) {
29 return getProperty(classParam, propertyStr, null);
32 public static String getProperty(Class<?> classParam, final String propertyStr, final String defaultValue) {
33 String value = ConfigProperties.OVERRIDES.get(propertyStr);
38 Bundle bundle = FrameworkUtil.getBundle(classParam);
41 BundleContext bundleContext = bundle.getBundleContext();
42 if (bundleContext != null) {
43 value = bundleContext.getProperty(propertyStr);
47 value = System.getProperty(propertyStr, defaultValue);
51 LOG.debug("ConfigProperties missing a value for {}, default {}", propertyStr, defaultValue);
57 public static void overrideProperty(String property, String value) {
58 ConfigProperties.OVERRIDES.put(property, value);