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
8 package org.opendaylight.ovsdb.utils.config;
10 import java.util.HashMap;
12 import org.osgi.framework.Bundle;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.FrameworkUtil;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public final class ConfigProperties {
19 private static final Logger LOG = LoggerFactory.getLogger(ConfigProperties.class);
20 private static final Map<String, String> OVERRIDES = new HashMap<>();
22 private ConfigProperties() {
26 public static String getProperty(Class<?> classParam, final String propertyStr) {
27 return getProperty(classParam, propertyStr, null);
30 public static String getProperty(Class<?> classParam, final String propertyStr, final String defaultValue) {
31 String value = ConfigProperties.OVERRIDES.get(propertyStr);
36 Bundle bundle = FrameworkUtil.getBundle(classParam);
39 BundleContext bundleContext = bundle.getBundleContext();
40 if (bundleContext != null) {
41 value = bundleContext.getProperty(propertyStr);
45 value = System.getProperty(propertyStr, defaultValue);
49 LOG.debug("ConfigProperties missing a value for {}, default {}", propertyStr, defaultValue);
55 public static void overrideProperty(String property, String value) {
56 ConfigProperties.OVERRIDES.put(property, value);