2 * Copyright (c) 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.odlparent.bundlestest;
10 import java.util.Arrays;
11 import java.util.Collections;
12 import java.util.HashMap;
13 import java.util.List;
15 import java.util.stream.Collectors;
16 import org.osgi.framework.ServiceReference;
19 * Utilities for OSGi's {@link ServiceReference}.
21 * @author Michael Vorburger.ch
23 public class ServiceReferenceUtil {
25 public Map<String, Object> getProperties(ServiceReference<?> serviceRef) {
26 String[] propertyKeys = serviceRef.getPropertyKeys();
27 Map<String, Object> properties = new HashMap<>(propertyKeys.length);
28 for (String propertyKey : propertyKeys) {
29 Object propertyValue = serviceRef.getProperty(propertyKey);
30 if (propertyValue.getClass().isArray()) {
31 propertyValue = Arrays.asList((Object[]) propertyValue);
33 properties.put(propertyKey, propertyValue);
38 public List<String> getUsingBundleSymbolicNames(ServiceReference<?> serviceRef) {
39 if (serviceRef.getUsingBundles() == null) {
40 return Collections.emptyList();
42 return Arrays.asList(serviceRef.getUsingBundles()).stream()
43 .map(bundle -> bundle.getSymbolicName()).collect(Collectors.toList());