Fix for Bug 308.
authorMartin Vitez <mvitez@cisco.com>
Tue, 21 Jan 2014 09:08:25 +0000 (10:08 +0100)
committerMartin Vitez <mvitez@cisco.com>
Tue, 21 Jan 2014 09:17:17 +0000 (10:17 +0100)
Fixed searching in context by qname instead of local name.
Fixed SchemaNodeComparator.
Updated child nodes storing in implementations.

Change-Id: I5c47fea79b227b3351ab558fca93671308af566c
Signed-off-by: Martin Vitez <mvitez@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend
code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/augment-abstract-topology@2013-05-03.yang

index 10bca49c9e9493a9d34f401c13f2fa92c95e36f6..4411c09aecbe8057a247483f66efa8f2d7230008 100644 (file)
@@ -738,8 +738,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         checkState(augSchema.targetPath !== null,
             "Augmentation Schema does not contain Target Path (Target Path is NULL).");
 
-        processUsesAugments(augSchema, module);
-\r
+        processUsesAugments(augSchema, module);\r
         val targetPath = augSchema.targetPath;
         var targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);\r
         if (targetSchemaNode instanceof DataSchemaNode && (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
@@ -756,7 +755,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         }\r
 \r
         if (targetSchemaNode == null) {\r
-            throw new IllegalArgumentException("augment target not found")\r
+            throw new IllegalArgumentException("augment target not found: " + targetPath)\r
         }\r
 
         if (targetSchemaNode !== null) {
@@ -804,10 +803,10 @@ public class BindingGeneratorImpl implements BindingGenerator {
             return null
         }
 
-        var String currentName = node.QName.localName\r
+        var QName currentName = node.QName\r
         var Object currentNode = node
         var Object parent = node;\r
-        val tmpPath = new ArrayList<String>()\r
+        val tmpPath = new ArrayList<QName>()\r
         val tmpTree = new ArrayList<SchemaNode>()\r
 
         var AugmentationSchema augment = null;
@@ -823,7 +822,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 tmpTree.add(currentNode as SchemaNode)\r
                 augment = findNodeInAugment((parent as AugmentationTarget).availableAugmentations, currentName);
                 if (augment == null) {
-                    currentName = (parent as DataSchemaNode).QName.localName;\r
+                    currentName = (parent as DataSchemaNode).QName\r
                     currentNode = parent
                 }
             }
@@ -838,12 +837,12 @@ public class BindingGeneratorImpl implements BindingGenerator {
             var DataSchemaNode result = null;
             for (name : tmpPath) {
                 if (actualParent instanceof DataNodeContainer) {
-                    result = (actualParent as DataNodeContainer).getDataChildByName(name);
-                    actualParent = (actualParent as DataNodeContainer).getDataChildByName(name);
+                    result = (actualParent as DataNodeContainer).getDataChildByName(name.localName);
+                    actualParent = (actualParent as DataNodeContainer).getDataChildByName(name.localName);
                 } else {
                     if (actualParent instanceof ChoiceNode) {
-                        result = (actualParent as ChoiceNode).getCaseNodeByName(name);
-                        actualParent = (actualParent as ChoiceNode).getCaseNodeByName(name);
+                        result = (actualParent as ChoiceNode).getCaseNodeByName(name.localName);
+                        actualParent = (actualParent as ChoiceNode).getCaseNodeByName(name.localName);
                     }
                 }
             }
@@ -856,9 +855,10 @@ public class BindingGeneratorImpl implements BindingGenerator {
         }
     }
 
-    private def AugmentationSchema findNodeInAugment(Collection<AugmentationSchema> augments, String name) {
-        for (augment : augments) {
-            if (augment.getDataChildByName(name) != null) {
+    private def AugmentationSchema findNodeInAugment(Collection<AugmentationSchema> augments, QName name) {
+        for (augment : augments) {\r
+            val DataSchemaNode node = augment.getDataChildByName(name);\r
+            if (node != null) {
                 return augment;
             }
         }
@@ -884,8 +884,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
             return result\r
         } else {\r
             var DataSchemaNode result = null;\r
-            var String currentName = node.QName.localName\r
-            var tmpPath = new ArrayList<String>()\r
+            var QName currentName = node.QName\r
+            var tmpPath = new ArrayList<QName>()\r
             var Object parent = null\r
 
             val SchemaPath sp = node.path
@@ -900,13 +900,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 val dataNodeParent = parent as DataNodeContainer;\r
                 for (u : dataNodeParent.uses) {\r
                     if (result == null) {\r
-                        result = getResultFromUses(u, currentName)\r
+                        result = getResultFromUses(u, currentName.localName)\r
                     }\r
                 }\r
                 if (result == null) {
-                    currentName = (parent as SchemaNode).QName.localName
-                    if (parent instanceof DataSchemaNode) {
-                        val SchemaPath nodeSp = (parent as DataSchemaNode).path
+                    currentName = (parent as SchemaNode).QName
+                    if (parent instanceof SchemaNode) {
+                        val SchemaPath nodeSp = (parent as SchemaNode).path
                         val List<QName> nodeNames = nodeSp.path
                         val List<QName> nodeNewNames = new ArrayList(nodeNames)
                         nodeNewNames.remove(nodeNewNames.size - 1)
@@ -933,8 +933,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
         List<SchemaNode> dataTree) {\r
 \r
         var DataSchemaNode result = null;
-        var String currentName = node.QName.localName
-        var tmpPath = new ArrayList<String>()\r
+        var QName currentName = node.QName
+        var tmpPath = new ArrayList<QName>()\r
         tmpPath.add(currentName)\r
         var int i = 1;\r
         var Object parent = null
@@ -944,18 +944,18 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 parent = parentNode
             } else {
                 parent = dataTree.get(dataTree.size - (i+1))
-                tmpPath.add((parent as SchemaNode).QName.localName);
+                tmpPath.add((parent as SchemaNode).QName)
             }\r
 
             val dataNodeParent = parent as DataNodeContainer;
             for (u : dataNodeParent.uses) {
                 if (result == null) {\r
-                    result = getResultFromUses(u, currentName)
+                    result = getResultFromUses(u, currentName.localName)
                 }
             }
             if (result == null) {
                 i = i + 1\r
-                currentName = (parent as SchemaNode).QName.localName
+                currentName = (parent as SchemaNode).QName
             }
         } while (result == null);
 \r
@@ -974,7 +974,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return gr.getDataChildByName(currentName)
     }\r
 \r
-    private def getTargetNode(List<String> tmpPath, DataSchemaNode node) {
+    private def getTargetNode(List<QName> tmpPath, DataSchemaNode node) {
         var DataSchemaNode result = node
         if (tmpPath.size == 1) {
             if (result != null && result.addedByUses) {
@@ -986,8 +986,9 @@ public class BindingGeneratorImpl implements BindingGenerator {
             Collections.reverse(tmpPath);
 
             tmpPath.remove(0);
-            for (name : tmpPath) {
-                newParent = (newParent as DataNodeContainer).getDataChildByName(name);
+            for (name : tmpPath) {\r
+                // searching by local name is must, because node has different namespace in its original location
+                newParent = (newParent as DataNodeContainer).getDataChildByName(name.localName);
             }
             if (newParent != null && newParent.addedByUses) {
                 newParent = findOriginal(newParent);
index c9c368d536f7616042cba649259ef66d4c80e21f..fd15dce839a16e782064bddba774ea5de9c15ba9 100644 (file)
@@ -52,7 +52,7 @@ module augment-abstract-topology {
 
                 leaf tunnel-id {
                     type leafref {
-                        path "../../../link-id";
+                        path "../../../at:link-id";
                     }
                 }
             }