Binding codec v2 - fix augmentation #1 98/61298/31
authorJie Han <han.jie@zte.com.cn>
Tue, 8 Aug 2017 01:00:54 +0000 (09:00 +0800)
committerRobert Varga <nite@hq.sk>
Wed, 7 Feb 2018 12:24:22 +0000 (12:24 +0000)
-  Since if target node in same module as augment, data nodes are represented as-if
their statements were inlined in target. so we should process these data nodes from
binding structs to normalized nodes.

Change-Id: Ib024517f050758cadfbd016b96cf2821bc7c689c
Signed-off-by: Jie Han <han.jie@zte.com.cn>
binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/spi/source/AbstractDataNodeContainerSerializerSource.java

index 05171a46f7d137569d1ef6be9ce6cd7afb4e7f0d..fe1b9f142316746022de1761e8d9d8c23edf8f98 100755 (executable)
@@ -25,6 +25,7 @@ import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingSerializer;
 import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingStreamEventWriter;
 import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializerImplementation;
 import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializerRegistry;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -133,10 +134,25 @@ public abstract class AbstractDataNodeContainerSerializerSource extends Abstract
             JavaIdentifier.CLASS);
     }
 
+    private boolean emitCheck(final DataSchemaNode schemaChild) {
+        if (schemaChild.isAugmenting()) {
+            QName root = schemaChild.getPath().getPathFromRoot().iterator().next();
+            return root.getModule().equals(schemaChild.getQName().getModule());
+        }
+
+        return true;
+    }
+
     private void emitBody(final StringBuilder builder) {
         final Map<String, Type> getterToType = collectAllProperties(dtoType, new HashMap<String, Type>());
         for (final DataSchemaNode schemaChild : schemaNode.getChildNodes()) {
-            if (!schemaChild.isAugmenting()) {
+            /**
+             * As before, it only emitted data nodes which were not added by uses or augment, now
+             * according to binding v2 specification, augment of the same module is same as inlining,
+             * all data node children should be processed as-if they were directly defined inside
+             * target node.
+             */
+            if (emitCheck(schemaChild)) {
                 final String getter = getGetterName(schemaChild);
                 final Type childType = getterToType.get(getter);
                 if (childType == null) {