Package: ConfigurationAdminConfigurationInfo

ConfigurationAdminConfigurationInfo

nameinstructionbranchcomplexitylinemethod
ConfigurationAdminConfigurationInfo(ConfigurationAdmin, String)
M: 12 C: 23
66%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getPid()
M: 6 C: 3
33%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getProperties()
M: 6 C: 48
89%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 13
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.nano.config.internal;
13:
14: import java.io.IOException;
15: import java.util.Dictionary;
16: import java.util.Enumeration;
17: import java.util.HashMap;
18: import java.util.Map;
19:
20: import org.eclipse.virgo.nano.serviceability.NonNull;
21: import org.osgi.service.cm.Configuration;
22: import org.osgi.service.cm.ConfigurationAdmin;
23: import org.slf4j.Logger;
24: import org.slf4j.LoggerFactory;
25:
26:
27: public class ConfigurationAdminConfigurationInfo implements ConfigurationInfo {
28:
29: private final Logger logger = LoggerFactory.getLogger(this.getClass());
30:
31: private final ConfigurationAdmin configurationAdmin;
32:
33: private final String pid;
34:
35: public ConfigurationAdminConfigurationInfo(@NonNull ConfigurationAdmin configurationAdmin, String pid) {
36: this.configurationAdmin = configurationAdmin;
37: this.pid = pid;
38: }
39:
40: public String getPid() {
41: return this.pid;
42: }
43:
44: public Map<String, String> getProperties() {
45: try {
46: Configuration configuration = configurationAdmin.getConfiguration(this.pid, null);
47: Map<String, String> properties = new HashMap<String, String>();
48:
49: Dictionary<String, Object> dictionary = configuration.getProperties();
50:
51:• if (dictionary != null) {
52: Enumeration<String> keys = dictionary.keys();
53:• while (keys.hasMoreElements()) {
54: String key = keys.nextElement();
55: String value = (String)dictionary.get(key);
56: properties.put(key, value);
57: }
58: }
59: return properties;
60: } catch (IOException e) {
61: logger.warn("Unable to get configuration for {}", this.pid);
62: }
63: return null;
64: }
65:
66: }