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 org.osgi.framework.BundleContext;
13 import org.osgi.framework.InvalidSyntaxException;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.service.cm.ManagedService;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public final class NetconfConfigUtil {
20 private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigUtil.class);
22 private NetconfConfigUtil() {
23 throw new AssertionError("Utility class should not be instantiated");
26 public static NetconfConfiguration getNetconfConfigurationService(BundleContext bundleContext)
27 throws InvalidSyntaxException {
28 LOG.debug("Trying to retrieve netconf configuration service");
29 final Collection<ServiceReference<ManagedService>> serviceReferences
30 = bundleContext.getServiceReferences(ManagedService.class, null);
31 for (final ServiceReference<ManagedService> serviceReference : serviceReferences) {
32 ManagedService service = bundleContext.getService(serviceReference);
33 if (service instanceof NetconfConfiguration) {
34 LOG.debug("Netconf configuration service found");
35 return (NetconfConfiguration) service;
39 throw new IllegalStateException("Netconf configuration service not found");