Codecs can handle the same yang "case" from multiple resources 08/9308/2
authorMartin Sunal <msunal@cisco.com>
Fri, 25 Jul 2014 09:39:42 +0000 (11:39 +0200)
committerMartin Sunal <msunal@cisco.com>
Fri, 25 Jul 2014 10:49:03 +0000 (12:49 +0200)
- resolves a problem when the same case statements are augmented through different paths

Change-Id: I85a0972e352556c525ab64e093e77ad33abeedba
Signed-off-by: Martin Sunal <msunal@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingSchemaContextUtils.java

index 69c67953c0ca89f6170797ab516a718f8b9d0f8f..5cb27aa0b6da4a12c516c4dc6d86aae5fbe96b4b 100644 (file)
@@ -22,6 +22,8 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -178,16 +180,31 @@ public class BindingSchemaContextUtils {
         return Optional.absent();
     }
 
-    public static Optional<ChoiceCaseNode> findInstantiatedCase(final ChoiceNode instantiatedChoice, final ChoiceCaseNode schema) {
-        ChoiceCaseNode potential = instantiatedChoice.getCaseNodeByName(schema.getQName());
+    public static Optional<ChoiceCaseNode> findInstantiatedCase(final ChoiceNode instantiatedChoice, final ChoiceCaseNode originalDefinition) {
+        ChoiceCaseNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName());
+        if(originalDefinition.equals(potential)) {
+            return Optional.of(potential);
+        }
         if (potential != null) {
+            SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential);
+            if (originalDefinition.equals(potentialRoot)) {
+                return Optional.of(potential);
+            }
+        }
+        // We try to find case by name, then lookup its root definition
+        // and compare it with original definition
+        // This solves case, if choice was inside grouping
+        // which was used in different module and thus namespaces are
+        // different, but local names are still same.
+        // 
+        // Still we need to check equality of definition, because local name is not
+        // sufficient to uniquelly determine equality of cases
+        //
+        potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName().getLocalName());
+        if(potential != null && (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential)))) {
             return Optional.of(potential);
         }
-        // FIXME: Probably requires more extensive check
-        // e.g. we have one choice and two augmentations from different
-        // modules using same local name
-        // but different namespace / contents
-        return Optional.fromNullable(instantiatedChoice.getCaseNodeByName(schema.getQName().getLocalName()));
+        return Optional.absent();
     }
 
 }