Projects moved under correct parent.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / impl / YangParserImpl.java
@@ -14,6 +14,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -893,7 +894,7 @@ public final class YangParserImpl implements YangModelParser {
             }
 
             // child nodes
-            processUsesNode(usesNode, targetGrouping);
+            processUsesNode(module, usesNode, targetGrouping);
         }
     }
 
@@ -942,7 +943,7 @@ public final class YangParserImpl implements YangModelParser {
                     usesNode.addRefineNode(nodeToRefine);
                 }
 
-                processUsesNode(usesNode, targetGroupingBuilder);
+                processUsesNode(module, usesNode, targetGroupingBuilder);
             }
         }
     }
@@ -1056,19 +1057,34 @@ public final class YangParserImpl implements YangModelParser {
      * Add nodes defined in target grouping to current context. Refinement has
      * to be already performed.
      *
+     * @param module current module
      * @param usesNode
      * @param targetGrouping
      */
-    private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
+    private void processUsesNode(final ModuleBuilder module, final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
         List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
         DataNodeContainerBuilder parent = usesNode.getParent();
+        URI namespace = null;
+        Date revision = null;
+        String prefix = null;
+        if (parent instanceof ModuleBuilder || parent instanceof AugmentationSchemaBuilder) {
+            namespace = module.getNamespace();
+            revision = module.getRevision();
+            prefix = module.getPrefix();
+        } else {
+            QName parentQName = parent.getQName();
+            namespace = parentQName.getNamespace();
+            revision = parentQName.getRevision();
+            prefix = parentQName.getPrefix();
+        }
         SchemaPath parentPath = parent.getPath();
         for (DataSchemaNodeBuilder child : targetGrouping.getChildNodeBuilders()) {
             if (child != null) {
                 // if node is refined, take it from refined nodes and continue
                 SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
                 if (refined != null) {
-                    refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+                    refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName(), namespace,
+                            revision, prefix));
                     parent.addChildNode((DataSchemaNodeBuilder) refined);
                     continue;
                 }
@@ -1097,20 +1113,22 @@ public final class YangParserImpl implements YangModelParser {
                     ((GroupingMember) newChild).setAddedByUses(true);
                 }
 
-                newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+                newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName(), namespace, revision,
+                        prefix));
                 parent.addChildNode(newChild);
             }
         }
         for (GroupingBuilder g : targetGrouping.getGroupingBuilders()) {
             GroupingBuilder newGrouping = new GroupingBuilderImpl(g);
             newGrouping.setAddedByUses(true);
-            newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+            newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName(), namespace,
+                    revision, prefix));
             parent.addGrouping(newGrouping);
         }
         for (TypeDefinitionBuilder td : targetGrouping.getTypeDefinitionBuilders()) {
             TypeDefinitionBuilder newType = new TypeDefinitionBuilderImpl(td);
             newType.setAddedByUses(true);
-            newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+            newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName(), namespace, revision, prefix));
             parent.addTypedef(newType);
         }
         for (UsesNodeBuilder un : targetGrouping.getUses()) {
@@ -1122,7 +1140,7 @@ public final class YangParserImpl implements YangModelParser {
         for (UnknownSchemaNodeBuilder un : targetGrouping.getUnknownNodeBuilders()) {
             UnknownSchemaNodeBuilder newUn = new UnknownSchemaNodeBuilder(un);
             newUn.setAddedByUses(true);
-            newUn.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+            newUn.setPath(createSchemaPath(parentPath, un.getQName().getLocalName(), namespace, revision, prefix));
             parent.addUnknownNodeBuilder(newUn);
         }
     }
@@ -1132,13 +1150,28 @@ public final class YangParserImpl implements YangModelParser {
         final int line = usesNode.getLine();
         List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
         DataNodeContainerBuilder parent = usesNode.getParent();
+        URI namespace = null;
+        Date revision = null;
+        String prefix = null;
+        if (parent instanceof ModuleBuilder) {
+            ModuleBuilder module = (ModuleBuilder) parent;
+            namespace = module.getNamespace();
+            revision = module.getRevision();
+            prefix = module.getPrefix();
+        } else {
+            QName parentQName = parent.getQName();
+            namespace = parentQName.getNamespace();
+            revision = parentQName.getRevision();
+            prefix = parentQName.getPrefix();
+        }
         SchemaPath parentPath = parent.getPath();
         for (DataSchemaNode child : targetGrouping.getChildNodes()) {
             if (child != null) {
                 // if node is refined, take it from refined nodes and continue
                 SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
                 if (refined != null) {
-                    refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+                    refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName(), namespace,
+                            revision, prefix));
                     parent.addChildNode((DataSchemaNodeBuilder) refined);
                     continue;
                 }
@@ -1166,20 +1199,22 @@ public final class YangParserImpl implements YangModelParser {
                 if (newChild instanceof GroupingMember) {
                     ((GroupingMember) newChild).setAddedByUses(true);
                 }
-                newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+                newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName(), namespace, revision,
+                        prefix));
                 parent.addChildNode(newChild);
             }
         }
         for (GroupingDefinition g : targetGrouping.getGroupings()) {
             GroupingBuilder newGrouping = createGrouping(g, moduleName, line);
             newGrouping.setAddedByUses(true);
-            newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+            newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName(), namespace,
+                    revision, prefix));
             parent.addGrouping(newGrouping);
         }
         for (TypeDefinition<?> td : targetGrouping.getTypeDefinitions()) {
             TypeDefinitionBuilder newType = createTypedef((ExtendedType) td, moduleName, line);
             newType.setAddedByUses(true);
-            newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+            newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName(), namespace, revision, prefix));
             parent.addTypedef(newType);
         }
         for (UsesNode un : targetGrouping.getUses()) {
@@ -1193,7 +1228,7 @@ public final class YangParserImpl implements YangModelParser {
         for (UnknownSchemaNode un : targetGrouping.getUnknownSchemaNodes()) {
             UnknownSchemaNodeBuilder newNode = createUnknownSchemaNode(un, moduleName, line);
             newNode.setAddedByUses(true);
-            newNode.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+            newNode.setPath(createSchemaPath(parentPath, un.getQName().getLocalName(), namespace, revision, prefix));
             parent.addUnknownNodeBuilder(newNode);
         }
     }