Binding codec v2 - fix augmentation #2 99/61299/34
authorJie Han <han.jie@zte.com.cn>
Tue, 8 Aug 2017 01:26:17 +0000 (09:26 +0800)
committerRobert Varga <nite@hq.sk>
Wed, 7 Feb 2018 12:24:22 +0000 (12:24 +0000)
- filter out local augments by using a child node qname of
  augment schema.
Change-Id: I475e399460e3b19cbc1691a8c0be10cd1a2e0298
Signed-off-by: Jie Han <han.jie@zte.com.cn>
binding2/mdsal-binding2-runtime/src/main/java/org/opendaylight/mdsal/binding/javav2/runtime/context/BindingRuntimeContext.java [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index c4074da..caf9fca
@@ -412,20 +412,34 @@ public class BindingRuntimeContext implements Immutable {
         }
     }
 
+    private boolean isLocalAugment(final AugmentationTarget container, final AugmentationSchemaNode augment) {
+        Preconditions.checkState(container instanceof SchemaNode);
+        final QName root = ((SchemaNode) container).getPath().getPathFromRoot().iterator().next();
+        // findFirst makes no sense but just pick up one child to judge whether the target node is
+        // in the same module.
+        final java.util.Optional<DataSchemaNode> child = augment.getChildNodes().stream().findFirst();
+        if (child.isPresent()) {
+            return root.getModule().equals(child.get().getQName().getModule());
+        }
+        return false;
+    }
+
     public ImmutableMap<AugmentationIdentifier,Type> getAvailableAugmentationTypes(final DataNodeContainer container) {
         final Map<AugmentationIdentifier,Type> identifierToType = new HashMap<>();
         if (container instanceof AugmentationTarget) {
             for (final AugmentationSchemaNode augment : ((AugmentationTarget) container).getAvailableAugmentations()) {
-                // Augmentation must have child nodes if is to be used with Binding classes
-                AugmentationSchemaNode augOrig = augment;
-                while (augOrig.getOriginalDefinition().isPresent()) {
-                    augOrig = augOrig.getOriginalDefinition().get();
-                }
+                if (!isLocalAugment((AugmentationTarget) container, augment)) {
+                    // Augmentation must have child nodes if is to be used with Binding classes
+                    AugmentationSchemaNode augOrig = augment;
+                    while (augOrig.getOriginalDefinition().isPresent()) {
+                        augOrig = augOrig.getOriginalDefinition().get();
+                    }
 
-                if (!augment.getChildNodes().isEmpty()) {
-                    final Type augType = this.typeToDefiningSchema.inverse().get(augOrig);
-                    if (augType != null) {
-                        identifierToType.put(getAugmentationIdentifier(augment),augType);
+                    if (!augment.getChildNodes().isEmpty()) {
+                        final Type augType = this.typeToDefiningSchema.inverse().get(augOrig);
+                        if (augType != null) {
+                            identifierToType.put(getAugmentationIdentifier(augment), augType);
+                        }
                     }
                 }
             }