Projects moved under correct parent.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / builder / impl / ModuleBuilder.java
@@ -85,6 +85,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         super(name, 0, null);
         this.name = name;
         instance = new ModuleImpl(name);
+        actualPath.push(this);
     }
 
     /**
@@ -379,7 +380,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         builder.setParent(parent);
 
         String groupingName = qname.getLocalName();
-        if (parent == null) {
+        if (parent.equals(this)) {
             for (GroupingBuilder addedGrouping : addedGroupings) {
                 if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
                     throw new YangParseException(name, line, "grouping with same name '" + groupingName
@@ -420,7 +421,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         Builder parent = getActualNode();
         builder.setParent(parent);
 
-        if (parent == null) {
+        if (parent.equals(this)) {
             // augment can be declared only under 'module' ...
             addedAugments.add(builder);
         } else {
@@ -448,7 +449,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         Builder parent = getActualNode();
         usesBuilder.setParent(parent);
 
-        if (parent == null) {
+        if (parent.equals(this)) {
             addedUsesNodes.add(usesBuilder);
         } else {
             if (!(parent instanceof DataNodeContainerBuilder)) {
@@ -465,21 +466,16 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
     public void addRefine(final RefineHolder refine) {
         final Builder parent = getActualNode();
-        if (parent == null) {
+        if (!(parent instanceof UsesNodeBuilder)) {
             throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
-        } else {
-            if (parent instanceof UsesNodeBuilder) {
-                ((UsesNodeBuilder) parent).addRefine(refine);
-            } else {
-                throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
-            }
-            refine.setParent(parent);
         }
+        ((UsesNodeBuilder) parent).addRefine(refine);
+        refine.setParent(parent);
     }
 
     public RpcDefinitionBuilder addRpc(final int line, final QName qname) {
         Builder parent = getActualNode();
-        if (parent != null) {
+        if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "rpc can be defined only in module or submodule");
         }
 
@@ -523,7 +519,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) {
-        final Builder parent = actualPath.getFirst();
+        final Builder parent = getActualNode();
         if (!(parent instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "output can be defined only in rpc statement");
         }
@@ -537,7 +533,8 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public NotificationBuilder addNotification(final int line, final QName qname) {
-        if (!(actualPath.isEmpty())) {
+        final Builder parent = getActualNode();
+        if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "notification can be defined only in module or submodule");
         }
 
@@ -569,7 +566,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
     public FeatureBuilder addFeature(final int line, final QName qname) {
         Builder parent = getActualNode();
-        if (parent != null) {
+        if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "feature can be defined only in module or submodule");
         }
 
@@ -598,7 +595,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
     public ChoiceCaseBuilder addCase(final int line, final QName qname) {
         Builder parent = getActualNode();
-        if (parent == null) {
+        if (parent == null || parent.equals(this)) {
             throw new YangParseException(name, line, "'case' parent not found");
         }
 
@@ -645,7 +642,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         builder.setParent(parent);
 
         String typedefName = qname.getLocalName();
-        if (parent == null) {
+        if (parent.equals(this)) {
             for (TypeDefinitionBuilder tdb : addedTypedefs) {
                 if (tdb.getQName().getLocalName().equals(typedefName)) {
                     throw new YangParseException(name, line, "typedef with same name '" + typedefName
@@ -723,7 +720,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
     public DeviationBuilder addDeviation(final int line, final String targetPath) {
         Builder parent = getActualNode();
-        if (parent != null) {
+        if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "deviation can be defined only in module or submodule");
         }
 
@@ -734,7 +731,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
     public IdentitySchemaNodeBuilder addIdentity(final QName qname, final List<String> parentPath, final int line) {
         Builder parent = getActualNode();
-        if (parent != null) {
+        if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "identity can be defined only in module or submodule");
         }
         String identityName = qname.getLocalName();
@@ -762,7 +759,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         builder.setParent(parent);
         allUnknownNodes.add(builder);
 
-        if (parent == null) {
+        if (parent.equals(this)) {
             addedUnknownNodes.add(builder);
         } else {
             if (parent instanceof SchemaNodeBuilder) {
@@ -1137,7 +1134,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
      */
     private void addChildToParent(final Builder parent, final DataSchemaNodeBuilder child, final String childName) {
         final int line = child.getLine();
-        if (parent == null) {
+        if (parent.equals(this)) {
             // if parent == null => node is defined under module
             // All leafs, leaf-lists, lists, containers, choices, rpcs,
             // notifications, and anyxmls defined within a parent node or at the