Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / ServiceInterfaceEntry.java
index f03bd96529a728921bd656a5998bb4be2f79868c..d7a806568054e8c05c025c78813106c309067637 100644 (file)
@@ -44,7 +44,6 @@ import org.slf4j.LoggerFactory;
  * </pre>
  *
  * </blockquote>
- * </p>
  */
 public class ServiceInterfaceEntry extends AbstractEntry {
     private static final Logger LOG = LoggerFactory
@@ -56,23 +55,27 @@ public class ServiceInterfaceEntry extends AbstractEntry {
     private final QName qName;
     private final String nullableDescription, packageName, typeName;
     private final QName yangModuleQName;
+    private final boolean registerToOsgi;
 
-    private ServiceInterfaceEntry(IdentitySchemaNode id, String packageName, QName yangModuleQName) {
+    private ServiceInterfaceEntry(final IdentitySchemaNode id, final String packageName, final QName yangModuleQName) {
         this(Optional.<ServiceInterfaceEntry> absent(), id, packageName, yangModuleQName);
     }
 
-    private ServiceInterfaceEntry(Optional<ServiceInterfaceEntry> base,
-            IdentitySchemaNode id, String packageName, QName yangModuleQName) {
+    private ServiceInterfaceEntry(final Optional<ServiceInterfaceEntry> base,
+            final IdentitySchemaNode id, final String packageName, final QName yangModuleQName) {
         checkNotNull(base);
         this.maybeBaseCache = base;
         List<UnknownSchemaNode> unknownSchemaNodes = id.getUnknownSchemaNodes();
         List<String> exportedOsgiClassNames = new ArrayList<>(
                 unknownSchemaNodes.size());
+
+        boolean disableOsgiServiceRegistration = false;
         for (UnknownSchemaNode usn : unknownSchemaNodes) {
-            if (ConfigConstants.JAVA_CLASS_EXTENSION_QNAME.equals(usn
-                    .getNodeType())) {
+            if (ConfigConstants.JAVA_CLASS_EXTENSION_QNAME.equals(usn.getNodeType())) {
                 String localName = usn.getNodeParameter();
                 exportedOsgiClassNames.add(localName);
+            } else if (ConfigConstants.DISABLE_OSGI_SERVICE_REG_QNAME.equals(usn.getNodeType())) {
+                disableOsgiServiceRegistration = true;
             } else {
                 throw new IllegalStateException(format(
                         "Unexpected unknown schema node. Expected %s, got %s",
@@ -87,15 +90,17 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                             getClass(),
                             ConfigConstants.JAVA_CLASS_EXTENSION_QNAME, id));
         }
+
+        this.registerToOsgi = !disableOsgiServiceRegistration;
         this.exportedOsgiClassName = exportedOsgiClassNames.get(0);
         qName = id.getQName();
-        nullableDescription = id.getDescription();
+        nullableDescription = id.getDescription().orElse(null);
         typeName = getSimpleName(exportedOsgiClassName) + CLASS_NAME_SUFFIX;
         this.packageName = packageName;
         this.yangModuleQName = yangModuleQName;
     }
 
-    private static final String getSimpleName(String fullyQualifiedName) {
+    private static final String getSimpleName(final String fullyQualifiedName) {
         int lastDotPosition = fullyQualifiedName.lastIndexOf(".");
         return fullyQualifiedName.substring(lastDotPosition + 1);
     }
@@ -116,12 +121,16 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         return qName;
     }
 
+    public boolean isRegisterToOsgi() {
+        return registerToOsgi;
+    }
+
     /**
      * @return Map of QNames as keys and ServiceInterfaceEntry instances as
      *         values
      */
-    public static Map<QName, ServiceInterfaceEntry> create(Module currentModule,
-            String packageName,Map<IdentitySchemaNode, ServiceInterfaceEntry> definedSEItracker) {
+    public static Map<QName, ServiceInterfaceEntry> create(final Module currentModule,
+            final String packageName,final Map<IdentitySchemaNode, ServiceInterfaceEntry> definedSEItracker) {
         LOG.debug("Generating ServiceInterfaces from {} to package {}",
                 currentModule.getNamespace(), packageName);
 
@@ -141,17 +150,17 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                     .hasNext();) {
                 IdentitySchemaNode identity = iterator.next();
                 ServiceInterfaceEntry created = null;
-                if (identity.getBaseIdentity() == null) {
+                if (identity.getBaseIdentities().isEmpty()) {
                     // this can happen while loading config module, just skip
                     // the identity
                     continue;
-                } else if (identity.getBaseIdentity().getQName()
+                } else if (identity.getBaseIdentities().iterator().next().getQName()
                         .equals(SERVICE_TYPE_Q_NAME)) {
                     // this is a base type
                     created = new ServiceInterfaceEntry(identity, packageName, ModuleUtil.getQName(currentModule));
                 } else {
                     ServiceInterfaceEntry foundBase = definedSEItracker
-                            .get(identity.getBaseIdentity());
+                            .get(identity.getBaseIdentities().iterator().next());
                     // derived type, did we convert the parent?
                     if (foundBase != null) {
                         created = new ServiceInterfaceEntry(
@@ -198,7 +207,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
     }
 
     @Override
-    public boolean equals(Object o) {
+    public boolean equals(final Object o) {
         if (this == o) {
             return true;
         }