Binding generator v2 - Notifications 20/58220/1
authorMartin Ciglan <martin.ciglan@pantheon.tech>
Tue, 30 May 2017 12:17:01 +0000 (14:17 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Mon, 5 Jun 2017 06:07:19 +0000 (06:07 +0000)
- generated Java code compilability fixes

Change-Id: I82e1f59820820c1d6717fc4227031e7d33465cab
Signed-off-by: Martin Ciglan <martin.ciglan@pantheon.tech>
(cherry picked from commit 138cdec6a16b8663d0f9670c8aef7457925109c3)

binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/impl/ModuleToGenType.java
binding2/mdsal-binding2-generator-util/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/util/BindingTypes.java
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/BuilderRenderer.java
binding2/mdsal-binding2-java-api-generator/src/main/twirl/org/opendaylight/mdsal/binding/javav2/java/api/generator/builderTemplate.scala.txt
binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/NotificationListener.java [new file with mode: 0644]

index 9af13aa2932ff9a6a37df4dabddd92d949650ff3..23d360c97c0a2164e4bc4dbefe1eb7346ca9b578 100644 (file)
@@ -17,6 +17,7 @@ import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -151,23 +152,28 @@ final class ModuleToGenType {
 
         //YANG 1.1 allows notifications be tied to containers and lists
         final Collection<DataSchemaNode> potentials = module.getChildNodes();
+        Set<NotificationDefinition> tiedNotifications = null;
 
         for (final DataSchemaNode potential : potentials) {
             if (potential instanceof NotificationNodeContainer) {
-                final Set<NotificationDefinition> tiedNotifications = ((NotificationNodeContainer) potential)
+                tiedNotifications = ((NotificationNodeContainer) potential)
                         .getNotifications();
                 for (final NotificationDefinition tiedNotification: tiedNotifications) {
                     if (tiedNotification != null) {
                         resolveNotification(listenerInterface, potential.getQName().getLocalName(), basePackageName,
                                 tiedNotification, module, schemaContext, verboseClassComments, genTypeBuilders,
                                 typeProvider, genCtx);
-                        notifications.add(tiedNotification);
                     }
                 }
             }
         }
 
-        listenerInterface.setDescription(createDescription(notifications, module, verboseClassComments));
+        if (tiedNotifications != null) {
+            listenerInterface.setDescription(createDescription(ImmutableSet.<NotificationDefinition>builder()
+                .addAll(notifications).addAll(tiedNotifications).build(), module, verboseClassComments));
+        } else {
+            listenerInterface.setDescription(createDescription(notifications, module, verboseClassComments));
+        }
 
         genCtx.get(module).addTopLevelNodeType(listenerInterface);
 
index 09328e26c292eb517968ffd4e55798f6937ef89e..b69a30c597f3e2efcd916cecb4a4e0246bb17e72 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.mdsal.binding.javav2.generator.util;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.parameterizedTypeFor;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.typeForClass;
 
-import javax.management.NotificationListener;
 import org.opendaylight.mdsal.binding.javav2.model.api.ConcreteType;
 import org.opendaylight.mdsal.binding.javav2.model.api.ParameterizedType;
 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
@@ -29,6 +28,7 @@ import org.opendaylight.mdsal.binding.javav2.spec.base.Rpc;
 import org.opendaylight.mdsal.binding.javav2.spec.base.RpcCallback;
 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeRoot;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.NotificationListener;
 import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
 import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
 import org.opendaylight.mdsal.binding.javav2.spec.structural.TreeChildNode;
index 53a7b94899aa1523160519d2b88b989dc1e5318e..8fae7f7fa7dfef24d458a229384710a10253d197 100644 (file)
@@ -240,7 +240,7 @@ public class BuilderRenderer extends BaseRenderer {
 
     @Override
     protected String body() {
-        String parentTypeForBuilderName;
+        final String parentTypeForBuilderName;
         importedNames.put("genType", importedName(getType()));
         importedNames.put("objects", importedName(Objects.class));
         importedNames.put("object", importedName(Object.class));
@@ -252,9 +252,11 @@ public class BuilderRenderer extends BaseRenderer {
         if (getType().getParentType() != null) {
             importedNames.put("parent", importedName(getType().getParentType()));
             parentTypeForBuilderName = getType().getParentType().getName();
-        } else {
+        } else if (getType().getParentTypeForBuilder() != null) {
             importedNames.put("parentTypeForBuilder", importedName(getType().getParentTypeForBuilder()));
             parentTypeForBuilderName = getType().getParentTypeForBuilder().getName();
+        } else {
+            parentTypeForBuilderName = null;
         }
         importedNames.put("augmentation", importedName(Augmentation.class));
         importedNames.put("classInstMap", importedName(ClassToInstanceMap.class));
index e7f212af5a03c1cab43f160a9cba01e4e2859d38..02f012125c20a1fd03f32fc66fed9ed97892631d 100644 (file)
@@ -54,9 +54,9 @@ public class @{genType.getName}Builder implements @{getSimpleNameForBuilder} <@{
     }
 
     private static final class @{genType.getName}Impl implements @{genType.getName} {
-
+    @if(parentTypeForBuilderName != null) {
         @implementedInterfaceGetter()
-
+    }
         @generateFields(true)
 
         @generateAugmentField(true)
@@ -400,12 +400,13 @@ public class @{genType.getName}Builder implements @{getSimpleNameForBuilder} <@{
 }
 
 @generateImplementedMethods() = {
+    @if(parentTypeForBuilderName != null) {
         @@Override
         public @{importedNames.get("item")}<@{parentTypeForBuilderName}> treeIdentifier() {
             //TODO implement
             return null;
         }
-
+    }
         @@Override
         public @{importedNames.get("classInstMap")}<@{importedNames.get("augmentation")}<? super @{genType.getName}>>
         augments() {
@@ -424,6 +425,7 @@ public class @{genType.getName}Builder implements @{getSimpleNameForBuilder} <@{
             if (!(obj instanceof @{importedNames.get("treeNode")})) {
                 return false;
             }
+        @if(parentTypeForBuilderName != null) {
             if (!(obj instanceof @{importedNames.get("instantiable")})) {
                 return false;
             }
@@ -431,6 +433,7 @@ public class @{genType.getName}Builder implements @{getSimpleNameForBuilder} <@{
             .implementedInterface())) {
                 return false;
             }
+        }
             @{importedNames.get("genType")} other = (@{importedNames.get("genType")})obj;
             @for(property <- properties) {
                 @if(property.getReturnType.getName.contains("[")) {
diff --git a/binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/NotificationListener.java b/binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/NotificationListener.java
new file mode 100644 (file)
index 0000000..e08c940
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding.javav2.spec.runtime;
+
+import com.google.common.annotations.Beta;
+import java.util.EventListener;
+import org.opendaylight.mdsal.binding.javav2.spec.base.Notification;
+
+/**
+ * Marker interface for generated notification listener interfaces. This interface
+ * exists solely as support for generated code. Users should never implement this
+ * interface directly, but rather implement one of the sub-interfaces generated
+ * from a YANG model.
+ *
+ * <p>
+ * The subclasses of this interface have callbacks for events, which are derived
+ * from {@link Notification} class in form void
+ * on{NotificationType}(NotificationType notification).
+ *
+ * <p>
+ * E.g. if we have notification SessionUp the callback will have signature:
+ * <code>void onSessionUp(SessionUp notification)</code>
+ */
+@Beta
+public interface NotificationListener extends EventListener {
+}