Fixed few sonar warnings.
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / dependencyresolver / DependencyResolverImpl.java
index 024518ca98f43a544ec2f3f87673033914de3113..d667f13ec601e23d6b0cb77447dba63a13c9ec56 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.impl.dependencyresolver;
 
-import static java.lang.String.format;
-
 import com.google.common.base.Preconditions;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -30,12 +28,11 @@ import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry;
 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 import org.opendaylight.controller.config.manager.impl.TransactionStatus;
+import org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
-import org.opendaylight.yangtools.yang.data.impl.codec.IdentityCodec;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,15 +51,16 @@ final class DependencyResolverImpl implements DependencyResolver,
     @GuardedBy("this")
     private final Set<ModuleIdentifier> dependencies = new HashSet<>();
     private final ServiceReferenceReadableRegistry readableRegistry;
-    private final CodecRegistry codecRegistry;
+    private final BindingContextProvider bindingContextProvider;
     private final String transactionName;
     private final MBeanServer mBeanServer;
+    private Integer maxDependencyDepth;
 
     DependencyResolverImpl(ModuleIdentifier currentModule,
                            TransactionStatus transactionStatus, ModulesHolder modulesHolder,
-                           ServiceReferenceReadableRegistry readableRegistry, CodecRegistry codecRegistry,
+                           ServiceReferenceReadableRegistry readableRegistry, BindingContextProvider bindingContextProvider,
                            String transactionName, MBeanServer mBeanServer) {
-        this.codecRegistry = codecRegistry;
+        this.bindingContextProvider = bindingContextProvider;
         this.name = currentModule;
         this.transactionStatus = transactionStatus;
         this.modulesHolder = modulesHolder;
@@ -101,8 +99,8 @@ final class DependencyResolverImpl implements DependencyResolver,
         boolean hasTransaction = ObjectNameUtil
                 .getTransactionName(dependentReadOnlyON) != null;
         JmxAttributeValidationException.checkCondition(
-                hasTransaction == false,
-                format("ObjectName should not contain "
+                !hasTransaction,
+                String.format("ObjectName should not contain "
                                 + "transaction name. %s set to %s. ", jmxAttribute,
                         dependentReadOnlyON
             ), jmxAttribute
@@ -117,8 +115,8 @@ final class DependencyResolverImpl implements DependencyResolver,
 
         boolean implementsSI = foundFactory
                 .isModuleImplementingServiceInterface(expectedServiceInterface);
-        if (implementsSI == false) {
-            String message = format(
+        if (!implementsSI) {
+            String message = String.format(
                     "Found module factory does not expose expected service interface. "
                             + "Module name is %s : %s, expected service interface %s, dependent module ON %s , "
                             + "attribute %s",
@@ -159,7 +157,7 @@ final class DependencyResolverImpl implements DependencyResolver,
         }
         AutoCloseable instance = module.getInstance();
         if (instance == null) {
-            String message = format(
+            String message = String.format(
                     "Error while %s resolving instance %s. getInstance() returned null. "
                             + "Expected type %s , attribute %s", name,
                     module.getIdentifier(), expectedType, jmxAttribute
@@ -169,7 +167,7 @@ final class DependencyResolverImpl implements DependencyResolver,
         try {
             return expectedType.cast(instance);
         } catch (ClassCastException e) {
-            String message = format(
+            String message = String.format(
                     "Instance cannot be cast to expected type. Instance class is %s , "
                             + "expected type %s , attribute %s",
                     instance.getClass(), expectedType, jmxAttribute
@@ -211,11 +209,10 @@ final class DependencyResolverImpl implements DependencyResolver,
     @Override
     public <T extends BaseIdentity> Class<? extends T> resolveIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass) {
         final QName qName = QName.create(identityRef.getqNameOfIdentity());
-        IdentityCodec<?> identityCodec = codecRegistry.getIdentityCodec();
-        Class<? extends BaseIdentity> deserialized = identityCodec.deserialize(qName);
+        Class<?> deserialized  = bindingContextProvider.getBindingContext().getIdentityClass(qName);
         if (deserialized == null) {
             throw new IllegalStateException("Unable to retrieve identity class for " + qName + ", null response from "
-                    + codecRegistry);
+                    + bindingContextProvider.getBindingContext());
         }
         if (expectedBaseClass.isAssignableFrom(deserialized)) {
             return (Class<T>) deserialized;
@@ -242,8 +239,6 @@ final class DependencyResolverImpl implements DependencyResolver,
                 o.getMaxDependencyDepth());
     }
 
-    private Integer maxDependencyDepth;
-
     int getMaxDependencyDepth() {
         if (maxDependencyDepth == null) {
             throw new IllegalStateException("Dependency depth was not computed");
@@ -259,7 +254,7 @@ final class DependencyResolverImpl implements DependencyResolver,
         transactionStatus.checkCommitStarted();
         if (maxDependencyDepth == null) {
             maxDependencyDepth = getMaxDepth(this, manager,
-                    new LinkedHashSet<ModuleIdentifier>());
+                    new LinkedHashSet<>());
         }
     }
 
@@ -274,7 +269,7 @@ final class DependencyResolverImpl implements DependencyResolver,
             DependencyResolverImpl dependentDRI = manager
                     .getOrCreate(dependencyName);
             if (chainForDetectingCycles2.contains(dependencyName)) {
-                throw new IllegalStateException(format(
+                throw new IllegalStateException(String.format(
                         "Cycle detected, %s contains %s",
                         chainForDetectingCycles2, dependencyName));
             }