Refactored ModuleBuilder to avoid name conflicts. Fixed implementation of ChoiceBuilder. 28/428/1
authorMartin Vitez <mvitez@cisco.com>
Tue, 4 Jun 2013 13:45:29 +0000 (15:45 +0200)
committerMartin Vitez <mvitez@cisco.com>
Tue, 4 Jun 2013 13:45:29 +0000 (15:45 +0200)
Refactored parsing of refine statement. Added tests.
Renamed ChildNodeBuilder -> DataNodeContainerBuilder.
Renamed AbstractChildNodeBuilder -> AbstractDataNodeContainerBuilder.
Renamed TypedefBuilder -> TypeDefinitionBuilderImpl.

Signed-off-by: Martin Vitez <mvitez@cisco.com>
34 files changed:
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/GenerateTest1/src/main/resources/testfile2.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractDataNodeContainerBuilder.java [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractChildNodeBuilder.java with 88% similarity]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractTypeAwareBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AugmentationSchemaBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/DataNodeContainerBuilder.java [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/ChildNodeBuilder.java with 89% similarity]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/GroupingBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/TypeAwareBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/AnyXmlBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ChoiceBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ChoiceCaseBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ContainerSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/GroupingBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/IdentityrefTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/LeafSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ListSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/NotificationBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/RpcDefinitionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/TypeDefinitionBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/TypedefBuilder.java with 96% similarity]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/UnionTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserListenerImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/ParserUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/TestUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile0.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile1.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile2.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile3.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile4.yang [new file with mode: 0644]

index 1a7b45ecb153e71d33c90036b26e14d2b1fba45d..7f7b3064f8d432f6fb24fd484955b2ed1a6f8fb8 100644 (file)
@@ -152,10 +152,7 @@ module types2 {
                     default "1.2.3.4";
                 }
                 refine port {
-                    must "must-condition" {
-                        error-message "An error message test";
-                        error-app-tag "An error app tag test";
-                    }
+                    description "new port description updated by refine";
                 }
             }
         }
@@ -12,13 +12,13 @@ import java.util.Set;
 
 import org.opendaylight.controller.yang.common.QName;
 
-public abstract class AbstractChildNodeBuilder implements ChildNodeBuilder {
+public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
 
     private final QName qname;
     protected final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
     protected final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
 
-    protected AbstractChildNodeBuilder(QName qname) {
+    protected AbstractDataNodeContainerBuilder(QName qname) {
         this.qname = qname;
     }
 
index 12acbceb025dfa80113119abf93858c2aaed087a..05ef4c5330634fd376cce90059bfeee97535f95e 100644 (file)
@@ -34,7 +34,7 @@ public abstract class AbstractTypeAwareBuilder implements TypeAwareBuilder {
     }
 
     @Override
-    public void setType(TypeDefinitionBuilder typedef) {
+    public void setTypedef(TypeDefinitionBuilder typedef) {
         this.typedef = typedef;
         this.type = null;
     }
index 4ab87df779569da46a0df87b7ca5fba8304c29cf..f99179846c160b9965dd35e0739862b3e0cbd1aa 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.controller.yang.model.api.Status;
 /**
  * Interface for builders of 'augment' statement.
  */
-public interface AugmentationSchemaBuilder extends ChildNodeBuilder {
+public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder {
 
     String getWhenCondition();
 
@@ -16,19 +16,21 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
  * Interface for all yang data-node containers [augment, case, container,
  * grouping, list, module, notification].
  */
-public interface ChildNodeBuilder extends Builder {
+public interface DataNodeContainerBuilder extends Builder {
 
     QName getQName();
 
+    Set<DataSchemaNodeBuilder> getChildNodes();
+
     void addChildNode(DataSchemaNodeBuilder childNode);
 
     void addGrouping(GroupingBuilder groupingBuilder);
 
     void addUsesNode(UsesNodeBuilder usesBuilder);
 
-    void addTypedef(TypeDefinitionBuilder typedefBuilder);
+    Set<TypeDefinitionBuilder> getTypeDefinitions();
 
-    Set<DataSchemaNodeBuilder> getChildNodes();
+    void addTypedef(TypeDefinitionBuilder typedefBuilder);
 
     SchemaPath getPath();
 
index 2c1f94da8335c9616778bf3af9115d80e54239c7..e4088a84a699e7de66d0d5385bfdbe84bb60c6bb 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBui
 /**
  * Interface for builders of 'grouping' statement.
  */
-public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder,
+public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder,
         TypeDefinitionAwareBuilder {
 
     String getDescription();
@@ -34,8 +34,6 @@ public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder,
 
     Set<GroupingBuilder> getGroupings();
 
-    Set<TypeDefinitionBuilder> getTypedefs();
-
     Set<UsesNodeBuilder> getUses();
 
 }
index 559eedb6dc869dc3e7140879ca0d2e152724ccd1..ad92b22f54e17ed26ee8a79d57b2611f88d26515 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.yang.parser.builder.api;
 
 import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 
 /**
@@ -18,12 +19,14 @@ public interface TypeAwareBuilder extends Builder {
 
     QName getQName();
 
+    SchemaPath getPath();
+
     TypeDefinition<?> getType();
 
     TypeDefinitionBuilder getTypedef();
 
     void setType(TypeDefinition<?> type);
 
-    void setType(TypeDefinitionBuilder typedef);
+    void setTypedef(TypeDefinitionBuilder typedef);
 
 }
index ba1ea9c922e4222e4fcead053f9e20f6e2e38000..d82cbe215e1e8f76233a21fb95fb52be1d971821 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
     private boolean built;
@@ -33,6 +32,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
     private String reference;
     private Status status = Status.CURRENT;
     private boolean configuration;
+    private boolean augmenting;
 
     public AnyXmlBuilder(final QName qname, final int line) {
         this.qname = qname;
@@ -50,6 +50,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
             instance.setReference(reference);
             instance.setStatus(status);
             instance.setConfiguration(configuration);
+            instance.setAugmenting(augmenting);
 
             // UNKNOWN NODES
             final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
@@ -127,8 +128,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
 
     @Override
     public void setAugmenting(final boolean augmenting) {
-        throw new YangParseException(line,
-                "An anyxml node cannot be augmented.");
+        this.augmenting = augmenting;
     }
 
     public boolean isConfiguration() {
@@ -148,6 +148,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
         private Status status = Status.CURRENT;
         private boolean configuration;
         private ConstraintDefinition constraintsDef;
+        private boolean augmenting;
         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
         private AnyXmlSchemaNodeImpl(final QName qname) {
@@ -199,7 +200,11 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
 
         @Override
         public boolean isAugmenting() {
-            return false;
+            return augmenting;
+        }
+
+        private void setAugmenting(boolean augmenting) {
+            this.augmenting = augmenting;
         }
 
         @Override
index 54f69c809ac9a97fcbe626f1ce61a530b8edd56c..e5ba8b17ccfe1f872070e491cf9c6396d8623557 100644 (file)
@@ -151,6 +151,11 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         this.whenCondition = whenCondition;
     }
 
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return Collections.emptySet();
+    }
+
     @Override
     public void addTypedef(TypeDefinitionBuilder type) {
         throw new YangParseException(line,
index e3ab0834e0cea16cc088a0c64feed69a2a214e52..a9e2b3b0feb8c09340901df26adfb6efc03a8dba 100644 (file)
@@ -23,15 +23,9 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class ChoiceBuilder implements DataSchemaNodeBuilder,
-        ChildNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationTargetBuilder {
     private boolean built;
     private final ChoiceNodeImpl instance;
     private final int line;
@@ -46,9 +40,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
     private boolean augmenting;
     private boolean configuration;
     private final ConstraintsBuilder constraints;
-    // DataNodeContainer args
-    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
-    private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
     // AugmentationTarget args
     private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
     // ChoiceNode args
@@ -109,7 +100,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         return cases;
     }
 
-    @Override
     public void addChildNode(DataSchemaNodeBuilder childNode) {
         if (!(childNode instanceof ChoiceCaseBuilder)) {
             ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(
@@ -126,31 +116,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         return qname;
     }
 
-    /**
-     * Choice can not contains grouping statements, so this method always
-     * returns an empty set.
-     *
-     * @return empty set
-     */
-    public Set<GroupingBuilder> getGroupings() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public void addGrouping(GroupingBuilder groupingBuilder) {
-        throw new YangParseException(line,
-                "Can not add grouping to 'choice' node.");
-    }
-
-    public Set<TypeDefinitionBuilder> getTypedefs() {
-        return addedTypedefs;
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        addedTypedefs.add(type);
-    }
-
     public SchemaPath getPath() {
         return schemaPath;
     }
@@ -212,15 +177,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         return constraints;
     }
 
-    public Set<UsesNodeBuilder> getUsesNodes() {
-        return addedUsesNodes;
-    }
-
-    @Override
-    public void addUsesNode(UsesNodeBuilder usesNodeBuilder) {
-        addedUsesNodes.add(usesNodeBuilder);
-    }
-
     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
         return addedUnknownNodes;
     }
@@ -247,10 +203,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         this.defaultCase = defaultCase;
     }
 
-    @Override
-    public Set<DataSchemaNodeBuilder> getChildNodes() {
-        return new HashSet<DataSchemaNodeBuilder>(cases);
-    }
 
     private final class ChoiceNodeImpl implements ChoiceNode {
         private final QName qname;
index 11a1b3114c7475d27d9e049600aa788b9d47783e..7117afe4693c9380aad602112a7350d5b6092db4 100644 (file)
@@ -19,13 +19,13 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class ChoiceCaseBuilder extends AbstractChildNodeBuilder implements
+public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements
         DataSchemaNodeBuilder {
     private final ChoiceCaseNodeImpl instance;
     private final int line;
@@ -150,6 +150,11 @@ public final class ChoiceCaseBuilder extends AbstractChildNodeBuilder implements
         addedUsesNodes.add(usesNodeBuilder);
     }
 
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return Collections.emptySet();
+    }
+
     @Override
     public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
         throw new YangParseException(line,
index 7fcdb6f8ba14a98b9340d81975af950251e47dfd..4831a2218eeeb1a5da8cacc1579fa5e272c1a77a 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
@@ -35,7 +35,7 @@ import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBu
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 
-public final class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
+public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
         implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
         DataSchemaNodeBuilder {
     private boolean isBuilt;
@@ -128,7 +128,8 @@ public final class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         return line;
     }
 
-    public Set<TypeDefinitionBuilder> getTypedefs() {
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
         return addedTypedefs;
     }
 
@@ -233,6 +234,11 @@ public final class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         addedUnknownNodes.add(unknownNode);
     }
 
+    @Override
+    public String toString() {
+        return "container " + getQName().getLocalName();
+    }
+
     private final class ContainerSchemaNodeImpl implements ContainerSchemaNode {
         private final QName qname;
         private SchemaPath path;
index bbf94408059119307396394fdbbff5e8f681b693..175910d9135b2087dd9d8e6d27c00f5314f5d236 100644 (file)
@@ -78,7 +78,7 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
     }
 
     @Override
-    public void setType(final TypeDefinitionBuilder tdb) {
+    public void setTypedef(final TypeDefinitionBuilder tdb) {
         throw new YangParseException(line, "Can not set type to " + NAME);
     }
 
index 99d4ffbe2480d7ff0783fa1bbfb68ab4382b0fca..ba9609b4db7f03eea305ae6b64bda80bc66b5fba 100644 (file)
@@ -177,6 +177,11 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder
         this.unitsStr = unitsStr;
     }
 
+    @Override
+    public String toString() {
+        return "leaf " + qname.getLocalName();
+    }
+
     private final class LeafSchemaNodeImpl implements LeafSchemaNode {
         private final QName qname;
         private SchemaPath path;
index db0e37b1e3d5983e69cb3b44a1018bb705a17be7..65839d34b1e4ccedec5a29d8b7aeba7b33aaca9e 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
@@ -35,7 +35,7 @@ import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBu
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 
-public final class ListSchemaNodeBuilder extends AbstractChildNodeBuilder
+public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
         implements DataSchemaNodeBuilder, AugmentationTargetBuilder,
         TypeDefinitionAwareBuilder {
     private boolean isBuilt;
@@ -134,7 +134,8 @@ public final class ListSchemaNodeBuilder extends AbstractChildNodeBuilder
         return line;
     }
 
-    public Set<TypeDefinitionBuilder> getTypedefs() {
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
         return addedTypedefs;
     }
 
index 0d47d7a5fc5dbd391be57e032dd387b490c8da93..6940e91e382247b384157f715d02fe4f948411fb 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -34,7 +35,7 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
@@ -61,31 +62,30 @@ public class ModuleBuilder implements Builder {
 
     private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
 
-    /**
-     * All nodes, that can contain other nodes
-     */
-    private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
-
     /**
      * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
      * list, leaf, leaf-list.
      */
-    private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
+    private final Map<List<String>, DataSchemaNodeBuilder> childNodes = new HashMap<List<String>, DataSchemaNodeBuilder>();
 
     private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
     private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();
     private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
+    //private final Map<List<String>, RefineHolder> addedRefines = new HashMap<List<String>, RefineHolder>();
     private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
     private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
     private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
     private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
-    private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
+    private final Map<List<String>, DeviationBuilder> addedDeviations = new HashMap<List<String>, DeviationBuilder>();
     private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
+    private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
     private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
     private final Set<UnknownSchemaNodeBuilder> addedUnknownNodes = new HashSet<UnknownSchemaNodeBuilder>();
 
     private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
 
+    private final LinkedList<Builder> actualPath = new LinkedList<Builder>();
+
     public ModuleBuilder(final String name) {
         this.name = name;
         instance = new ModuleImpl(name);
@@ -106,8 +106,8 @@ public class ModuleBuilder implements Builder {
         instance.setTypeDefinitions(typedefs);
 
         // CHILD NODES
-        final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
-        instance.setChildNodes(childNodes);
+        final Map<QName, DataSchemaNode> children = buildModuleChildNodes(childNodes);
+        instance.setChildNodes(children);
 
         // GROUPINGS
         final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
@@ -141,7 +141,7 @@ public class ModuleBuilder implements Builder {
 
         // DEVIATIONS
         final Set<Deviation> deviations = new HashSet<Deviation>();
-        for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
+        for (Map.Entry<List<String>, DeviationBuilder> entry : addedDeviations
                 .entrySet()) {
             deviations.add(entry.getValue().build());
         }
@@ -169,45 +169,61 @@ public class ModuleBuilder implements Builder {
         return 0;
     }
 
-    public Builder getNode(final List<String> path) {
-        return moduleNodes.get(path);
+    public void enterNode(final Builder node) {
+        actualPath.push(node);
+    }
+
+    public void exitNode() {
+        actualPath.pop();
+    }
+
+    public Builder getModuleNode(final List<String> path) {
+        return childNodes.get(path);
+    }
+
+    public GroupingBuilder getGrouping(final List<String> path) {
+        return addedGroupings.get(path);
+    }
+
+    public Builder getModuleTypedef(final List<String> path) {
+        return addedTypedefs.get(path);
     }
 
     public Set<DataSchemaNodeBuilder> getChildNodes() {
-        final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
-        for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
+        final Set<DataSchemaNodeBuilder> children = new HashSet<DataSchemaNodeBuilder>();
+        for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : childNodes
                 .entrySet()) {
-            List<String> path = entry.getKey();
-            DataSchemaNodeBuilder child = entry.getValue();
+            final List<String> path = entry.getKey();
+            final DataSchemaNodeBuilder child = entry.getValue();
             if (path.size() == 2) {
-                childNodes.add(child);
+                children.add(child);
             }
         }
-        return childNodes;
+        return children;
     }
 
     public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
         return dirtyNodes;
     }
 
-    public List<AugmentationSchemaBuilder> getAddedAugments() {
+    public List<AugmentationSchemaBuilder> getAugments() {
         return addedAugments;
     }
 
-    public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
+    public Set<IdentitySchemaNodeBuilder> getIdentities() {
         return addedIdentities;
     }
 
-    public Map<List<String>, UsesNodeBuilder> getAddedUsesNodes() {
+    public Map<List<String>, UsesNodeBuilder> getUsesNodes() {
         return addedUsesNodes;
     }
 
-    public Set<UnknownSchemaNodeBuilder> getAddedUnknownNodes() {
+    public Set<UnknownSchemaNodeBuilder> getUnknownNodes() {
         return addedUnknownNodes;
     }
 
     public Set<TypeDefinitionBuilder> getModuleTypedefs() {
-        Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
+        final Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
         for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
                 .entrySet()) {
             if (entry.getKey().size() == 2) {
@@ -247,8 +263,8 @@ public class ModuleBuilder implements Builder {
 
     public void addDirtyNode(final List<String> path) {
         final List<String> dirtyNodePath = new ArrayList<String>(path);
-        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
-                .get(dirtyNodePath);
+        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath
+                .getFirst();
         dirtyNodes.put(dirtyNodePath, nodeBuilder);
     }
 
@@ -303,18 +319,10 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
                 containerName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                containerBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(containerBuilder);
-        }
+        updateParent(containerBuilder, line, "container");
 
         pathToNode.add(containerName.getLocalName());
-        moduleNodes.put(pathToNode, containerBuilder);
-        addedChilds.put(pathToNode, containerBuilder);
+        childNodes.put(pathToNode, containerBuilder);
 
         return containerBuilder;
     }
@@ -324,18 +332,10 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
                 listName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                listBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(listBuilder);
-        }
+        updateParent(listBuilder, line, "list");
 
         pathToNode.add(listName.getLocalName());
-        moduleNodes.put(pathToNode, listBuilder);
-        addedChilds.put(pathToNode, listBuilder);
+        childNodes.put(pathToNode, listBuilder);
 
         return listBuilder;
     }
@@ -345,39 +345,23 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(
                 leafName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                leafBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(leafBuilder);
-        }
+        updateParent(leafBuilder, line, "leaf");
 
         pathToNode.add(leafName.getLocalName());
-        addedChilds.put(pathToNode, leafBuilder);
-        moduleNodes.put(pathToNode, leafBuilder);
+        childNodes.put(pathToNode, leafBuilder);
 
         return leafBuilder;
     }
 
-    public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName,
+    public LeafListSchemaNodeBuilder addLeafListNode(final QName qname,
             final List<String> parentPath, final int line) {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
-                leafListName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                leafListBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(leafListBuilder);
-        }
+                qname, line);
+        updateParent(leafListBuilder, line, "leaf-list");
 
-        pathToNode.add(leafListName.getLocalName());
-        addedChilds.put(pathToNode, leafListBuilder);
-        moduleNodes.put(pathToNode, leafListBuilder);
+        pathToNode.add(qname.getLocalName());
+        childNodes.put(pathToNode, leafListBuilder);
 
         return leafListBuilder;
     }
@@ -386,15 +370,18 @@ public class ModuleBuilder implements Builder {
             final List<String> parentPath, final int line) {
         final List<String> pathToGroup = new ArrayList<String>(parentPath);
         final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
-        final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes
-                .get(pathToGroup);
-        if (parentNodeBuilder != null) {
-            parentNodeBuilder.addGrouping(builder);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                ((DataNodeContainerBuilder) parent).addGrouping(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of grouping " + qname.getLocalName());
+            }
         }
 
-        pathToGroup.add("grouping");
         pathToGroup.add(qname.getLocalName());
-        moduleNodes.put(pathToGroup, builder);
         addedGroupings.put(pathToGroup, builder);
 
         return builder;
@@ -407,13 +394,17 @@ public class ModuleBuilder implements Builder {
                 name, line);
 
         // augment can only be in 'module' or 'uses' statement
-        final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
-        if (parent != null) {
-            parent.addAugment(builder);
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof UsesNodeBuilder) {
+                ((UsesNodeBuilder) parent).addAugment(builder);
+            } else {
+                throw new YangParseException(this.name, line,
+                        "Unresolved parent of augment " + name);
+            }
         }
 
         pathToAugment.add(name);
-        moduleNodes.put(pathToAugment, builder);
         addedAugments.add(builder);
 
         return builder;
@@ -424,34 +415,53 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToUses = new ArrayList<String>(parentPath);
         final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
                 groupingPathStr, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToUses);
-        if (parent != null) {
-            parent.addUsesNode(usesBuilder);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                if (parent instanceof AugmentationSchemaBuilder) {
+                    usesBuilder.setAugmenting(true);
+                }
+                ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of uses " + groupingPathStr);
+            }
         }
 
         pathToUses.add(groupingPathStr);
         addedUsesNodes.put(pathToUses, usesBuilder);
-        moduleNodes.put(pathToUses, usesBuilder);
         return usesBuilder;
     }
 
     public void addRefine(final RefineHolder refine,
             final List<String> parentPath) {
         final List<String> path = new ArrayList<String>(parentPath);
-        final Builder parent = moduleNodes.get(path);
-        if (!(parent instanceof UsesNodeBuilder)) {
-            throw new YangParseException("Failed to parse refine "
-                    + refine.getName());
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(name, refine.getLine(),
+                    "refine can be defined only in uses statement");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof UsesNodeBuilder) {
+                ((UsesNodeBuilder) parent).addRefine(refine);
+            } else {
+                throw new YangParseException(name, refine.getLine(),
+                        "refine can be defined only in uses statement");
+            }
         }
-        UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
-        usesBuilder.addRefine(refine);
+
         path.add(refine.getName());
-        moduleNodes.put(path, refine);
     }
 
     public RpcDefinitionBuilder addRpc(final QName qname,
             final List<String> parentPath, final int line) {
+
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "rpc can be defined only in module or submodule");
+        }
+
         final List<String> pathToRpc = new ArrayList<String>(parentPath);
         final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname,
                 line);
@@ -459,37 +469,51 @@ public class ModuleBuilder implements Builder {
         pathToRpc.add(qname.getLocalName());
         addedRpcs.put(pathToRpc, rpcBuilder);
 
-        final QName inputQName = new QName(qname.getNamespace(),
-                qname.getRevision(), qname.getPrefix(), "input");
+        return rpcBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder addRpcInput(final QName inputQName,
+            final int line) {
+        final Builder parent = actualPath.getFirst();
+        if (!(parent instanceof RpcDefinitionBuilder)) {
+            throw new YangParseException(name, line,
+                    "input can be defined only in rpc statement");
+        }
+        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+
         final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
                 inputQName, line);
-        final List<String> pathToInput = new ArrayList<String>(pathToRpc);
-        pathToInput.add("input");
-        moduleNodes.put(pathToInput, inputBuilder);
-        rpcBuilder.setInput(inputBuilder);
+        rpc.setInput(inputBuilder);
+        return inputBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder addRpcOutput(final QName outputQName,
+            final int line) {
+        final Builder parent = actualPath.getFirst();
+        if (!(parent instanceof RpcDefinitionBuilder)) {
+            throw new YangParseException(name, line,
+                    "output can be defined only in rpc statement");
+        }
+        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
 
-        final QName outputQName = new QName(qname.getNamespace(),
-                qname.getRevision(), qname.getPrefix(), "output");
         final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
                 outputQName, line);
-        final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
-        pathToOutput.add("output");
-        moduleNodes.put(pathToOutput, outputBuilder);
-        rpcBuilder.setOutput(outputBuilder);
-
-        return rpcBuilder;
+        rpc.setOutput(outputBuilder);
+        return outputBuilder;
     }
 
     public NotificationBuilder addNotification(final QName notificationName,
             final List<String> parentPath, final int line) {
-        final List<String> pathToNotification = new ArrayList<String>(
-                parentPath);
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "notification can be defined only in module or submodule");
+        }
 
-        NotificationBuilder builder = new NotificationBuilder(notificationName,
-                line);
+        final NotificationBuilder builder = new NotificationBuilder(
+                notificationName, line);
 
-        pathToNotification.add(notificationName.getLocalName());
-        moduleNodes.put(pathToNotification, builder);
+        final List<String> notificationPath = new ArrayList<String>(parentPath);
+        notificationPath.add(notificationName.getLocalName());
         addedNotifications.add(builder);
 
         return builder;
@@ -497,174 +521,237 @@ public class ModuleBuilder implements Builder {
 
     public FeatureBuilder addFeature(final QName featureName,
             final List<String> parentPath, final int line) {
-        List<String> pathToFeature = new ArrayList<String>(parentPath);
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "feature can be defined only in module or submodule");
+        }
+
+        final List<String> pathToFeature = new ArrayList<String>(parentPath);
         pathToFeature.add(featureName.getLocalName());
 
-        FeatureBuilder builder = new FeatureBuilder(featureName, line);
+        final FeatureBuilder builder = new FeatureBuilder(featureName, line);
         addedFeatures.put(pathToFeature, builder);
         return builder;
     }
 
     public ChoiceBuilder addChoice(final QName choiceName,
             final List<String> parentPath, final int line) {
-        List<String> pathToChoice = new ArrayList<String>(parentPath);
-        ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
-
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToChoice);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                builder.setAugmenting(true);
+        final List<String> pathToChoice = new ArrayList<String>(parentPath);
+        final ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
+
+        if (!(actualPath.isEmpty())) {
+            Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                if (parent instanceof AugmentationSchemaBuilder) {
+                    builder.setAugmenting(true);
+                }
+                ((DataNodeContainerBuilder) parent).addChildNode(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of choice "
+                                + choiceName.getLocalName());
             }
-            parent.addChildNode(builder);
         }
 
         pathToChoice.add(choiceName.getLocalName());
-        addedChilds.put(pathToChoice, builder);
-        moduleNodes.put(pathToChoice, builder);
+        childNodes.put(pathToChoice, builder);
 
         return builder;
     }
 
     public ChoiceCaseBuilder addCase(final QName caseName,
             final List<String> parentPath, final int line) {
-        List<String> pathToCase = new ArrayList<String>(parentPath);
-        ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
-
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToCase);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
+        final List<String> pathToCase = new ArrayList<String>(parentPath);
+        final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(name, line, "'case' parent not found");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof ChoiceBuilder) {
+                ((ChoiceBuilder) parent).addChildNode(builder);
+            } else if (parent instanceof AugmentationSchemaBuilder) {
                 builder.setAugmenting(true);
+                ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of 'case' "
+                                + caseName.getLocalName());
             }
-            parent.addChildNode(builder);
         }
 
         pathToCase.add(caseName.getLocalName());
-        moduleNodes.put(pathToCase, builder);
+        childNodes.put(pathToCase, builder);
 
         return builder;
     }
 
     public AnyXmlBuilder addAnyXml(final QName anyXmlName,
             final List<String> parentPath, final int line) {
-        List<String> pathToAnyXml = new ArrayList<String>(parentPath);
-        AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
-
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToAnyXml);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                throw new YangParseException(
-                        "An anyxml node cannot be augmented.");
-            }
-            parent.addChildNode(builder);
-        }
+        final List<String> pathToAnyXml = new ArrayList<String>(parentPath);
+        final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
+        updateParent(builder, line, "anyxml");
 
         pathToAnyXml.add(anyXmlName.getLocalName());
-        addedChilds.put(pathToAnyXml, builder);
-        moduleNodes.put(pathToAnyXml, builder);
+        childNodes.put(pathToAnyXml, builder);
 
         return builder;
     }
 
-    public TypedefBuilder addTypedef(final QName typeDefName,
+    public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName,
             final List<String> parentPath, final int line) {
-        List<String> pathToType = new ArrayList<String>(parentPath);
-        TypedefBuilder builder = new TypedefBuilder(typeDefName, line);
-        TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes
-                .get(pathToType);
-        if (parent != null) {
-            parent.addTypedef(builder);
+        final List<String> pathToType = new ArrayList<String>(parentPath);
+        final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(
+                typeDefName, line);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeDefinitionAwareBuilder) {
+                ((TypeDefinitionAwareBuilder) parent).addTypedef(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of typedef "
+                                + typeDefName.getLocalName());
+            }
         }
+
         pathToType.add(typeDefName.getLocalName());
         addedTypedefs.put(pathToType, builder);
-        moduleNodes.put(pathToType, builder);
         return builder;
     }
 
-    public void setType(TypeDefinition<?> type, List<String> parentPath) {
-        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(parentPath);
-        if (parent == null) {
-            throw new YangParseException("Failed to set type '"
-                    + type.getQName().getLocalName()
-                    + "'. Parent node not found.");
+    public void setType(final TypeDefinition<?> type,
+            final List<String> parentPath) {
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeAwareBuilder) {
+                ((TypeAwareBuilder) parent).setType(type);
+            } else {
+                throw new YangParseException("Failed to set type '"
+                        + type.getQName().getLocalName()
+                        + "'. Unknown parent node: " + parent);
+            }
         }
-        parent.setType(type);
     }
 
-    public UnionTypeBuilder addUnionType(final List<String> actualPath,
+    public UnionTypeBuilder addUnionType(final List<String> currentPath,
             final URI namespace, final Date revision, final int line) {
-        List<String> pathToUnion = new ArrayList<String>(actualPath);
-        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(pathToUnion);
-        UnionTypeBuilder union = new UnionTypeBuilder(line);
-        parent.setType(union);
+        final List<String> pathToUnion = new ArrayList<String>(currentPath);
+        final UnionTypeBuilder union = new UnionTypeBuilder(line);
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(line, "union error");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeAwareBuilder) {
 
-        List<String> path = new ArrayList<String>(pathToUnion);
-        path.add("union");
+                ((TypeAwareBuilder) parent).setTypedef(union);
 
-        moduleNodes.put(path, union);
-        return union;
+                final List<String> path = new ArrayList<String>(pathToUnion);
+                path.add("union");
+
+                addedUnionTypes.put(path, union);
+                return union;
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of union type.");
+            }
+        }
     }
 
     public void addIdentityrefType(final String baseString,
             final List<String> parentPath, final SchemaPath schemaPath,
             final int line) {
-        List<String> pathToIdentityref = new ArrayList<String>(parentPath);
-        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(pathToIdentityref);
-        IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
+        final List<String> pathToIdentityref = new ArrayList<String>(parentPath);
+        final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
                 baseString, schemaPath, line);
-        parent.setType(identityref);
-        dirtyNodes.put(pathToIdentityref, parent);
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(line, "identityref error");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeAwareBuilder) {
+                final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
+                typeParent.setTypedef(identityref);
+                dirtyNodes.put(pathToIdentityref, typeParent);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of identityref type.");
+            }
+        }
     }
 
     public DeviationBuilder addDeviation(final String targetPath,
             final List<String> parentPath, final int line) {
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "deviation can be defined only in module or submodule");
+        }
+
         final List<String> pathToDeviation = new ArrayList<String>(parentPath);
         pathToDeviation.add(targetPath);
-        DeviationBuilder builder = new DeviationBuilder(targetPath, line);
-        addedDeviations.put(targetPath, builder);
-        moduleNodes.put(pathToDeviation, builder);
+        final DeviationBuilder builder = new DeviationBuilder(targetPath, line);
+        addedDeviations.put(pathToDeviation, builder);
         return builder;
     }
 
     public IdentitySchemaNodeBuilder addIdentity(final QName qname,
             final List<String> parentPath, final int line) {
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "identity can be defined only in module or submodule");
+        }
+
         final List<String> pathToIdentity = new ArrayList<String>(parentPath);
         final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(
                 qname, line);
         pathToIdentity.add(qname.getLocalName());
-        moduleNodes.put(pathToIdentity, builder);
         addedIdentities.add(builder);
         return builder;
     }
 
-    public void addConfiguration(boolean configuration, List<String> parentPath) {
-        Builder builder = moduleNodes.get(parentPath);
-        // current api did not support adding config to deviate
-        if (!(builder instanceof DeviationBuilder)) {
-            if(builder instanceof RefineHolder) {
-                ((RefineHolder)builder).setConfig(configuration);
+    public void addConfiguration(final boolean configuration,
+            final List<String> parentPath, final int line) {
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(name, line,
+                    "Parent node of config statement not found.");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof DataSchemaNodeBuilder) {
+                ((DataSchemaNodeBuilder) parent)
+                        .setConfiguration(configuration);
+            } else if (parent instanceof RefineHolder) {
+                ((RefineHolder) parent).setConfig(configuration);
+            } else if (parent instanceof DeviationBuilder) {
+                // skip: set config to deviation (deviate stmt) not supported by
+                // current api
+                return;
             } else {
-                ((DataSchemaNodeBuilder)builder).setConfiguration(configuration);
+                throw new YangParseException(name, line,
+                        "Unresolved parent of config statement.");
             }
         }
     }
 
     public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname,
             final List<String> parentPath, final int line) {
-        final List<String> pathToUnknown = new ArrayList<String>(parentPath);
         final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
                 qname, line);
-        final Builder parent = moduleNodes.get(pathToUnknown);
-        if (parent instanceof RefineHolder) {
-            ((RefineHolder) parent).addUnknownSchemaNode(builder);
-        } else if (parent instanceof SchemaNodeBuilder) {
-            ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof SchemaNodeBuilder) {
+                ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+            } else if (parent instanceof RefineHolder) {
+                ((RefineHolder) parent).addUnknownSchemaNode(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of unknown node '"
+                                + qname.getLocalName() + "'");
+            }
         }
+
         addedUnknownNodes.add(builder);
         return builder;
     }
@@ -1006,6 +1093,26 @@ public class ModuleBuilder implements Builder {
         }
     }
 
+    private void updateParent(DataSchemaNodeBuilder nodeBuilder, int line,
+            String nodeTypeName) {
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                if (parent instanceof AugmentationSchemaBuilder) {
+                    nodeBuilder.setAugmenting(true);
+                }
+                ((DataNodeContainerBuilder) parent)
+                        .addChildNode(nodeBuilder);
+            } else if (parent instanceof ChoiceBuilder) {
+                ((ChoiceBuilder) parent).addChildNode(nodeBuilder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of " + nodeTypeName + " "
+                                + nodeBuilder.getQName().getLocalName());
+            }
+        }
+    }
+
     private ModuleImport createModuleImport(final String moduleName,
             final Date revision, final String prefix) {
         ModuleImport moduleImport = new ModuleImport() {
@@ -1119,7 +1226,7 @@ public class ModuleBuilder implements Builder {
         final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
         for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
                 .entrySet()) {
-            if (entry.getKey().size() == 3) {
+            if (entry.getKey().size() == 2) {
                 groupings.add(entry.getValue().build());
             }
         }
index e058efc2fc4792bea0a48d127691cb3c0acacfe5..f75b97d1d73146762e9983399a59857b98b8c37d 100644 (file)
@@ -25,7 +25,7 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
@@ -33,7 +33,7 @@ import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBu
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 
-public final class NotificationBuilder extends AbstractChildNodeBuilder
+public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         implements TypeDefinitionAwareBuilder, SchemaNodeBuilder {
     private boolean isBuilt;
     private final NotificationDefinitionImpl instance;
@@ -100,6 +100,11 @@ public final class NotificationBuilder extends AbstractChildNodeBuilder
         return line;
     }
 
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return addedTypedefs;
+    }
+
     @Override
     public void addTypedef(final TypeDefinitionBuilder type) {
         addedTypedefs.add(type);
@@ -140,6 +145,11 @@ public final class NotificationBuilder extends AbstractChildNodeBuilder
         addedUnknownNodes.add(unknownNode);
     }
 
+    @Override
+    public String toString() {
+        return "notification " + getQName().getLocalName();
+    }
+
     private final class NotificationDefinitionImpl implements NotificationDefinition {
         private final QName qname;
         private SchemaPath path;
index 914ebc764474b43dfe4c48e91c4bc8124730903d..5b9638eb63dc715a7b58a6b810fe6095810fa938 100644 (file)
@@ -94,11 +94,19 @@ public final class RpcDefinitionBuilder implements SchemaNodeBuilder,
         this.outputBuilder = outputBuilder;
     }
 
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return addedTypedefs;
+    }
+
     @Override
     public void addTypedef(final TypeDefinitionBuilder type) {
         addedTypedefs.add(type);
     }
 
+    public void addGrouping(GroupingBuilder grouping) {
+        addedGroupings.add(grouping);
+    }
+
     @Override
     public SchemaPath getPath() {
         return schemaPath;
@@ -25,8 +25,8 @@ import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuil
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class TypedefBuilder extends AbstractTypeAwareBuilder implements
-        TypeDefinitionBuilder {
+public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
+        implements TypeDefinitionBuilder {
     private final int line;
     private final QName qname;
     private SchemaPath schemaPath;
@@ -43,7 +43,7 @@ public final class TypedefBuilder extends AbstractTypeAwareBuilder implements
     private String units;
     private Object defaultValue;
 
-    public TypedefBuilder(final QName qname, final int line) {
+    public TypeDefinitionBuilderImpl(final QName qname, final int line) {
         this.qname = qname;
         this.line = line;
     }
index 61aec1a8c95702f36787f1770791467f36ad3082..07db69901fe485a4eb1066a4882e150c2d79c089 100644 (file)
@@ -76,7 +76,7 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
     }
 
     @Override
-    public void setType(final TypeDefinitionBuilder tdb) {
+    public void setTypedef(final TypeDefinitionBuilder tdb) {
         typedefs.add(tdb);
     }
 
@@ -125,7 +125,7 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public SchemaPath getPath() {
-        return null;
+        return path;
     }
 
     @Override
index 14ef4914d512f8c7775f5c622990246587063908..ac2b5334fb3ec66e0cf8915fee70101f5da2e8bc 100644 (file)
@@ -52,9 +52,10 @@ import org.opendaylight.controller.yang.model.util.UnknownType;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
@@ -67,7 +68,8 @@ import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBu
 import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.ModuleDependencySort;
@@ -190,7 +192,7 @@ public final class YangParserImpl implements YangModelParser {
         resolveAugments(modules);
 
         // build
-        // Linked Hash Set MUST be used otherwise the Set will not maintain
+        // LinkedHashSet MUST be used otherwise the Set will not maintain
         // order!
         // http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashSet.html
         final Set<Module> result = new LinkedHashSet<Module>();
@@ -213,7 +215,7 @@ public final class YangParserImpl implements YangModelParser {
             final ModuleBuilder builder) {
         resolveDirtyNodes(modules, builder);
         resolveIdentities(modules, builder);
-        resolveUses(modules, builder);
+        resolveUsesRefines(modules, builder);
         resolveUnknownNodes(modules, builder);
     }
 
@@ -246,12 +248,13 @@ public final class YangParserImpl implements YangModelParser {
                             final UnknownType unknownType = (UnknownType) td;
                             final TypeDefinitionBuilder resolvedType = resolveTypeUnion(
                                     nodeToResolve, unknownType, modules, module);
-                            union.setType(resolvedType);
+                            union.setTypedef(resolvedType);
                             toRemove.add(unknownType);
                         }
                     }
                     unionTypes.removeAll(toRemove);
                 } else if (nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) {
+                    // different handling for identityref types
                     IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder) nodeToResolve
                             .getTypedef();
                     nodeToResolve.setType(new IdentityrefType(findFullQName(
@@ -259,28 +262,28 @@ public final class YangParserImpl implements YangModelParser {
                 } else {
                     final TypeDefinitionBuilder resolvedType = resolveType(
                             nodeToResolve, modules, module);
-                    nodeToResolve.setType(resolvedType);
+                    nodeToResolve.setTypedef(resolvedType);
                 }
             }
         }
     }
 
     private TypeDefinitionBuilder resolveType(
-            final TypeAwareBuilder typeToResolve,
+            final TypeAwareBuilder nodeToResolve,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder builder) {
         final TypeConstraints constraints = new TypeConstraints();
 
-        final TypeDefinitionBuilder targetType = getTypedefBuilder(
-                typeToResolve, modules, builder);
-        final TypeConstraints tConstraints = findConstraints(typeToResolve,
+        final TypeDefinitionBuilder targetTypeBuilder = getTypeDefinitionBuilderFromDirtyNode(
+                nodeToResolve, modules, builder);
+        final TypeConstraints tConstraints = findConstraints(nodeToResolve,
                 constraints, modules, builder);
-        targetType.setRanges(tConstraints.getRange());
-        targetType.setLengths(tConstraints.getLength());
-        targetType.setPatterns(tConstraints.getPatterns());
-        targetType.setFractionDigits(tConstraints.getFractionDigits());
+        targetTypeBuilder.setRanges(tConstraints.getRange());
+        targetTypeBuilder.setLengths(tConstraints.getLength());
+        targetTypeBuilder.setPatterns(tConstraints.getPatterns());
+        targetTypeBuilder.setFractionDigits(tConstraints.getFractionDigits());
 
-        return targetType;
+        return targetTypeBuilder;
     }
 
     private TypeDefinitionBuilder resolveTypeUnion(
@@ -290,38 +293,34 @@ public final class YangParserImpl implements YangModelParser {
             final ModuleBuilder builder) {
         final TypeConstraints constraints = new TypeConstraints();
 
-        final TypeDefinitionBuilder targetType = getUnionBuilder(typeToResolve,
-                unknownType, modules, builder);
+        final TypeDefinitionBuilder targetTypeBuilder = getUnionBuilder(
+                typeToResolve, unknownType, modules, builder);
         final TypeConstraints tConstraints = findConstraints(typeToResolve,
                 constraints, modules, builder);
-        targetType.setRanges(tConstraints.getRange());
-        targetType.setLengths(tConstraints.getLength());
-        targetType.setPatterns(tConstraints.getPatterns());
-        targetType.setFractionDigits(tConstraints.getFractionDigits());
+        targetTypeBuilder.setRanges(tConstraints.getRange());
+        targetTypeBuilder.setLengths(tConstraints.getLength());
+        targetTypeBuilder.setPatterns(tConstraints.getPatterns());
+        targetTypeBuilder.setFractionDigits(tConstraints.getFractionDigits());
 
-        return targetType;
+        return targetTypeBuilder;
     }
 
-    private TypeDefinitionBuilder getTypedefBuilder(
+    private TypeDefinitionBuilder getTypeDefinitionBuilderFromDirtyNode(
             final TypeAwareBuilder nodeToResolve,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder builder) {
-
-        final TypeDefinition<?> nodeToResolveBase = nodeToResolve.getType();
-        if (nodeToResolveBase != null
-                && !(nodeToResolveBase instanceof UnknownType)) {
-            return (TypeDefinitionBuilder) nodeToResolve;
-        }
+            final ModuleBuilder module) {
 
         final UnknownType unknownType = (UnknownType) nodeToResolve.getType();
         final QName unknownTypeQName = unknownType.getQName();
 
         // search for module which contains referenced typedef
         final ModuleBuilder dependentModule = findDependentModule(modules,
-                builder, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
-        final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
-                dependentModule, unknownTypeQName.getLocalName(),
-                builder.getName(), nodeToResolve.getLine());
+                module, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
+
+        final TypeDefinitionBuilder lookedUpBuilder = findTypeDefinitionBuilder(
+                nodeToResolve.getPath(), dependentModule,
+                unknownTypeQName.getLocalName(), module.getName(),
+                nodeToResolve.getLine());
 
         final TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder(
                 lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder);
@@ -346,9 +345,10 @@ public final class YangParserImpl implements YangModelParser {
         // search for module which contains referenced typedef
         final ModuleBuilder dependentModule = findDependentModule(modules,
                 module, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
-        final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
-                dependentModule, unknownTypeQName.getLocalName(),
-                module.getName(), nodeToResolve.getLine());
+        final TypeDefinitionBuilder lookedUpBuilder = findTypeDefinitionBuilder(
+                nodeToResolve.getPath(), dependentModule,
+                unknownTypeQName.getLocalName(), module.getName(),
+                nodeToResolve.getLine());
 
         final TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder(
                 lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder);
@@ -361,12 +361,13 @@ public final class YangParserImpl implements YangModelParser {
             final TypeDefinitionBuilder old, final boolean seekByTypedefBuilder) {
         if (old instanceof UnionTypeBuilder) {
             final UnionTypeBuilder oldUnion = (UnionTypeBuilder) old;
-            final UnionTypeBuilder newUnion = new UnionTypeBuilder(old.getLine());
+            final UnionTypeBuilder newUnion = new UnionTypeBuilder(
+                    old.getLine());
             for (TypeDefinition<?> td : oldUnion.getTypes()) {
                 newUnion.setType(td);
             }
             for (TypeDefinitionBuilder tdb : oldUnion.getTypedefs()) {
-                newUnion.setType(copyTypedefBuilder(tdb, true));
+                newUnion.setTypedef(copyTypedefBuilder(tdb, true));
             }
             newUnion.setPath(old.getPath());
             return newUnion;
@@ -376,8 +377,8 @@ public final class YangParserImpl implements YangModelParser {
         final QName newName = new QName(oldName.getNamespace(),
                 oldName.getRevision(), oldName.getPrefix(),
                 oldName.getLocalName());
-        final TypeDefinitionBuilder tdb = new TypedefBuilder(newName,
-                old.getLine());
+        final TypeDefinitionBuilder tdb = new TypeDefinitionBuilderImpl(
+                newName, old.getLine());
 
         tdb.setRanges(old.getRanges());
         tdb.setLengths(old.getLengths());
@@ -387,7 +388,7 @@ public final class YangParserImpl implements YangModelParser {
 
         final TypeDefinition<?> oldType = old.getType();
         if (oldType == null) {
-            tdb.setType(old.getTypedef());
+            tdb.setTypedef(old.getTypedef());
         } else {
             tdb.setType(oldType);
         }
@@ -416,7 +417,7 @@ public final class YangParserImpl implements YangModelParser {
                     final UnknownType unknownType = (UnknownType) td;
                     final TypeDefinitionBuilder resolvedType = resolveTypeUnion(
                             union, unknownType, modules, builder);
-                    union.setType(resolvedType);
+                    union.setTypedef(resolvedType);
                     toRemove.add(unknownType);
                 }
             }
@@ -435,9 +436,9 @@ public final class YangParserImpl implements YangModelParser {
             final String unknownTypePrefix = unknownTypeQName.getPrefix();
             final ModuleBuilder dependentModule = findDependentModule(modules,
                     builder, unknownTypePrefix, copy.getLine());
-            final TypeDefinitionBuilder utBuilder = getTypedefBuilder(copy,
-                    modules, dependentModule);
-            copy.setType(utBuilder);
+            final TypeDefinitionBuilder utBuilder = getTypeDefinitionBuilderFromDirtyNode(
+                    copy, modules, dependentModule);
+            copy.setTypedef(utBuilder);
             return copy;
         } else if (base == null && baseTdb != null) {
             // make a copy of baseTypeDef and call again
@@ -445,27 +446,14 @@ public final class YangParserImpl implements YangModelParser {
                     baseTdb, true);
             final TypeDefinitionBuilder baseTdbCopyResolved = resolveCopiedBuilder(
                     baseTdbCopy, modules, builder);
-            copy.setType(baseTdbCopyResolved);
+            copy.setTypedef(baseTdbCopyResolved);
             return copy;
         } else {
-            throw new IllegalStateException("Failed to resolve type "
-                    + copy.getQName().getLocalName());
+            throw new YangParseException(copy.getLine(),
+                    "Failed to resolve type " + copy.getQName().getLocalName());
         }
     }
 
-    private TypeDefinitionBuilder findTypedefBuilder(
-            final QName unknownTypeQName,
-            final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder builder, int line) {
-        // search for module which contains referenced typedef
-        final ModuleBuilder dependentModule = findDependentModule(modules,
-                builder, unknownTypeQName.getPrefix(), line);
-        final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
-                dependentModule, unknownTypeQName.getLocalName(),
-                builder.getName(), line);
-        return copyTypedefBuilder(lookedUpBuilder, true);
-    }
-
     private TypeConstraints findConstraints(
             final TypeAwareBuilder nodeToResolve,
             final TypeConstraints constraints,
@@ -505,7 +493,8 @@ public final class YangParserImpl implements YangModelParser {
             fractionDigits = ext.getFractionDigits();
             constraints.setFractionDigits(fractionDigits);
             return findConstraints(
-                    findTypedefBuilder(ext.getQName(), modules, builder,
+                    findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
+                            ext.getQName().getLocalName(), builder.getName(),
                             nodeToResolve.getLine()), constraints, modules,
                     builder);
         } else if (referencedType instanceof UnknownType) {
@@ -526,8 +515,9 @@ public final class YangParserImpl implements YangModelParser {
             final ModuleBuilder dependentModule = findDependentModule(modules,
                     builder, unknown.getQName().getPrefix(),
                     nodeToResolve.getLine());
-            final TypeDefinitionBuilder utBuilder = findTypedefBuilder(
-                    unknown.getQName(), modules, builder,
+            final TypeDefinitionBuilder utBuilder = findTypeDefinitionBuilder(
+                    nodeToResolve.getPath(), dependentModule, unknown
+                            .getQName().getLocalName(), builder.getName(),
                     nodeToResolve.getLine());
             return findConstraints(utBuilder, constraints, modules,
                     dependentModule);
@@ -541,29 +531,71 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Search for type definition builder by name.
      *
+     * @param dirtyNodeSchemaPath
+     *            schema path of node which contains unresolved type
      * @param dependentModule
-     *            module to search
-     * @param name
+     *            module which should contains referenced type
+     * @param typeName
      *            name of type definition
      * @param currentModuleName
-     *            current module name
+     *            name of current module
      * @param line
      *            current line in yang model
      * @return
      */
-    private TypeDefinitionBuilder findTypedefBuilderByName(
-            final ModuleBuilder dependentModule, final String name,
+    private TypeDefinitionBuilder findTypeDefinitionBuilder(
+            SchemaPath dirtyNodeSchemaPath,
+            final ModuleBuilder dependentModule, final String typeName,
             final String currentModuleName, final int line) {
-        final Set<TypeDefinitionBuilder> typedefs = dependentModule
+        final List<QName> path = dirtyNodeSchemaPath.getPath();
+        TypeDefinitionBuilder result = null;
+
+        Set<TypeDefinitionBuilder> typedefs = dependentModule
                 .getModuleTypedefs();
-        for (TypeDefinitionBuilder td : typedefs) {
+        result = findTdb(typedefs, typeName);
+
+        if (result == null) {
+            Builder currentNode = null;
+            final List<String> currentPath = new ArrayList<String>();
+            currentPath.add(dependentModule.getName());
+
+            for (int i = 0; i < path.size(); i++) {
+                QName qname = path.get(i);
+                currentPath.add(qname.getLocalName());
+                currentNode = dependentModule.getModuleNode(currentPath);
+
+                if (currentNode instanceof RpcDefinitionBuilder) {
+                    typedefs = ((RpcDefinitionBuilder) currentNode)
+                            .getTypeDefinitions();
+                } else if (currentNode instanceof DataNodeContainerBuilder) {
+                    typedefs = ((DataNodeContainerBuilder) currentNode)
+                            .getTypeDefinitions();
+                } else {
+                    typedefs = Collections.emptySet();
+                }
+
+                result = findTdb(typedefs, typeName);
+                if (result != null) {
+                    break;
+                }
+            }
+        }
+
+        if (result != null) {
+            return result;
+        }
+        throw new YangParseException(currentModuleName, line,
+                "Referenced type '" + typeName + "' not found.");
+    }
+
+    private TypeDefinitionBuilder findTdb(Set<TypeDefinitionBuilder> types,
+            String name) {
+        for (TypeDefinitionBuilder td : types) {
             if (td.getQName().getLocalName().equals(name)) {
                 return td;
             }
         }
-        throw new YangParseException(currentModuleName, line, "Target module '"
-                + dependentModule.getName() + "' does not contain typedef '"
-                + name + "'.");
+        return null;
     }
 
     /**
@@ -622,7 +654,7 @@ public final class YangParserImpl implements YangModelParser {
             // while all augments are not resolved
             final Iterator<ModuleBuilder> allModulesIterator = allModulesSet
                     .iterator();
-            while (!(module.getAugmentsResolved() == module.getAddedAugments()
+            while (!(module.getAugmentsResolved() == module.getAugments()
                     .size())) {
                 ModuleBuilder nextModule = null;
                 // try resolve other module augments
@@ -650,9 +682,9 @@ public final class YangParserImpl implements YangModelParser {
     private void resolveAugment(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
-        if (module.getAugmentsResolved() < module.getAddedAugments().size()) {
+        if (module.getAugmentsResolved() < module.getAugments().size()) {
             for (AugmentationSchemaBuilder augmentBuilder : module
-                    .getAddedAugments()) {
+                    .getAugments()) {
 
                 if (!augmentBuilder.isResolved()) {
                     final SchemaPath augmentTargetSchemaPath = augmentBuilder
@@ -678,10 +710,14 @@ public final class YangParserImpl implements YangModelParser {
                         }
                     }
 
+                    if (currentParent == null) {
+                        continue;
+                    }
+
                     for (int i = 1; i < path.size(); i++) {
                         final QName currentQName = path.get(i);
                         DataSchemaNodeBuilder newParent = null;
-                        for (DataSchemaNodeBuilder child : ((ChildNodeBuilder) currentParent)
+                        for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent)
                                 .getChildNodes()) {
                             final QName childQName = child.getQName();
                             if (childQName.getLocalName().equals(
@@ -702,8 +738,14 @@ public final class YangParserImpl implements YangModelParser {
                             .get(path.size() - 1);
                     if (currentQName.getLocalName().equals(
                             lastAugmentPathElement.getLocalName())) {
-                        ParserUtils.fillAugmentTarget(augmentBuilder,
-                                (ChildNodeBuilder) currentParent);
+
+                        if(currentParent instanceof ChoiceBuilder) {
+                            ParserUtils.fillAugmentTarget(augmentBuilder,
+                                    (ChoiceBuilder) currentParent);
+                        } else {
+                            ParserUtils.fillAugmentTarget(augmentBuilder,
+                                    (DataNodeContainerBuilder) currentParent);
+                        }
                         ((AugmentationTargetBuilder) currentParent)
                                 .addAugmentation(augmentBuilder);
                         SchemaPath oldPath = currentParent.getPath();
@@ -731,7 +773,7 @@ public final class YangParserImpl implements YangModelParser {
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         final Set<IdentitySchemaNodeBuilder> identities = module
-                .getAddedIdentities();
+                .getIdentities();
         for (IdentitySchemaNodeBuilder identity : identities) {
             final String baseIdentityName = identity.getBaseIdentityName();
             if (baseIdentityName != null) {
@@ -749,7 +791,7 @@ public final class YangParserImpl implements YangModelParser {
                         modules, module, baseIdentityPrefix, identity.getLine());
 
                 final Set<IdentitySchemaNodeBuilder> dependentModuleIdentities = dependentModule
-                        .getAddedIdentities();
+                        .getIdentities();
                 for (IdentitySchemaNodeBuilder idBuilder : dependentModuleIdentities) {
                     if (idBuilder.getQName().getLocalName()
                             .equals(baseIdentityLocalName)) {
@@ -769,11 +811,11 @@ public final class YangParserImpl implements YangModelParser {
      * @param module
      *            module being resolved
      */
-    private void resolveUses(
+    private void resolveUsesRefines(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         final Map<List<String>, UsesNodeBuilder> moduleUses = module
-                .getAddedUsesNodes();
+                .getUsesNodes();
         for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses
                 .entrySet()) {
             final List<String> key = entry.getKey();
@@ -783,8 +825,9 @@ public final class YangParserImpl implements YangModelParser {
             final String groupingName = key.get(key.size() - 1);
 
             for (RefineHolder refine : usesNode.getRefines()) {
-                Builder refineTarget = getRefineNodeBuilderCopy(groupingName,
-                        refine, modules, module);
+                SchemaNodeBuilder refineTarget = getRefineNodeBuilderCopy(
+                        groupingName, refine, modules, module);
+                ParserUtils.checkRefine(refineTarget, refine);
                 ParserUtils.refineDefault(refineTarget, refine, line);
                 if (refineTarget instanceof LeafSchemaNodeBuilder) {
                     final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) refineTarget;
@@ -810,10 +853,10 @@ public final class YangParserImpl implements YangModelParser {
                     final AnyXmlBuilder anyXml = (AnyXmlBuilder) refineTarget;
                     ParserUtils.refineAnyxml(anyXml, refine, line);
                     usesNode.addRefineNode(anyXml);
-                } else if(refineTarget instanceof GroupingBuilder) {
-                    usesNode.addRefineNode((GroupingBuilder)refineTarget);
-                } else if(refineTarget instanceof TypedefBuilder) {
-                    usesNode.addRefineNode((TypedefBuilder)refineTarget);
+                } else if (refineTarget instanceof GroupingBuilder) {
+                    usesNode.addRefineNode(refineTarget);
+                } else if (refineTarget instanceof TypeDefinitionBuilder) {
+                    usesNode.addRefineNode(refineTarget);
                 }
             }
         }
@@ -822,8 +865,8 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Find original builder of node to refine and return copy of this builder.
      * <p>
-     * We must make a copy of builder to preserve original builder, because this
-     * object will be refined (modified) and later added to
+     * We must create and use a copy of builder to preserve original builder
+     * state, because this object will be refined (modified) and later added to
      * {@link UsesNodeBuilder}.
      * </p>
      *
@@ -838,8 +881,8 @@ public final class YangParserImpl implements YangModelParser {
      * @return copy of node to be refined if it is present in grouping, null
      *         otherwise
      */
-    private Builder getRefineNodeBuilderCopy(final String groupingPath,
-            final RefineHolder refine,
+    private SchemaNodeBuilder getRefineNodeBuilderCopy(
+            final String groupingPath, final RefineHolder refine,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         Builder result = null;
@@ -868,12 +911,12 @@ public final class YangParserImpl implements YangModelParser {
                     .copyGroupingBuilder((GroupingBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
             result = ParserUtils
-                    .copyTypedefBuilder((TypedefBuilder) lookedUpBuilder);
+                    .copyTypedefBuilder((TypeDefinitionBuilderImpl) lookedUpBuilder);
         } else {
             throw new YangParseException(module.getName(), refine.getLine(),
                     "Target '" + refine.getName() + "' can not be refined");
         }
-        return result;
+        return (SchemaNodeBuilder) result;
     }
 
     /**
@@ -908,25 +951,24 @@ public final class YangParserImpl implements YangModelParser {
 
         final ModuleBuilder dependentModule = findDependentModule(modules,
                 module, prefix, refine.getLine());
-        builderPath.add(0, "grouping");
         builderPath.add(0, dependentModule.getName());
-        final GroupingBuilder builder = (GroupingBuilder) dependentModule
-                .getNode(builderPath);
+        final GroupingBuilder builder = dependentModule
+                .getGrouping(builderPath);
 
         Builder result = builder.getChildNode(refineNodeName);
-        if(result == null) {
+        if (result == null) {
             Set<GroupingBuilder> grps = builder.getGroupings();
-            for(GroupingBuilder gr : grps) {
-                if(gr.getQName().getLocalName().equals(refineNodeName)) {
+            for (GroupingBuilder gr : grps) {
+                if (gr.getQName().getLocalName().equals(refineNodeName)) {
                     result = gr;
                     break;
                 }
             }
         }
-        if(result == null) {
-            Set<TypeDefinitionBuilder> typedefs = builder.getTypedefs();
-            for(TypeDefinitionBuilder typedef : typedefs) {
-                if(typedef.getQName().getLocalName().equals(refineNodeName)) {
+        if (result == null) {
+            Set<TypeDefinitionBuilder> typedefs = builder.getTypeDefinitions();
+            for (TypeDefinitionBuilder typedef : typedefs) {
+                if (typedef.getQName().getLocalName().equals(refineNodeName)) {
                     result = typedef;
                     break;
                 }
@@ -962,7 +1004,7 @@ public final class YangParserImpl implements YangModelParser {
     private void resolveUnknownNodes(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
-        for (UnknownSchemaNodeBuilder usnb : module.getAddedUnknownNodes()) {
+        for (UnknownSchemaNodeBuilder usnb : module.getUnknownNodes()) {
             QName nodeType = usnb.getNodeType();
             if (nodeType.getNamespace() == null
                     || nodeType.getRevision() == null) {
@@ -992,6 +1034,8 @@ public final class YangParserImpl implements YangModelParser {
      *            current module
      * @param prefix
      *            target module prefix
+     * @param line
+     *            current line in yang model
      * @return
      */
     private ModuleBuilder findDependentModule(
index b853dcf2a89b29827bd4478a99eb5516ae55182d..8b739098a067f3fbd0144963b0cce0600e091045 100644 (file)
@@ -58,6 +58,8 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.util.YangTypesConverter;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder;
@@ -72,7 +74,6 @@ import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilde
 import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.NotificationBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.RefineHolder;
@@ -240,6 +241,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String augmentPath = stringFromNode(ctx);
         AugmentationSchemaBuilder builder = moduleBuilder.addAugment(
                 augmentPath, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(augmentPath);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -264,6 +266,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) {
         final String augment = actualPath.pop();
         logger.debug("exiting augment " + augment);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -293,8 +296,9 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String typedefName = stringFromNode(ctx);
         QName typedefQName = new QName(namespace, revision, yangModelPrefix,
                 typedefName);
-        TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName,
+        TypeDefinitionBuilder builder = moduleBuilder.addTypedef(typedefQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(typedefName);
 
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
@@ -307,6 +311,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -338,9 +343,11 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                     List<String> typePath = new ArrayList<String>(actualPath);
                     typePath.add(typeName);
 
-                    SchemaPath p = createActualSchemaPath(typePath, namespace, revision, yangModelPrefix);
-                    UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(actualPath, namespace, revision,
-                            line);
+                    SchemaPath p = createActualSchemaPath(typePath, namespace,
+                            revision, yangModelPrefix);
+                    UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(
+                            actualPath, namespace, revision, line);
+                    moduleBuilder.enterNode(unionBuilder);
                     unionBuilder.setPath(p);
                 } else if ("identityref".equals(typeName)) {
                     SchemaPath path = createActualSchemaPath(actualPath,
@@ -389,6 +396,11 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitType_stmt(YangParser.Type_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+
+        final String typeName = stringFromNode(ctx);
+        if ("union".equals(typeName)) {
+            moduleBuilder.exitNode();
+        }
     }
 
     @Override
@@ -396,11 +408,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String groupName = stringFromNode(ctx);
         QName groupQName = new QName(namespace, revision, yangModelPrefix,
                 groupName);
-        GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName,
+        GroupingBuilder builder = moduleBuilder.addGrouping(groupQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath("grouping");
         updatePath(groupName);
-        parseSchemaNodeArgs(ctx, groupBuilder);
+        parseSchemaNodeArgs(ctx, builder);
     }
 
     @Override
@@ -408,6 +421,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String actContainer = actualPath.pop();
         actContainer += "-" + actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -415,19 +429,20 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String containerName = stringFromNode(ctx);
         QName containerQName = new QName(namespace, revision, yangModelPrefix,
                 containerName);
-        ContainerSchemaNodeBuilder containerBuilder = moduleBuilder
-                .addContainerNode(containerQName, actualPath, ctx.getStart().getLine());
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(
+                containerQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(containerName);
 
-        containerBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, containerBuilder);
-        parseConstraints(ctx, containerBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
             if (childNode instanceof Presence_stmtContext) {
-                containerBuilder.setPresence(true);
+                builder.setPresence(true);
                 break;
             }
         }
@@ -437,6 +452,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitContainer_stmt(Container_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -444,14 +460,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String leafName = stringFromNode(ctx);
         QName leafQName = new QName(namespace, revision, yangModelPrefix,
                 leafName);
-        LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode(
-                leafQName, actualPath, ctx.getStart().getLine());
+        LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(leafQName,
+                actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(leafName);
 
-        leafBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, leafBuilder);
-        parseConstraints(ctx, leafBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         String defaultStr = null;
         String unitsStr = null;
@@ -463,21 +480,23 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 unitsStr = stringFromNode(child);
             }
         }
-        leafBuilder.setDefaultStr(defaultStr);
-        leafBuilder.setUnits(unitsStr);
+        builder.setDefaultStr(defaultStr);
+        builder.setUnits(unitsStr);
     }
 
     @Override
     public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) {
         final String actLeaf = actualPath.pop();
         logger.debug("exiting " + actLeaf);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterUses_stmt(YangParser.Uses_stmtContext ctx) {
         final String groupingPathStr = stringFromNode(ctx);
-        moduleBuilder.addUsesNode(groupingPathStr, actualPath, ctx.getStart()
-                .getLine());
+        UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr,
+                actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(groupingPathStr);
     }
 
@@ -485,6 +504,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitUses_stmt(YangParser.Uses_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -492,6 +512,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String refineString = stringFromNode(ctx);
         RefineHolder refine = parseRefine(ctx);
         moduleBuilder.addRefine(refine, actualPath);
+        moduleBuilder.enterNode(refine);
         updatePath(refineString);
     }
 
@@ -499,6 +520,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -506,20 +528,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String leafListName = stringFromNode(ctx);
         QName leafListQName = new QName(namespace, revision, yangModelPrefix,
                 leafListName);
-        LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder
-                .addLeafListNode(leafListQName, actualPath, ctx.getStart()
-                        .getLine());
+        LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(
+                leafListQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(leafListName);
 
-        parseSchemaNodeArgs(ctx, leafListBuilder);
-        parseConstraints(ctx, leafListBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
             if (childNode instanceof Ordered_by_stmtContext) {
                 final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
                 final boolean userOrdered = parseUserOrdered(orderedBy);
-                leafListBuilder.setUserOrdered(userOrdered);
+                builder.setUserOrdered(userOrdered);
                 break;
             }
         }
@@ -529,6 +553,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -536,14 +561,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String containerName = stringFromNode(ctx);
         QName containerQName = new QName(namespace, revision, yangModelPrefix,
                 containerName);
-        ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode(
+        ListSchemaNodeBuilder builder = moduleBuilder.addListNode(
                 containerQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(containerName);
 
-        listBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, listBuilder);
-        parseConstraints(ctx, listBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         String keyDefinition = "";
         for (int i = 0; i < ctx.getChildCount(); ++i) {
@@ -551,12 +577,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             if (childNode instanceof Ordered_by_stmtContext) {
                 final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
                 final boolean userOrdered = parseUserOrdered(orderedBy);
-                listBuilder.setUserOrdered(userOrdered);
+                builder.setUserOrdered(userOrdered);
             } else if (childNode instanceof Key_stmtContext) {
                 keyDefinition = stringFromNode(childNode);
                 List<QName> key = createListKey(keyDefinition, namespace,
                         revision, yangModelPrefix);
-                listBuilder.setKeyDefinition(key);
+                builder.setKeyDefinition(key);
             }
         }
     }
@@ -565,6 +591,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitList_stmt(List_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -572,20 +599,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String anyXmlName = stringFromNode(ctx);
         QName anyXmlQName = new QName(namespace, revision, yangModelPrefix,
                 anyXmlName);
-        AnyXmlBuilder anyXmlBuilder = moduleBuilder.addAnyXml(anyXmlQName,
+        AnyXmlBuilder builder = moduleBuilder.addAnyXml(anyXmlQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(anyXmlName);
 
-        anyXmlBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, anyXmlBuilder);
-        parseConstraints(ctx, anyXmlBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -593,21 +622,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String choiceName = stringFromNode(ctx);
         QName choiceQName = new QName(namespace, revision, yangModelPrefix,
                 choiceName);
-        ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(choiceQName,
+        ChoiceBuilder builder = moduleBuilder.addChoice(choiceQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
 
         updatePath(choiceName);
-        choiceBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, choiceBuilder);
-        parseConstraints(ctx, choiceBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         // set 'default' case
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree child = ctx.getChild(i);
             if (child instanceof Default_stmtContext) {
                 String defaultCase = stringFromNode(child);
-                choiceBuilder.setDefaultCase(defaultCase);
+                builder.setDefaultCase(defaultCase);
                 break;
             }
         }
@@ -617,6 +647,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitChoice_stmt(YangParser.Choice_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -624,20 +655,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String caseName = stringFromNode(ctx);
         QName choiceQName = new QName(namespace, revision, yangModelPrefix,
                 caseName);
-        ChoiceCaseBuilder caseBuilder = moduleBuilder.addCase(choiceQName,
+        ChoiceCaseBuilder builder = moduleBuilder.addCase(choiceQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
 
         updatePath(caseName);
-        caseBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, caseBuilder);
-        parseConstraints(ctx, caseBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitCase_stmt(YangParser.Case_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -645,20 +678,21 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String notificationName = stringFromNode(ctx);
         QName notificationQName = new QName(namespace, revision,
                 yangModelPrefix, notificationName);
-        NotificationBuilder notificationBuilder = moduleBuilder
-                .addNotification(notificationQName, actualPath, ctx.getStart()
-                        .getLine());
+        NotificationBuilder builder = moduleBuilder.addNotification(
+                notificationQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(notificationName);
 
-        notificationBuilder.setPath(createActualSchemaPath(actualPath,
-                namespace, revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, notificationBuilder);
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
     }
 
     @Override
     public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     // Unknown types
@@ -699,12 +733,14 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
                 yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
+        moduleBuilder.enterNode(builder);
     }
 
     @Override
     public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -714,6 +750,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 rpcName);
         RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(rpcBuilder);
         updatePath(rpcName);
 
         rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace,
@@ -725,28 +762,51 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterInput_stmt(YangParser.Input_stmtContext ctx) {
-        updatePath("input");
+        final String input = "input";
+        QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(
+                rpcQName, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
+        updatePath(input);
+
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitInput_stmt(YangParser.Input_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterOutput_stmt(YangParser.Output_stmtContext ctx) {
-        updatePath("output");
+        final String output = "output";
+        QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(
+                rpcQName, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
+        updatePath(output);
+
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitOutput_stmt(YangParser.Output_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -756,6 +816,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 featureName);
         FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(featureBuilder);
         updatePath(featureName);
 
         featureBuilder.setPath(createActualSchemaPath(actualPath, namespace,
@@ -767,6 +828,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -776,6 +838,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String deviate = null;
         DeviationBuilder builder = moduleBuilder.addDeviation(targetPath,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(targetPath);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -800,12 +863,14 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterConfig_stmt(YangParser.Config_stmtContext ctx) {
         boolean configuration = parseConfig(ctx);
-        moduleBuilder.addConfiguration(configuration, actualPath);
+        moduleBuilder.addConfiguration(configuration, actualPath, ctx
+                .getStart().getLine());
     }
 
     @Override
@@ -815,6 +880,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 yangModelPrefix, identityName);
         IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(
                 identityQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(identityName);
 
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
@@ -834,6 +900,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     public ModuleBuilder getModuleBuilder() {
index b4e250d19f9e2df482e4421f5943a29e73e350d9..2e3f0cc860ba80d22cef4d01b33b47d531626e10 100644 (file)
@@ -51,7 +51,7 @@ import org.opendaylight.controller.yang.model.util.StringType;
 import org.opendaylight.controller.yang.model.util.UnionType;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
@@ -68,7 +68,7 @@ import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBu
 import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
 
@@ -133,7 +133,7 @@ public final class ParserUtils {
      */
     public static void fillAugmentTarget(
             final AugmentationSchemaBuilder augment,
-            final ChildNodeBuilder target) {
+            final DataNodeContainerBuilder target) {
         for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
             builder.setAugmenting(true);
             correctAugmentChildPath(augment, target.getPath());
@@ -141,7 +141,17 @@ public final class ParserUtils {
         }
     }
 
-    private static void correctAugmentChildPath(final ChildNodeBuilder node,
+    public static void fillAugmentTarget(
+            final AugmentationSchemaBuilder augment,
+            final ChoiceBuilder target) {
+        for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+            builder.setAugmenting(true);
+            correctAugmentChildPath(augment, target.getPath());
+            target.addChildNode(builder);
+        }
+    }
+
+    private static void correctAugmentChildPath(final DataNodeContainerBuilder node,
             final SchemaPath parentSchemaPath) {
         for (DataSchemaNodeBuilder builder : node.getChildNodes()) {
 
@@ -151,149 +161,189 @@ public final class ParserUtils {
             targetNodePath.add(builder.getQName());
             builder.setPath(new SchemaPath(targetNodePath, true));
 
-            if (builder instanceof ChildNodeBuilder) {
-                ChildNodeBuilder cnb = (ChildNodeBuilder) builder;
+            if (builder instanceof DataNodeContainerBuilder) {
+                DataNodeContainerBuilder cnb = (DataNodeContainerBuilder) builder;
                 correctAugmentChildPath(cnb, builder.getPath());
             }
 
             // if child can contains type, correct path for this type too
-            if(builder instanceof TypeAwareBuilder) {
-                TypeAwareBuilder nodeBuilder = (TypeAwareBuilder)builder;
+            if (builder instanceof TypeAwareBuilder) {
+                TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) builder;
                 QName nodeBuilderQName = nodeBuilder.getQName();
                 TypeDefinition<?> nodeBuilderType = nodeBuilder.getType();
-                if(nodeBuilderType != null) {
-                    TypeDefinition<?> newType = createCorrectTypeDefinition(parentSchemaPath, nodeBuilderQName, nodeBuilderType);
+                if (nodeBuilderType != null) {
+                    TypeDefinition<?> newType = createCorrectTypeDefinition(
+                            parentSchemaPath, nodeBuilderQName, nodeBuilderType);
                     nodeBuilder.setType(newType);
                 } else {
-                    TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder.getTypedef();
-                    SchemaPath newSchemaPath = createNewSchemaPath(nodeBuilderTypedef.getPath(), nodeBuilderQName, nodeBuilderTypedef.getQName());
+                    TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder
+                            .getTypedef();
+                    SchemaPath newSchemaPath = createNewSchemaPath(
+                            nodeBuilderTypedef.getPath(), nodeBuilderQName,
+                            nodeBuilderTypedef.getQName());
                     nodeBuilderTypedef.setPath(newSchemaPath);
                 }
             }
         }
     }
 
-    private static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, QName nodeQName, TypeDefinition<?> nodeType) {
+    private static TypeDefinition<?> createCorrectTypeDefinition(
+            SchemaPath parentSchemaPath, QName nodeQName,
+            TypeDefinition<?> nodeType) {
         TypeDefinition<?> result = null;
         SchemaPath newSchemaPath = null;
-        if(nodeType != null) {
-            if(nodeType instanceof BinaryTypeDefinition) {
-                BinaryTypeDefinition binType = (BinaryTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, binType.getQName());
-                List<Byte> bytes = (List<Byte>)binType.getDefaultValue();
-                result = new BinaryType(newSchemaPath, bytes, binType.getLengthConstraints(), binType.getUnits());
-            } else if(nodeType instanceof BitsTypeDefinition) {
-                BitsTypeDefinition bitsType = (BitsTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
-                result = new BitsType(newSchemaPath, bitsType.getBits(), bitsType.getUnits());
-            } else if(nodeType instanceof BooleanTypeDefinition) {
-                BooleanTypeDefinition booleanType = (BooleanTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, booleanType.getQName());
-                result = new BooleanType(newSchemaPath, (Boolean)booleanType.getDefaultValue(), booleanType.getUnits());
-            } else if(nodeType instanceof DecimalTypeDefinition) {
-                DecimalTypeDefinition decimalType = (DecimalTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, decimalType.getQName());
-                BigDecimal defaultValue = (BigDecimal)decimalType.getDefaultValue();
-                result = new Decimal64(newSchemaPath, decimalType.getUnits(), defaultValue, decimalType.getRangeStatements(), decimalType.getFractionDigits());
-            } else if(nodeType instanceof EmptyTypeDefinition) {
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
+        if (nodeType != null) {
+            if (nodeType instanceof BinaryTypeDefinition) {
+                BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, binType.getQName());
+                List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
+                result = new BinaryType(newSchemaPath, bytes,
+                        binType.getLengthConstraints(), binType.getUnits());
+            } else if (nodeType instanceof BitsTypeDefinition) {
+                BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, nodeType.getQName());
+                result = new BitsType(newSchemaPath, bitsType.getBits(),
+                        bitsType.getUnits());
+            } else if (nodeType instanceof BooleanTypeDefinition) {
+                BooleanTypeDefinition booleanType = (BooleanTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, booleanType.getQName());
+                result = new BooleanType(newSchemaPath,
+                        (Boolean) booleanType.getDefaultValue(),
+                        booleanType.getUnits());
+            } else if (nodeType instanceof DecimalTypeDefinition) {
+                DecimalTypeDefinition decimalType = (DecimalTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, decimalType.getQName());
+                BigDecimal defaultValue = (BigDecimal) decimalType
+                        .getDefaultValue();
+                result = new Decimal64(newSchemaPath, decimalType.getUnits(),
+                        defaultValue, decimalType.getRangeStatements(),
+                        decimalType.getFractionDigits());
+            } else if (nodeType instanceof EmptyTypeDefinition) {
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, nodeType.getQName());
                 result = new EmptyType(newSchemaPath);
-            } else if(nodeType instanceof EnumTypeDefinition) {
-                EnumTypeDefinition enumType = (EnumTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, enumType.getQName());
-                result = new EnumerationType(newSchemaPath, (EnumPair)enumType.getDefaultValue(), enumType.getValues(), enumType.getUnits());
-            } else if(nodeType instanceof IdentityrefTypeDefinition) {
-                IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, idrefType.getQName());
-                result = new IdentityrefType(idrefType.getIdentity(), newSchemaPath);
-            } else if(nodeType instanceof InstanceIdentifierTypeDefinition) {
-                InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, instIdType.getQName());
-                return new InstanceIdentifier(newSchemaPath, instIdType.getPathStatement(), instIdType.requireInstance());
-            } else if(nodeType instanceof StringTypeDefinition) {
-                result = copyStringType(parentSchemaPath, nodeQName, (StringTypeDefinition)nodeType);
-            } else if(nodeType instanceof IntegerTypeDefinition) {
-                result = copyIntType(parentSchemaPath, nodeQName, (IntegerTypeDefinition)nodeType);
-            } else if(nodeType instanceof UnsignedIntegerTypeDefinition) {
-                result = copyUIntType(parentSchemaPath, nodeQName, (UnsignedIntegerTypeDefinition)nodeType);
-            } else if(nodeType instanceof LeafrefTypeDefinition) {
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
-                result = new Leafref(newSchemaPath, ((LeafrefTypeDefinition)nodeType).getPathStatement());
-            } else if(nodeType instanceof UnionTypeDefinition) {
-                UnionTypeDefinition unionType = (UnionTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, unionType.getQName());
+            } else if (nodeType instanceof EnumTypeDefinition) {
+                EnumTypeDefinition enumType = (EnumTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, enumType.getQName());
+                result = new EnumerationType(newSchemaPath,
+                        (EnumPair) enumType.getDefaultValue(),
+                        enumType.getValues(), enumType.getUnits());
+            } else if (nodeType instanceof IdentityrefTypeDefinition) {
+                IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, idrefType.getQName());
+                result = new IdentityrefType(idrefType.getIdentity(),
+                        newSchemaPath);
+            } else if (nodeType instanceof InstanceIdentifierTypeDefinition) {
+                InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, instIdType.getQName());
+                return new InstanceIdentifier(newSchemaPath,
+                        instIdType.getPathStatement(),
+                        instIdType.requireInstance());
+            } else if (nodeType instanceof StringTypeDefinition) {
+                result = copyStringType(parentSchemaPath, nodeQName,
+                        (StringTypeDefinition) nodeType);
+            } else if (nodeType instanceof IntegerTypeDefinition) {
+                result = copyIntType(parentSchemaPath, nodeQName,
+                        (IntegerTypeDefinition) nodeType);
+            } else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
+                result = copyUIntType(parentSchemaPath, nodeQName,
+                        (UnsignedIntegerTypeDefinition) nodeType);
+            } else if (nodeType instanceof LeafrefTypeDefinition) {
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, nodeType.getQName());
+                result = new Leafref(newSchemaPath,
+                        ((LeafrefTypeDefinition) nodeType).getPathStatement());
+            } else if (nodeType instanceof UnionTypeDefinition) {
+                UnionTypeDefinition unionType = (UnionTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, unionType.getQName());
                 return new UnionType(newSchemaPath, unionType.getTypes());
             }
         }
         return result;
     }
 
-    private static TypeDefinition<?> copyStringType(SchemaPath schemaPath, QName nodeQName, StringTypeDefinition nodeType) {
+    private static TypeDefinition<?> copyStringType(SchemaPath schemaPath,
+            QName nodeQName, StringTypeDefinition nodeType) {
         List<QName> path = schemaPath.getPath();
         List<QName> newPath = new ArrayList<QName>(path);
         newPath.add(nodeQName);
         newPath.add(nodeType.getQName());
-        SchemaPath newSchemaPath = new SchemaPath(newPath, schemaPath.isAbsolute());
+        SchemaPath newSchemaPath = new SchemaPath(newPath,
+                schemaPath.isAbsolute());
 
         String newDefault = nodeType.getDefaultValue().toString();
         String newUnits = nodeType.getUnits();
         List<LengthConstraint> lengths = nodeType.getLengthStatements();
         List<PatternConstraint> patterns = nodeType.getPatterns();
 
-        return new StringType(newSchemaPath, newDefault, lengths, patterns, newUnits);
+        return new StringType(newSchemaPath, newDefault, lengths, patterns,
+                newUnits);
     }
 
-    private static TypeDefinition<?> copyIntType(SchemaPath schemaPath, QName nodeQName, IntegerTypeDefinition type) {
+    private static TypeDefinition<?> copyIntType(SchemaPath schemaPath,
+            QName nodeQName, IntegerTypeDefinition type) {
         QName typeQName = type.getQName();
-        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
+                typeQName);
 
         String localName = typeQName.getLocalName();
         List<RangeConstraint> ranges = type.getRangeStatements();
         String units = type.getUnits();
 
-        if("int8".equals(localName)) {
-            Byte defaultValue = (Byte)type.getDefaultValue();
+        if ("int8".equals(localName)) {
+            Byte defaultValue = (Byte) type.getDefaultValue();
             return new Int8(newSchemaPath, ranges, units, defaultValue);
-        } else if("int16".equals(localName)) {
-            Short defaultValue = (Short)type.getDefaultValue();
+        } else if ("int16".equals(localName)) {
+            Short defaultValue = (Short) type.getDefaultValue();
             return new Int16(newSchemaPath, ranges, units, defaultValue);
-        } else if("int32".equals(localName)) {
-            Integer defaultValue = (Integer)type.getDefaultValue();
+        } else if ("int32".equals(localName)) {
+            Integer defaultValue = (Integer) type.getDefaultValue();
             return new Int32(newSchemaPath, ranges, units, defaultValue);
-        } else if("int64".equals(localName)) {
-            Long defaultValue = (Long)type.getDefaultValue();
+        } else if ("int64".equals(localName)) {
+            Long defaultValue = (Long) type.getDefaultValue();
             return new Int64(newSchemaPath, ranges, units, defaultValue);
         } else {
             return null;
         }
     }
 
-    private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath, QName nodeQName, UnsignedIntegerTypeDefinition type) {
+    private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath,
+            QName nodeQName, UnsignedIntegerTypeDefinition type) {
         QName typeQName = type.getQName();
-        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
+                typeQName);
 
         String localName = typeQName.getLocalName();
         List<RangeConstraint> ranges = type.getRangeStatements();
         String units = type.getUnits();
 
-        if("uint8".equals(localName)) {
-            Byte defaultValue = (Byte)type.getDefaultValue();
+        if ("uint8".equals(localName)) {
+            Byte defaultValue = (Byte) type.getDefaultValue();
             return new Int8(newSchemaPath, ranges, units, defaultValue);
-        } else if("uint16".equals(localName)) {
-            Short defaultValue = (Short)type.getDefaultValue();
+        } else if ("uint16".equals(localName)) {
+            Short defaultValue = (Short) type.getDefaultValue();
             return new Int16(newSchemaPath, ranges, units, defaultValue);
-        } else if("uint32".equals(localName)) {
-            Integer defaultValue = (Integer)type.getDefaultValue();
+        } else if ("uint32".equals(localName)) {
+            Integer defaultValue = (Integer) type.getDefaultValue();
             return new Int32(newSchemaPath, ranges, units, defaultValue);
-        } else if("uint64".equals(localName)) {
-            Long defaultValue = (Long)type.getDefaultValue();
+        } else if ("uint64".equals(localName)) {
+            Long defaultValue = (Long) type.getDefaultValue();
             return new Int64(newSchemaPath, ranges, units, defaultValue);
         } else {
             return null;
         }
     }
 
-    private static SchemaPath createNewSchemaPath(SchemaPath schemaPath, QName currentQName, QName qname) {
+    private static SchemaPath createNewSchemaPath(SchemaPath schemaPath,
+            QName currentQName, QName qname) {
         List<QName> newPath = new ArrayList<QName>(schemaPath.getPath());
         newPath.add(currentQName);
         newPath.add(qname);
@@ -426,6 +476,92 @@ public final class ParserUtils {
         }
     }
 
+    public static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
+        String name = node.getQName().getLocalName();
+        int line = refine.getLine();
+
+        String defaultStr = refine.getDefaultStr();
+        Boolean mandatory = refine.isMandatory();
+        Boolean presence = refine.isPresence();
+        MustDefinition must = refine.getMust();
+        Integer min = refine.getMinElements();
+        Integer max = refine.getMaxElements();
+
+        if (node instanceof AnyXmlBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefinePresence(node, presence, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof ChoiceBuilder) {
+            checkRefinePresence(node, presence, line);
+            checkRefineMust(node, must, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof ContainerSchemaNodeBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefineMandatory(node, mandatory, line);
+            checkRefineMust(node, must, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof LeafSchemaNodeBuilder) {
+            checkRefinePresence(node, presence, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof LeafListSchemaNodeBuilder
+                || node instanceof ListSchemaNodeBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefinePresence(node, presence, line);
+            checkRefineMandatory(node, mandatory, line);
+        } else if (node instanceof GroupingBuilder
+                || node instanceof TypeDefinitionBuilder
+                || node instanceof UsesNodeBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefinePresence(node, presence, line);
+            checkRefineMandatory(node, mandatory, line);
+            checkRefineMust(node, must, line);
+            checkRefineMinMax(name, line, min, max);
+        }
+    }
+
+    private static void checkRefineDefault(SchemaNodeBuilder node,
+            String defaultStr, int line) {
+        if (defaultStr != null) {
+            throw new YangParseException(line, "Can not refine 'default' for '"
+                    + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefineMandatory(SchemaNodeBuilder node,
+            Boolean mandatory, int line) {
+        if (mandatory != null) {
+            throw new YangParseException(line,
+                    "Can not refine 'mandatory' for '"
+                            + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefinePresence(SchemaNodeBuilder node,
+            Boolean presence, int line) {
+        if (presence != null) {
+            throw new YangParseException(line,
+                    "Can not refine 'presence' for '"
+                            + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefineMust(SchemaNodeBuilder node,
+            MustDefinition must, int line) {
+        if (must != null) {
+            throw new YangParseException(line, "Can not refine 'must' for '"
+                    + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefineMinMax(String refineTargetName,
+            int refineLine, Integer min, Integer max) {
+        if (min != null || max != null) {
+            throw new YangParseException(refineLine,
+                    "Can not refine 'min-elements' or 'max-elements' for '"
+                            + refineTargetName + "'.");
+        }
+    }
+
     /**
      * Perform refine operation of following parameters:
      * <ul>
@@ -490,7 +626,7 @@ public final class ParserUtils {
         final TypeDefinition<?> type = old.getType();
 
         if (type == null) {
-            copy.setType(old.getTypedef());
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(type);
         }
@@ -524,7 +660,7 @@ public final class ParserUtils {
         for (GroupingBuilder grouping : old.getGroupings()) {
             copy.addGrouping(grouping);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
             copy.addTypedef(typedef);
         }
         for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
@@ -557,7 +693,7 @@ public final class ParserUtils {
         for (GroupingBuilder grouping : old.getGroupings()) {
             copy.addGrouping(grouping);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
             copy.addTypedef(typedef);
         }
         for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
@@ -583,7 +719,7 @@ public final class ParserUtils {
         copyConstraints(old, copy);
         final TypeDefinition<?> type = old.getType();
         if (type == null) {
-            copy.setType(old.getTypedef());
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(type);
         }
@@ -610,12 +746,6 @@ public final class ParserUtils {
         for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
             copy.addUnknownSchemaNode(unknown);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
-            copy.addTypedef(typedef);
-        }
-        for (UsesNodeBuilder use : old.getUsesNodes()) {
-            copy.addUsesNode(use);
-        }
         copy.setDefaultCase(old.getDefaultCase());
         copy.setDescription(old.getDescription());
         copy.setReference(old.getReference());
@@ -650,7 +780,7 @@ public final class ParserUtils {
         for (GroupingBuilder grouping : old.getGroupings()) {
             copy.addGrouping(grouping);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
             copy.addTypedef(typedef);
         }
         for (UsesNodeBuilder use : old.getUses()) {
@@ -665,9 +795,10 @@ public final class ParserUtils {
         return copy;
     }
 
-    public static TypedefBuilder copyTypedefBuilder(TypedefBuilder old) {
-        final TypedefBuilder copy = new TypedefBuilder(old.getQName(),
-                old.getLine());
+    public static TypeDefinitionBuilderImpl copyTypedefBuilder(
+            TypeDefinitionBuilderImpl old) {
+        final TypeDefinitionBuilderImpl copy = new TypeDefinitionBuilderImpl(
+                old.getQName(), old.getLine());
         copy.setPath(old.getPath());
         copy.setDefaultValue(old.getDefaultValue());
         copy.setUnits(old.getUnits());
@@ -681,8 +812,8 @@ public final class ParserUtils {
         copy.setFractionDigits(old.getFractionDigits());
 
         TypeDefinition<?> type = old.getType();
-        if(type == null) {
-            copy.setType(old.getTypedef());
+        if (type == null) {
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(old.getType());
         }
index babd0d06f6a7bb217bf12de36b863be569921c56..3d9df349e4ec5a390518b67fdaadb5640b51dd86 100644 (file)
@@ -9,11 +9,14 @@ package org.opendaylight.controller.yang.parser.impl;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
@@ -45,6 +48,28 @@ final class TestUtils {
         return parser.parseYangModels(testFiles);
     }
 
+    public static Set<Module> loadModules(String... pathToYangFile) throws IOException {
+        YangModelParser parser = new YangParserImpl();
+        List<InputStream> input = new ArrayList<InputStream>();
+        for(String path : pathToYangFile) {
+            input.add(TestUtils.class.getResourceAsStream(path));
+        }
+        Set<Module> modules = parser.parseYangModelsFromStreams(input);
+        for(InputStream stream : input) {
+            stream.close();
+        }
+        return modules;
+    }
+
+    public static Module loadModule(String pathToYangFile) throws IOException {
+        YangModelParser parser = new YangParserImpl();
+        InputStream stream = TestUtils.class.getResourceAsStream(pathToYangFile);
+        List<InputStream> input = Collections.singletonList(stream);
+        Set<Module> modules = parser.parseYangModelsFromStreams(input);
+        stream.close();
+        return modules.iterator().next();
+    }
+
     public static Module findModule(Set<Module> modules, String moduleName) {
         Module result = null;
         for (Module module : modules) {
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java
new file mode 100644 (file)
index 0000000..be44c6f
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
+import org.opendaylight.controller.yang.parser.util.YangValidationException;
+
+public class YangParserNegativeTest {
+
+    @Test
+    public void testInvalidImport() throws IOException {
+        try {
+            TestUtils.loadModule("/negative-scenario/testfile1.yang");
+            fail("ValidationException should by thrown");
+        } catch(YangValidationException e) {
+            assertTrue(e.getMessage().contains("Not existing module imported"));
+        }
+    }
+
+    @Test
+    public void testTypeNotFound() throws IOException {
+        try {
+            TestUtils.loadModule("/negative-scenario/testfile2.yang");
+            fail("YangParseException should by thrown");
+        } catch(YangParseException e) {
+            assertTrue(e.getMessage().contains("Error in module 'test2' on line 24: Referenced type 'int-ext' not found."));
+        }
+    }
+
+    @Test
+    public void testInvalidAugmentTarget() throws IOException {
+        try {
+            TestUtils.loadModules("/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang");
+            fail("YangParseException should by thrown");
+        } catch(YangParseException e) {
+            assertTrue(e.getMessage().contains("Failed to resolve augments in module 'test3'."));
+        }
+    }
+
+    @Test
+    public void testInvalidRefine() throws IOException {
+        try {
+            TestUtils.loadModule("/negative-scenario/testfile4.yang");
+            fail("YangParseException should by thrown");
+        } catch(YangParseException e) {
+            assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'."));
+        }
+    }
+
+}
index 9463410af8395d3232f581920fc05b930527de13..fd2593ba4805fade12bb2193e7a3d4cf94a5b097 100644 (file)
@@ -601,11 +601,7 @@ public class YangParserTest {
         assertNotNull(refineContainer);
         Set<MustDefinition> mustConstraints = refineContainer.getConstraints()
                 .getMustConstraints();
-        assertEquals(1, mustConstraints.size());
-        MustDefinition must = mustConstraints.iterator().next();
-        assertEquals("must-condition", must.toString());
-        assertEquals("An error message test", must.getErrorMessage());
-        assertEquals(("An error app tag test"), must.getErrorAppTag());
+        assertTrue(mustConstraints.isEmpty());
         assertEquals("description of port defined by refine",
                 refineContainer.getDescription());
         assertEquals("port reference added by refine",
index 619a5c3e104a1ecd3dcc331ee235a3647cd47ebd..4ec69c18b229bb7bc4055bf7140b526c0378da2f 100644 (file)
@@ -124,5 +124,17 @@ module types1 {
             }
         }
     }
-
+    
+    container mycont {
+        container innercont {
+            typedef mytype {
+                type string;
+            }
+        
+            leaf myleaf {
+                type mytype;
+            }
+        }
+    }
+    
 }
index b779c3ca34c88bc1ee9b579a7a3878df943feeeb..8860e06622fee0d1128649f3386a392138d35aa2 100644 (file)
@@ -205,10 +205,6 @@ module types2 {
                     }
                 }
                 refine port {
-                    must "must-condition" {
-                        error-message "An error message test";
-                        error-app-tag "An error app tag test";
-                    }
                     description "description of port defined by refine";
                     reference "port reference added by refine";
                     config false;
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile0.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile0.yang
new file mode 100644 (file)
index 0000000..ea60ba9
--- /dev/null
@@ -0,0 +1,9 @@
+module test0 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+    
+    container interfaces {
+    
+    }
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile1.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile1.yang
new file mode 100644 (file)
index 0000000..fdc7e71
--- /dev/null
@@ -0,0 +1,11 @@
+module test1 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+
+    import some-module {
+        prefix "data";
+        revision-date 2013-02-27;
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile2.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile2.yang
new file mode 100644 (file)
index 0000000..ea5a11f
--- /dev/null
@@ -0,0 +1,29 @@
+module test2 {
+    yang-version 1;
+    namespace "urn:simple.types.data.demo";
+    prefix "t2";
+    
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+    
+    description "This is types-data test description";
+
+    revision "2013-02-27" {
+        reference " WILL BE DEFINED LATER";
+    }
+    
+    container c1 {
+        typedef int-ext {
+            type int32 {
+                range "10..20";
+            }
+        }
+    }
+    
+    container top {
+        leaf id {
+            type int-ext;
+        }
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile3.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile3.yang
new file mode 100644 (file)
index 0000000..187e9dd
--- /dev/null
@@ -0,0 +1,19 @@
+module test3 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+
+    import test0 {
+        prefix "data";
+    }
+    
+    augment "/data:unknown" {
+        when "if:ifType='ds0'";
+        leaf interface-id {
+            type leafref {
+                path "/if:interfaces/if:interface/if:name";
+            }
+        }
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile4.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile4.yang
new file mode 100644 (file)
index 0000000..c327de3
--- /dev/null
@@ -0,0 +1,26 @@
+module test4 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+
+    grouping tree {
+        leaf-list node {
+            type string;
+        }
+        container holder {
+        
+        }
+    }
+
+    container schema {
+        uses tree {
+            refine node {
+                presence "true";
+            }
+            refine holder {
+                default "one";
+            }
+        }
+    }
+
+}