Fix checkstyle warnings in yang-jmx-generator.
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / ServiceInterfaceEntry.java
index 71cd0900eb6f985521257cc552faead563f8eba1..f03bd96529a728921bd656a5998bb4be2f79868c 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static java.lang.String.format;
 import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.SERVICE_TYPE_Q_NAME;
 
+import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -18,7 +19,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -26,8 +26,6 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-
 /**
  * Represents identity derived from {@link ConfigConstants#SERVICE_TYPE_Q_NAME}.
  * Example:
@@ -49,7 +47,7 @@ import com.google.common.base.Optional;
  * </p>
  */
 public class ServiceInterfaceEntry extends AbstractEntry {
-    private static final Logger logger = LoggerFactory
+    private static final Logger LOG = LoggerFactory
             .getLogger(ServiceInterfaceEntry.class);
 
     private static final String CLASS_NAME_SUFFIX = "ServiceInterface";
@@ -57,13 +55,14 @@ public class ServiceInterfaceEntry extends AbstractEntry {
     private final String exportedOsgiClassName;
     private final QName qName;
     private final String nullableDescription, packageName, typeName;
+    private final QName yangModuleQName;
 
-    private ServiceInterfaceEntry(IdentitySchemaNode id, String packageName) {
-        this(Optional.<ServiceInterfaceEntry> absent(), id, packageName);
+    private ServiceInterfaceEntry(IdentitySchemaNode id, String packageName, QName yangModuleQName) {
+        this(Optional.<ServiceInterfaceEntry> absent(), id, packageName, yangModuleQName);
     }
 
     private ServiceInterfaceEntry(Optional<ServiceInterfaceEntry> base,
-            IdentitySchemaNode id, String packageName) {
+            IdentitySchemaNode id, String packageName, QName yangModuleQName) {
         checkNotNull(base);
         this.maybeBaseCache = base;
         List<UnknownSchemaNode> unknownSchemaNodes = id.getUnknownSchemaNodes();
@@ -93,6 +92,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         nullableDescription = id.getDescription();
         typeName = getSimpleName(exportedOsgiClassName) + CLASS_NAME_SUFFIX;
         this.packageName = packageName;
+        this.yangModuleQName = yangModuleQName;
     }
 
     private static final String getSimpleName(String fullyQualifiedName) {
@@ -120,18 +120,18 @@ public class ServiceInterfaceEntry extends AbstractEntry {
      * @return Map of QNames as keys and ServiceInterfaceEntry instances as
      *         values
      */
-    public static Map<QName, ServiceInterfaceEntry> create(Module module,
-            String packageName) {
-        logger.debug("Generating ServiceInterfaces from {} to package {}",
-                module.getNamespace(), packageName);
+    public static Map<QName, ServiceInterfaceEntry> create(Module currentModule,
+            String packageName,Map<IdentitySchemaNode, ServiceInterfaceEntry> definedSEItracker) {
+        LOG.debug("Generating ServiceInterfaces from {} to package {}",
+                currentModule.getNamespace(), packageName);
 
         Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
         Set<IdentitySchemaNode> notVisited = new HashSet<>(
-                module.getIdentities());
+                currentModule.getIdentities());
         int lastSize = notVisited.size() + 1;
-        while (notVisited.size() > 0) {
+        while (!notVisited.isEmpty()) {
             if (notVisited.size() == lastSize) {
-                logger.debug(
+                LOG.debug(
                         "Following identities will be ignored while generating ServiceInterfaces, as they are not derived from {} : {}",
                         SERVICE_TYPE_Q_NAME, notVisited);
                 break;
@@ -148,22 +148,25 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                 } else if (identity.getBaseIdentity().getQName()
                         .equals(SERVICE_TYPE_Q_NAME)) {
                     // this is a base type
-                    created = new ServiceInterfaceEntry(identity, packageName);
+                    created = new ServiceInterfaceEntry(identity, packageName, ModuleUtil.getQName(currentModule));
                 } else {
-                    ServiceInterfaceEntry foundBase = identitiesToSIs
+                    ServiceInterfaceEntry foundBase = definedSEItracker
                             .get(identity.getBaseIdentity());
                     // derived type, did we convert the parent?
                     if (foundBase != null) {
                         created = new ServiceInterfaceEntry(
-                                Optional.of(foundBase), identity, packageName);
+                                Optional.of(foundBase), identity, packageName, ModuleUtil.getQName(currentModule));
                     }
                 }
+
+
                 if (created != null) {
-                    created.setYangModuleName(module.getName());
+                    created.setYangModuleName(currentModule.getName());
                     // TODO how to get local name
                     created.setYangModuleLocalname(identity.getQName()
                             .getLocalName());
                     identitiesToSIs.put(identity, created);
+                    definedSEItracker.put(identity, created);
                     iterator.remove();
                 }
             }
@@ -173,7 +176,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         for (ServiceInterfaceEntry sie : identitiesToSIs.values()) {
             resultMap.put(sie.getQName(), sie);
         }
-        logger.debug("Number of ServiceInterfaces to be generated: {}",
+        LOG.debug("Number of ServiceInterfaces to be generated: {}",
                 resultMap.size());
         return resultMap;
     }
@@ -190,27 +193,39 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         return typeName;
     }
 
+    public QName getYangModuleQName() {
+        return yangModuleQName;
+    }
+
     @Override
     public boolean equals(Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        if (o == null || getClass() != o.getClass())
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
+        }
 
         ServiceInterfaceEntry that = (ServiceInterfaceEntry) o;
 
-        if (!maybeBaseCache.equals(that.maybeBaseCache))
+        if (!maybeBaseCache.equals(that.maybeBaseCache)) {
             return false;
-        if (!nullableDescription.equals(that.nullableDescription))
+        }
+        if (!nullableDescription.equals(that.nullableDescription)) {
             return false;
-        if (!exportedOsgiClassName.equals(that.exportedOsgiClassName))
+        }
+        if (!exportedOsgiClassName.equals(that.exportedOsgiClassName)) {
             return false;
-        if (!qName.equals(that.qName))
+        }
+        if (!qName.equals(that.qName)) {
             return false;
-        if (!packageName.equals(that.packageName))
+        }
+        if (!packageName.equals(that.packageName)) {
             return false;
-        if (!typeName.equals(that.typeName))
+        }
+        if (!typeName.equals(that.typeName)) {
             return false;
+        }
 
         return true;
     }