3a81061881439af327be8c5291d7c015cdd4abc2
[controller.git] / opendaylight / config / config-api / src / main / java / org / opendaylight / controller / config / stat / ConfigProvider.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
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
9 package org.opendaylight.controller.config.stat;
10
11 import org.osgi.framework.BundleContext;
12
13 /**
14  * Subset of {@link org.osgi.framework.BundleContext}
15  */
16 public interface ConfigProvider {
17     /**
18      * Returns the value of the specified property. If the key is not found in
19      * the Framework properties, the system properties are then searched. The
20      * method returns {@code null} if the property is not found.
21      *
22      * <p>
23      * All bundles must have permission to read properties whose names start
24      * with &quot;org.osgi.&quot;.
25      *
26      * @param key
27      *            The name of the requested property.
28      * @return The value of the requested property, or {@code null} if the
29      *         property is undefined.
30      * @throws SecurityException
31      *             If the caller does not have the appropriate
32      *             {@code PropertyPermission} to read the property, and the Java
33      *             Runtime Environment supports permissions.
34      */
35     String getProperty(String key);
36
37     public static class ConfigProviderImpl implements ConfigProvider {
38         private final BundleContext context;
39
40         public ConfigProviderImpl(BundleContext context) {
41             this.context = context;
42         }
43
44         @Override
45         public String getProperty(String key) {
46             return context.getProperty(key);
47         }
48
49         @Override
50         public String toString() {
51             return "ConfigProviderImpl{" + "context=" + context + '}';
52         }
53     }
54
55 }