Bug 8153: Enforce check-style rules for netconf - netconf-util
[netconf.git] / netconf / netconf-util / src / main / java / org / opendaylight / netconf / util / osgi / NetconfConfigUtil.java
index 63bec7c525362593537c2dd2b48824ec73f15613..64537f336fc96ce49408a02633c0d761cf813cec 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.netconf.util.osgi;
 
 import java.util.Collection;
-import java.util.Optional;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -21,22 +20,22 @@ public final class NetconfConfigUtil {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigUtil.class);
 
     private NetconfConfigUtil() {
+        throw new AssertionError("Utility class should not be instantiated");
     }
 
-    public static Optional<NetconfConfiguration> getNetconfConfigurationService(BundleContext bundleContext) {
-        final Collection<ServiceReference<ManagedService>> serviceReferences;
-        try {
-            serviceReferences = bundleContext.getServiceReferences(ManagedService.class, null);
-            for (final ServiceReference<ManagedService> serviceReference : serviceReferences) {
-                ManagedService service = bundleContext.getService(serviceReference);
-                if (service instanceof NetconfConfiguration){
-                    return Optional.of((NetconfConfiguration) service);
-                }
+    public static NetconfConfiguration getNetconfConfigurationService(BundleContext bundleContext)
+            throws InvalidSyntaxException {
+        LOG.debug("Trying to retrieve netconf configuration service");
+        final Collection<ServiceReference<ManagedService>> serviceReferences
+                = bundleContext.getServiceReferences(ManagedService.class, null);
+        for (final ServiceReference<ManagedService> serviceReference : serviceReferences) {
+            ManagedService service = bundleContext.getService(serviceReference);
+            if (service instanceof NetconfConfiguration) {
+                LOG.debug("Netconf configuration service found");
+                return (NetconfConfiguration) service;
             }
-        } catch (InvalidSyntaxException e) {
-            LOG.error("Unable to retrieve references for ManagedService: {}", e);
         }
-        LOG.error("Unable to retrieve NetconfConfiguration service. Not found. Bundle netconf-util probably failed to load.");
-        return Optional.empty();
+
+        throw new IllegalStateException("Netconf configuration service not found");
     }
 }