2 * Copyright (c) 2013 Cisco Systems, 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.netconf.util.osgi;
11 import java.util.Collection;
12 import java.util.Optional;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.InvalidSyntaxException;
15 import org.osgi.framework.ServiceReference;
16 import org.osgi.service.cm.ManagedService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public final class NetconfConfigUtil {
21 private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigUtil.class);
23 private NetconfConfigUtil() {
26 public static Optional<NetconfConfiguration> getNetconfConfigurationService(BundleContext bundleContext) {
27 final Collection<ServiceReference<ManagedService>> serviceReferences;
29 serviceReferences = bundleContext.getServiceReferences(ManagedService.class, null);
30 for (final ServiceReference<ManagedService> serviceReference : serviceReferences) {
31 ManagedService service = bundleContext.getService(serviceReference);
32 if (service instanceof NetconfConfiguration){
33 return Optional.of((NetconfConfiguration) service);
36 } catch (InvalidSyntaxException e) {
37 LOG.error("Unable to retrieve references for ManagedService: {}", e);
39 LOG.error("Unable to retrieve NetconfConfiguration service. Not found. Bundle netconf-util probably failed to load.");
40 return Optional.empty();