Minor code refactoring and improvements. 79/579/2
authorMartin Vitez <mvitez@cisco.com>
Tue, 9 Jul 2013 15:10:20 +0000 (17:10 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 10 Jul 2013 06:35:37 +0000 (08:35 +0200)
Change-Id: Ifdc5b45e610037ef14eed6c97885deb1075aa884
Signed-off-by: Martin Vitez <mvitez@cisco.com>
19 files changed:
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractDataNodeContainerBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractSchemaNodeBuilder.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/DeviationBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ExtensionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/FeatureBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/IdentitySchemaNodeBuilder.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/UnknownSchemaNodeBuilder.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/ParserListenerUtils.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/YangParserWithContextTest.java
opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Deviation.java

index 116f82e..091bfc7 100644 (file)
@@ -7,12 +7,14 @@
  */
 package org.opendaylight.controller.yang.parser.builder.api;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
     protected final int line;
@@ -52,6 +54,9 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
 
     @Override
     public Set<DataSchemaNode> getChildNodes() {
+        if (childNodes == null) {
+            return Collections.emptySet();
+        }
         return childNodes;
     }
 
@@ -66,8 +71,8 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
 
     @Override
     public DataSchemaNodeBuilder getDataChildByName(final String name) {
-        for(DataSchemaNodeBuilder child : addedChildNodes) {
-            if(child.getQName().getLocalName().equals(name)) {
+        for (DataSchemaNodeBuilder child : addedChildNodes) {
+            if (child.getQName().getLocalName().equals(name)) {
                 return child;
             }
         }
@@ -75,12 +80,20 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
     }
 
     @Override
-    public void addChildNode(DataSchemaNodeBuilder childNode) {
-        addedChildNodes.add(childNode);
+    public void addChildNode(DataSchemaNodeBuilder child) {
+        for (DataSchemaNodeBuilder childNode : addedChildNodes) {
+            if (childNode.getQName().getLocalName().equals(child.getQName().getLocalName())) {
+                throw new YangParseException(child.getLine(), "Duplicate node found at line " + childNode.getLine());
+            }
+        }
+        addedChildNodes.add(child);
     }
 
     @Override
     public Set<GroupingDefinition> getGroupings() {
+        if (groupings == null) {
+            return Collections.emptySet();
+        }
         return groupings;
     }
 
@@ -93,8 +106,13 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
     }
 
     @Override
-    public void addGrouping(GroupingBuilder grouping) {
-        addedGroupings.add(grouping);
+    public void addGrouping(GroupingBuilder groupingBuilder) {
+        for (GroupingBuilder gb : addedGroupings) {
+            if (gb.getQName().getLocalName().equals(groupingBuilder.getQName().getLocalName())) {
+                throw new YangParseException(groupingBuilder.getLine(), "Duplicate node found at line " + gb.getLine());
+            }
+        }
+        addedGroupings.add(groupingBuilder);
     }
 
 }
index 1963c6c..8659cac 100644 (file)
@@ -13,6 +13,7 @@ import java.util.List;
 import org.opendaylight.controller.yang.common.QName;\r
 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
 import org.opendaylight.controller.yang.model.api.Status;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;\r
 \r
 /**\r
@@ -26,6 +27,7 @@ public abstract class AbstractSchemaNodeBuilder implements SchemaNodeBuilder {
     protected String description;\r
     protected String reference;\r
     protected Status status = Status.CURRENT;\r
+    protected List<UnknownSchemaNode> unknownNodes;\r
     protected final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
 \r
     protected AbstractSchemaNodeBuilder(final int line, final QName qname) {\r
@@ -52,34 +54,42 @@ public abstract class AbstractSchemaNodeBuilder implements SchemaNodeBuilder {
         this.parent = parent;\r
     }\r
 \r
+    @Override\r
     public SchemaPath getPath() {\r
         return schemaPath;\r
     }\r
 \r
+    @Override\r
     public void setPath(SchemaPath schemaPath) {\r
         this.schemaPath = schemaPath;\r
     }\r
 \r
+    @Override\r
     public String getDescription() {\r
         return description;\r
     }\r
 \r
+    @Override\r
     public void setDescription(String description) {\r
         this.description = description;\r
     }\r
 \r
+    @Override\r
     public String getReference() {\r
         return reference;\r
     }\r
 \r
+    @Override\r
     public void setReference(String reference) {\r
         this.reference = reference;\r
     }\r
 \r
+    @Override\r
     public Status getStatus() {\r
         return status;\r
     }\r
 \r
+    @Override\r
     public void setStatus(Status status) {\r
         if (status != null) {\r
             this.status = status;\r
@@ -91,4 +101,8 @@ public abstract class AbstractSchemaNodeBuilder implements SchemaNodeBuilder {
         addedUnknownNodes.add(unknownNode);\r
     }\r
 \r
+    public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {\r
+        this.unknownNodes = unknownNodes;\r
+    }\r
+\r
 }\r
index dd89060..a2dacc2 100644 (file)
@@ -28,7 +28,6 @@ public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements Da
     private boolean built;
     private final AnyXmlSchemaNodeImpl instance;
     private final ConstraintsBuilder constraints;
-    private List<UnknownSchemaNode> unknownNodes;
 
     private Boolean configuration;
     private boolean augmenting;
@@ -93,10 +92,6 @@ public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements Da
         return addedUnknownNodes;
     }
 
-    public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
-        this.unknownNodes = unknownNodes;
-    }
-
     @Override
     public boolean isAugmenting() {
         return augmenting;
index d3082e8..7fcee2e 100644 (file)
@@ -27,8 +27,8 @@ 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.model.util.RevisionAwareXPathImpl;
+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.Builder;
 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;
@@ -37,11 +37,10 @@ import org.opendaylight.controller.yang.parser.util.Comparators;
 import org.opendaylight.controller.yang.parser.util.ParserListenerUtils;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder {
+public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContainerBuilder implements
+        AugmentationSchemaBuilder {
     private boolean built;
     private final AugmentationSchemaImpl instance;
-    private final int line;
-    private Builder parent;
 
     private String whenCondition;
     private String description;
@@ -52,60 +51,18 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
     private SchemaPath dirtyAugmentTarget;
     private SchemaPath finalAugmentTarget;
 
-    private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
-    private final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
     private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     private boolean resolved;
 
     AugmentationSchemaBuilderImpl(final int line, final String augmentTargetStr) {
+        super(line, null);
         this.augmentTargetStr = augmentTargetStr;
-        this.line = line;
         final SchemaPath targetPath = ParserListenerUtils.parseAugmentPath(augmentTargetStr);
         dirtyAugmentTarget = targetPath;
         instance = new AugmentationSchemaImpl(targetPath);
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
-    @Override
-    public Builder getParent() {
-        return parent;
-    }
-
-    @Override
-    public void setParent(final Builder parent) {
-        this.parent = parent;
-    }
-
-    @Override
-    public void addChildNode(DataSchemaNodeBuilder childNode) {
-        childNodes.add(childNode);
-    }
-
-    @Override
-    public Set<DataSchemaNode> getChildNodes() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public DataSchemaNodeBuilder getDataChildByName(final String name) {
-        for(DataSchemaNodeBuilder child : childNodes) {
-            if(child.getQName().getLocalName().equals(name)) {
-                return child;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
-        return childNodes;
-    }
-
     @Override
     public Set<GroupingDefinition> getGroupings() {
         return Collections.emptySet();
@@ -113,12 +70,12 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
 
     @Override
     public Set<GroupingBuilder> getGroupingBuilders() {
-        return groupings;
+        return Collections.emptySet();
     }
 
     @Override
     public void addGrouping(GroupingBuilder grouping) {
-        groupings.add(grouping);
+        throw new YangParseException(line, "augment can not contains grouping statement");
     }
 
     @Override
@@ -126,14 +83,6 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         usesNodes.add(usesBuilder);
     }
 
-    /**
-     * Always returns null.
-     */
-    @Override
-    public QName getQName() {
-        return null;
-    }
-
     /**
      * Always returns null.
      */
@@ -160,19 +109,11 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
 
             // CHILD NODES
             final Map<QName, DataSchemaNode> childs = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
-            for (DataSchemaNodeBuilder node : childNodes) {
+            for (DataSchemaNodeBuilder node : addedChildNodes) {
                 childs.put(node.getQName(), node.build());
             }
             instance.setChildNodes(childs);
 
-            // GROUPINGS
-            final Set<GroupingDefinition> groupingDefinitions = new TreeSet<GroupingDefinition>(
-                    Comparators.SCHEMA_NODE_COMP);
-            for (GroupingBuilder builder : groupings) {
-                groupingDefinitions.add(builder.build());
-            }
-            instance.setGroupings(groupingDefinitions);
-
             // USES
             final Set<UsesNode> usesNodeDefinitions = new HashSet<UsesNode>();
             for (UsesNodeBuilder builder : usesNodes) {
@@ -316,7 +257,6 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         private SchemaPath targetPath;
         private RevisionAwareXPath whenCondition;
         private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
-        private Set<GroupingDefinition> groupings = Collections.emptySet();
         private Set<UsesNode> uses = Collections.emptySet();
         private String description;
         private String reference;
@@ -358,15 +298,13 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
             }
         }
 
+        /**
+         * Always returns an empty set, because augment can not contains
+         * grouping statement.
+         */
         @Override
         public Set<GroupingDefinition> getGroupings() {
-            return groupings;
-        }
-
-        private void setGroupings(Set<GroupingDefinition> groupings) {
-            if (groupings != null) {
-                this.groupings = groupings;
-            }
+            return Collections.emptySet();
         }
 
         @Override
@@ -381,8 +319,8 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         }
 
         /**
-         * Always returns an empty set, because augmentation can not contains
-         * type definitions.
+         * Always returns an empty set, because augment can not contains type
+         * definitions.
          */
         @Override
         public Set<TypeDefinition<?>> getTypeDefinitions() {
index 01acc11..7ed47bf 100644 (file)
@@ -35,8 +35,6 @@ public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements Da
         AugmentationTargetBuilder, GroupingMember, ConfigNode {
     private boolean isBuilt;
     private final ChoiceNodeImpl instance;
-    // SchemaNode args
-    private List<UnknownSchemaNode> unknownNodes;
     // DataSchemaNode args
     private boolean augmenting;
     private boolean addedByUses;
@@ -197,10 +195,6 @@ public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements Da
         return addedUnknownNodes;
     }
 
-    public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
-        this.unknownNodes = unknownNodes;
-    }
-
     public String getDefaultCase() {
         return defaultCase;
     }
index a0ee47f..764d2bf 100644 (file)
@@ -37,11 +37,13 @@ public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
             instance.setStatus(status);
 
             // UNKNOWN NODES
-            final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-            for (UnknownSchemaNodeBuilder un : addedUnknownNodes) {
-                unknownNodes.add(un.build());
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder un : addedUnknownNodes) {
+                    unknownNodes.add(un.build());
+                }
+                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             }
-            Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             instance.setUnknownSchemaNodes(unknownNodes);
 
             isBuilt = true;
index c5dd60a..4d5ce97 100644 (file)
@@ -37,11 +37,13 @@ public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
             instance.setStatus(status);
 
             // UNKNOWN NODES
-            final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
-                unknownNodes.add(b.build());
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                    unknownNodes.add(b.build());
+                }
+                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             }
-            Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             instance.setUnknownSchemaNodes(unknownNodes);
 
             isBuilt = true;
index 14fca7d..96b4bd4 100644 (file)
@@ -48,11 +48,13 @@ public final class IdentitySchemaNodeBuilder extends AbstractSchemaNodeBuilder {
             }
 
             // UNKNOWN NODES
-            final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
-                unknownNodes.add(b.build());
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                    unknownNodes.add(b.build());
+                }
+                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             }
-            Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             instance.setUnknownSchemaNodes(unknownNodes);
 
             isBuilt = true;
index 484461e..47f1fbc 100644 (file)
@@ -11,7 +11,6 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -37,6 +36,7 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 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.AbstractDataNodeContainerBuilder;
 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.DataNodeContainerBuilder;
@@ -51,11 +51,11 @@ import org.opendaylight.controller.yang.parser.util.RefineHolder;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 /**
- * This builder builds Module object. If this module is dependent on external
+ * Builder of Module object. If this module is dependent on external
  * module/modules, these dependencies must be resolved before module is built,
  * otherwise result may not be valid.
  */
-public class ModuleBuilder implements DataNodeContainerBuilder {
+public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     private final ModuleImpl instance;
     private final String name;
     private URI namespace;
@@ -64,15 +64,10 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
 
     private int augmentsResolved;
 
-    private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
-
-    /**
-     * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
-     * list, leaf, leaf-list.
-     */
-    private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
+    private final LinkedList<Builder> actualPath = new LinkedList<Builder>();
+    private final Set<TypeAwareBuilder> dirtyNodes = new HashSet<TypeAwareBuilder>();
 
-    private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
+    private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
     private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();
     private final List<AugmentationSchemaBuilder> allAugments = new ArrayList<AugmentationSchemaBuilder>();
     private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
@@ -83,15 +78,12 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
     private final Set<FeatureBuilder> addedFeatures = new HashSet<FeatureBuilder>();
     private final Set<DeviationBuilder> addedDeviations = new HashSet<DeviationBuilder>();
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
-    private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
     private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
-    private final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes = new HashMap<List<String>, List<UnknownSchemaNodeBuilder>>();
-
-    private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
-
-    private final LinkedList<Builder> actualPath = new LinkedList<Builder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> allUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     public ModuleBuilder(final String name) {
+        super(0, null);
         this.name = name;
         instance = new ModuleImpl(name);
     }
@@ -115,7 +107,7 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
 
         // CHILD NODES
         final Map<QName, DataSchemaNode> children = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
-        for (DataSchemaNodeBuilder child : childNodes) {
+        for (DataSchemaNodeBuilder child : addedChildNodes) {
             children.put(child.getQName(), child.build());
         }
         instance.setChildNodes(children);
@@ -186,32 +178,20 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         instance.setIdentities(identities);
 
         // UNKNOWN NODES
-        final List<UnknownSchemaNode> unknownNodes = buildModuleUnknownNodes(addedUnknownNodes);
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for (UnknownSchemaNodeBuilder unb : addedUnknownNodes) {
+            unknownNodes.add(unb.build());
+        }
         instance.setUnknownSchemaNodes(unknownNodes);
 
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return 0;
-    }
-
-    @Override
-    public Builder getParent() {
-        return null;
-    }
-
     @Override
     public void setParent(Builder parent) {
         throw new YangParseException(name, 0, "Can not set parent to module");
     }
 
-    @Override
-    public QName getQName() {
-        return new QName(namespace, revision, prefix, name);
-    }
-
     @Override
     public SchemaPath getPath() {
         return null;
@@ -246,36 +226,7 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         }
     }
 
-    @Override
-    public Set<GroupingDefinition> getGroupings() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public Set<GroupingBuilder> getGroupingBuilders() {
-        return addedGroupings;
-    }
-
-    @Override
-    public Set<DataSchemaNode> getChildNodes() {
-        return Collections.emptySet();
-    }
-
-    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
-        return childNodes;
-    }
-
-    @Override
-    public DataSchemaNodeBuilder getDataChildByName(final String name) {
-        for(DataSchemaNodeBuilder child : childNodes) {
-            if(child.getQName().getLocalName().equals(name)) {
-                return child;
-            }
-        }
-        return null;
-    }
-
-    public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
+    public Set<TypeAwareBuilder> getDirtyNodes() {
         return dirtyNodes;
     }
 
@@ -295,12 +246,8 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         return addedDeviations;
     }
 
-    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
-        List<UnknownSchemaNodeBuilder> result = new ArrayList<UnknownSchemaNodeBuilder>();
-        for (List<UnknownSchemaNodeBuilder> entry : addedUnknownNodes.values()) {
-            result.addAll(entry);
-        }
-        return result;
+    public List<UnknownSchemaNodeBuilder> getAllUnknownNodes() {
+        return allUnknownNodes;
     }
 
     public String getName() {
@@ -331,10 +278,9 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         augmentsResolved++;
     }
 
-    public void addDirtyNode(final List<String> path) {
-        final List<String> dirtyNodePath = new ArrayList<String>(path);
-        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath.getFirst();
-        dirtyNodes.put(dirtyNodePath, nodeBuilder);
+    public void markActualNodeDirty() {
+        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) getActualNode();
+        dirtyNodes.add(nodeBuilder);
     }
 
     public void setRevision(final Date revision) {
@@ -380,17 +326,6 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         return builder;
     }
 
-    @Override
-    public void addChildNode(DataSchemaNodeBuilder child) {
-        for (DataSchemaNodeBuilder childNode : childNodes) {
-            if (childNode.getQName().getLocalName().equals(child.getQName().getLocalName())) {
-                throw new YangParseException(name, child.getLine(), "Duplicate node found at line "
-                        + childNode.getLine());
-            }
-        }
-        childNodes.add(child);
-    }
-
     public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName containerName,
             final SchemaPath schemaPath) {
         final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(line, containerName, schemaPath);
@@ -433,17 +368,6 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         return builder;
     }
 
-    @Override
-    public void addGrouping(GroupingBuilder groupingBuilder) {
-        for (GroupingBuilder gb : addedGroupings) {
-            if (gb.getQName().getLocalName().equals(groupingBuilder.getQName().getLocalName())) {
-                throw new YangParseException(name, groupingBuilder.getLine(), "Duplicate node found at line "
-                        + gb.getLine());
-            }
-        }
-        addedGroupings.add(groupingBuilder);
-    }
-
     public GroupingBuilder addGrouping(final int line, final QName qname) {
         final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
 
@@ -720,50 +644,39 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         Builder parent = getActualNode();
         if (parent == null || !(parent instanceof TypeAwareBuilder)) {
             throw new YangParseException("Failed to set type '" + type.getQName().getLocalName()
-                    + "'. Unknown parent node: " + parent);
+                    + "'. Invalid parent node: " + parent);
         }
         ((TypeAwareBuilder) parent).setType(type);
     }
 
-    public UnionTypeBuilder addUnionType(final List<String> currentPath, final URI namespace, final Date revision,
-            final int line) {
-        final List<String> pathToUnion = new ArrayList<String>(currentPath);
-        final UnionTypeBuilder union = new UnionTypeBuilder(line);
-
-        if (actualPath.isEmpty()) {
-            throw new YangParseException(line, "union error");
+    public UnionTypeBuilder addUnionType(final int line, final URI namespace, final Date revision) {
+        final Builder parent = getActualNode();
+        if (parent == null) {
+            throw new YangParseException(line, "Error while parsing union type");
         } else {
-            final Builder parent = actualPath.getFirst();
+            final UnionTypeBuilder union = new UnionTypeBuilder(line);
             if (parent instanceof TypeAwareBuilder) {
-
                 ((TypeAwareBuilder) parent).setTypedef(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.");
+                throw new YangParseException(name, line, "Invalid parent of union type.");
             }
         }
     }
 
-    public void addIdentityrefType(final String baseString, final List<String> parentPath, final SchemaPath schemaPath,
-            final int line) {
-        final List<String> pathToIdentityref = new ArrayList<String>(parentPath);
+    public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) {
         final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString, schemaPath, line);
 
-        if (actualPath.isEmpty()) {
-            throw new YangParseException(line, "identityref error");
+        final Builder parent = getActualNode();
+        if (parent == null) {
+            throw new YangParseException(line, "Error while parsing identityref type.");
         } else {
-            final Builder parent = actualPath.getFirst();
             if (parent instanceof TypeAwareBuilder) {
                 final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
                 typeParent.setTypedef(identityref);
-                dirtyNodes.put(pathToIdentityref, typeParent);
+                dirtyNodes.add(typeParent);
             } else {
-                throw new YangParseException(name, line, "Unresolved parent of identityref type.");
+                throw new YangParseException(name, line, "Invalid parent of identityref type.");
             }
         }
     }
@@ -796,29 +709,24 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
     }
 
     @Override
-    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder builder) {
-        final List<String> unPath = new ArrayList<String>();
-        for (QName name : builder.getPath().getPath()) {
-            unPath.add(name.getLocalName());
-        }
-        if (addedUnknownNodes.containsKey(unPath)) {
-            addedUnknownNodes.get(unPath).add(builder);
-        } else {
-            List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
-            nodes.add(builder);
-            addedUnknownNodes.put(unPath, nodes);
-        }
+    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder builder) {
+        addedUnknownNodes.add(builder);
+        allUnknownNodes.add(builder);
     }
 
-    public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname, final List<String> parentPath,
-            final int line) {
+    public UnknownSchemaNodeBuilder addUnknownSchemaNode(final int line, final QName qname) {
         final Builder parent = getActualNode();
         final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(line, qname);
         builder.setParent(parent);
+        allUnknownNodes.add(builder);
 
-        if (parent != null) {
+        if (parent == null) {
+            addedUnknownNodes.add(builder);
+        } else {
             if (parent instanceof SchemaNodeBuilder) {
                 ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+            } else if (parent instanceof DataNodeContainerBuilder) {
+                ((DataNodeContainerBuilder) parent).addUnknownSchemaNode(builder);
             } else if (parent instanceof RefineHolder) {
                 ((RefineHolder) parent).addUnknownSchemaNode(builder);
             } else {
@@ -826,22 +734,13 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
                         + "'");
             }
         }
-        final List<String> unPath = new ArrayList<String>(parentPath);
-        unPath.add(qname.getLocalName());
 
-        if (addedUnknownNodes.containsKey(unPath)) {
-            addedUnknownNodes.get(unPath).add(builder);
-        } else {
-            List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
-            nodes.add(builder);
-            addedUnknownNodes.put(unPath, nodes);
-        }
         return builder;
     }
 
     @Override
     public String toString() {
-        return ModuleBuilder.class.getSimpleName() + "[" + name + "]";
+        return "module " + name;
     }
 
     private final class ModuleImpl implements Module {
@@ -1193,7 +1092,7 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
             // notifications, and anyxmls defined within a parent node or at the
             // top level of the module or its submodules share the same
             // identifier namespace.
-            for (DataSchemaNodeBuilder childNode : childNodes) {
+            for (DataSchemaNodeBuilder childNode : addedChildNodes) {
                 if (childNode.getQName().getLocalName().equals(childLocalName)) {
                     throw new YangParseException(name, line, "Duplicate node found at line " + childNode.getLine());
                 }
@@ -1208,7 +1107,7 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
                     throw new YangParseException(name, line, "Duplicate node found at line " + notification.getLine());
                 }
             }
-            childNodes.add(child);
+            addedChildNodes.add(child);
         } else {
             // no need for checking rpc and notification because they can be
             // defined only under module or submodule
@@ -1306,30 +1205,4 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         return moduleImport;
     }
 
-    /**
-     * Traverse through given addedUnknownNodes and add only unknown nodes
-     * defined under module statement.
-     *
-     * @param addedUnknownNodes
-     *            unknown node builders
-     * @return list of all unknown nodes defined in module in lexicographical
-     *         order
-     */
-    private List<UnknownSchemaNode> buildModuleUnknownNodes(
-            final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes) {
-        final List<UnknownSchemaNode> result = new ArrayList<UnknownSchemaNode>();
-        for (Map.Entry<List<String>, List<UnknownSchemaNodeBuilder>> entry : addedUnknownNodes.entrySet()) {
-            final List<String> path = entry.getKey();
-            final List<UnknownSchemaNodeBuilder> child = entry.getValue();
-
-            if (path.size() == 2) {
-                for (UnknownSchemaNodeBuilder node : child) {
-                    result.add(node.build());
-                }
-            }
-        }
-        Collections.sort(result, Comparators.SCHEMA_NODE_COMP);
-        return result;
-    }
-
 }
index b9b1519..1c49628 100644 (file)
@@ -40,7 +40,6 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         AugmentationTargetBuilder {
     private boolean isBuilt;
     private final NotificationDefinitionImpl instance;
-    private final int line;
     private SchemaPath schemaPath;
     private String description;
     private String reference;
@@ -53,7 +52,6 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
 
     NotificationBuilder(final int line, final QName qname) {
         super(line, qname);
-        this.line = line;
         instance = new NotificationDefinitionImpl(qname);
     }
 
index d2b8544..65b15c5 100644 (file)
@@ -69,11 +69,13 @@ public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {
             instance.setGroupings(groupings);
 
             // UNKNOWN NODES
-            final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
-                unknownNodes.add(b.build());
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                    unknownNodes.add(b.build());
+                }
+                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             }
-            Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
             instance.setUnknownSchemaNodes(unknownNodes);
 
             isBuilt = true;
@@ -140,6 +142,11 @@ public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {
         return true;
     }
 
+    @Override
+    public String toString() {
+        return "rpc " + qname.getLocalName();
+    }
+
     private final class RpcDefinitionImpl implements RpcDefinition {
         private final QName qname;
         private SchemaPath path;
index 232fa60..267696b 100644 (file)
@@ -22,7 +22,6 @@ public final class UnknownSchemaNodeBuilder extends AbstractSchemaNodeBuilder {
     private boolean isBuilt;
     private final UnknownSchemaNodeImpl instance;
     private boolean addedByUses;
-    private List<UnknownSchemaNode> unknownNodes;
     private QName nodeType;
     private String nodeParameter;
 
@@ -80,10 +79,6 @@ public final class UnknownSchemaNodeBuilder extends AbstractSchemaNodeBuilder {
         this.addedByUses = addedByUses;
     }
 
-    public void setUnknownNodes(final List<UnknownSchemaNode> unknownNodes) {
-        this.unknownNodes = unknownNodes;
-    }
-
     public QName getNodeType() {
         return nodeType;
     }
index 712c84f..5850abe 100644 (file)
@@ -381,11 +381,9 @@ public final class YangParserImpl implements YangModelParser {
      *            current module
      */
     private void resolveDirtyNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
-        final Map<List<String>, TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
+        final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
         if (!dirtyNodes.isEmpty()) {
-            for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes.entrySet()) {
-                final TypeAwareBuilder nodeToResolve = entry.getValue();
-
+            for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
                 if (nodeToResolve instanceof UnionTypeBuilder) {
                     // special handling for union types
                     resolveTypeUnion((UnionTypeBuilder) nodeToResolve, modules, module);
@@ -402,11 +400,9 @@ public final class YangParserImpl implements YangModelParser {
 
     private void resolveDirtyNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module, SchemaContext context) {
-        final Map<List<String>, TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
+        final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
         if (!dirtyNodes.isEmpty()) {
-            for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes.entrySet()) {
-                final TypeAwareBuilder nodeToResolve = entry.getValue();
-
+            for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
                 if (nodeToResolve instanceof UnionTypeBuilder) {
                     // special handling for union types
                     resolveTypeUnionWithContext((UnionTypeBuilder) nodeToResolve, modules, module, context);
@@ -1067,34 +1063,42 @@ public final class YangParserImpl implements YangModelParser {
         DataNodeContainerBuilder parent = usesNode.getParent();
         SchemaPath parentPath = parent.getPath();
         for (DataSchemaNodeBuilder child : targetGrouping.getChildNodeBuilders()) {
-            // if node is refined, take it from refined nodes and continue
-            SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
-            if (refined != null) {
-                refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
-                parent.addChildNode((DataSchemaNodeBuilder) refined);
-                continue;
-            }
+            if (child != null) {
+                // if node is refined, take it from refined nodes and continue
+                SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+                if (refined != null) {
+                    refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+                    parent.addChildNode((DataSchemaNodeBuilder) refined);
+                    continue;
+                }
 
-            DataSchemaNodeBuilder newChild = null;
-            if (child instanceof AnyXmlBuilder) {
-                newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
-            } else if (child instanceof ChoiceBuilder) {
-                newChild = new ChoiceBuilder((ChoiceBuilder) child);
-            } else if (child instanceof ContainerSchemaNodeBuilder) {
-                newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
-            } else if (child instanceof LeafListSchemaNodeBuilder) {
-                newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
-            } else if (child instanceof LeafSchemaNodeBuilder) {
-                newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
-            } else if (child instanceof ListSchemaNodeBuilder) {
-                newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
-            }
+                DataSchemaNodeBuilder newChild = null;
+                if (child instanceof AnyXmlBuilder) {
+                    newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
+                } else if (child instanceof ChoiceBuilder) {
+                    newChild = new ChoiceBuilder((ChoiceBuilder) child);
+                } else if (child instanceof ContainerSchemaNodeBuilder) {
+                    newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
+                } else if (child instanceof LeafListSchemaNodeBuilder) {
+                    newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
+                } else if (child instanceof LeafSchemaNodeBuilder) {
+                    newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
+                } else if (child instanceof ListSchemaNodeBuilder) {
+                    newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
+                }
 
-            if (newChild instanceof GroupingMember) {
-                ((GroupingMember) newChild).setAddedByUses(true);
+                if (newChild == null) {
+                    throw new YangParseException(usesNode.getLine(),
+                            "Unknown member of target grouping while resolving uses node.");
+                }
+
+                if (newChild instanceof GroupingMember) {
+                    ((GroupingMember) newChild).setAddedByUses(true);
+                }
+
+                newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+                parent.addChildNode(newChild);
             }
-            newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
-            parent.addChildNode(newChild);
         }
         for (GroupingBuilder g : targetGrouping.getGroupingBuilders()) {
             GroupingBuilder newGrouping = new GroupingBuilderImpl(g);
@@ -1128,34 +1132,41 @@ public final class YangParserImpl implements YangModelParser {
         DataNodeContainerBuilder parent = usesNode.getParent();
         SchemaPath parentPath = parent.getPath();
         for (DataSchemaNode child : targetGrouping.getChildNodes()) {
-            // if node is refined, take it from refined nodes and continue
-            SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
-            if (refined != null) {
-                refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
-                parent.addChildNode((DataSchemaNodeBuilder) refined);
-                continue;
-            }
+            if (child != null) {
+                // if node is refined, take it from refined nodes and continue
+                SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+                if (refined != null) {
+                    refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+                    parent.addChildNode((DataSchemaNodeBuilder) refined);
+                    continue;
+                }
 
-            DataSchemaNodeBuilder newChild = null;
-            if (child instanceof AnyXmlSchemaNode) {
-                newChild = createAnyXml((AnyXmlSchemaNode) child, line);
-            } else if (child instanceof ChoiceNode) {
-                newChild = createChoice((ChoiceNode) child, line);
-            } else if (child instanceof ContainerSchemaNode) {
-                newChild = createContainer((ContainerSchemaNode) child, line);
-            } else if (child instanceof LeafListSchemaNode) {
-                newChild = createLeafList((LeafListSchemaNode) child, line);
-            } else if (child instanceof LeafSchemaNode) {
-                newChild = createLeafBuilder((LeafSchemaNode) child, line);
-            } else if (child instanceof ListSchemaNode) {
-                newChild = createList((ListSchemaNode) child, line);
-            }
+                DataSchemaNodeBuilder newChild = null;
+                if (child instanceof AnyXmlSchemaNode) {
+                    newChild = createAnyXml((AnyXmlSchemaNode) child, line);
+                } else if (child instanceof ChoiceNode) {
+                    newChild = createChoice((ChoiceNode) child, line);
+                } else if (child instanceof ContainerSchemaNode) {
+                    newChild = createContainer((ContainerSchemaNode) child, line);
+                } else if (child instanceof LeafListSchemaNode) {
+                    newChild = createLeafList((LeafListSchemaNode) child, line);
+                } else if (child instanceof LeafSchemaNode) {
+                    newChild = createLeafBuilder((LeafSchemaNode) child, line);
+                } else if (child instanceof ListSchemaNode) {
+                    newChild = createList((ListSchemaNode) child, line);
+                }
+
+                if (newChild == null) {
+                    throw new YangParseException(usesNode.getLine(),
+                            "Unknown member of target grouping while resolving uses node.");
+                }
 
-            if (newChild instanceof GroupingMember) {
-                ((GroupingMember) newChild).setAddedByUses(true);
+                if (newChild instanceof GroupingMember) {
+                    ((GroupingMember) newChild).setAddedByUses(true);
+                }
+                newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+                parent.addChildNode(newChild);
             }
-            newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
-            parent.addChildNode(newChild);
         }
         for (GroupingDefinition g : targetGrouping.getGroupings()) {
             GroupingBuilder newGrouping = createGrouping(g, line);
@@ -1206,7 +1217,7 @@ public final class YangParserImpl implements YangModelParser {
     }
 
     private void resolveUnknownNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
-        for (UnknownSchemaNodeBuilder usnb : module.getUnknownNodes()) {
+        for (UnknownSchemaNodeBuilder usnb : module.getAllUnknownNodes()) {
             QName nodeType = usnb.getNodeType();
             if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
                 try {
@@ -1224,7 +1235,7 @@ public final class YangParserImpl implements YangModelParser {
 
     private void resolveUnknownNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module, final SchemaContext context) {
-        for (UnknownSchemaNodeBuilder unknownNodeBuilder : module.getUnknownNodes()) {
+        for (UnknownSchemaNodeBuilder unknownNodeBuilder : module.getAllUnknownNodes()) {
             QName nodeType = unknownNodeBuilder.getNodeType();
             if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
                 try {
index 73462b2..eb0fc21 100644 (file)
@@ -185,12 +185,10 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void enterRevision_stmts(Revision_stmtsContext ctx) {
         enterLog("revisions", "", ctx.getStart().getLine());
-        if (ctx != null) {
-            for (int i = 0; i < ctx.getChildCount(); ++i) {
-                final ParseTree treeNode = ctx.getChild(i);
-                if (treeNode instanceof Revision_stmtContext) {
-                    updateRevisionForRevisionStatement(treeNode);
-                }
+        for (int i = 0; i < ctx.getChildCount(); ++i) {
+            final ParseTree treeNode = ctx.getChild(i);
+            if (treeNode instanceof Revision_stmtContext) {
+                updateRevisionForRevisionStatement(treeNode);
             }
         }
     }
@@ -368,12 +366,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             } else {
                 if ("union".equals(typeName)) {
                     SchemaPath p = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, typeName);
-                    UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(actualPath, namespace, revision, line);
+                    UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(line, namespace, revision);
                     moduleBuilder.enterNode(unionBuilder);
                     unionBuilder.setPath(p);
                 } else if ("identityref".equals(typeName)) {
                     SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, typeName);
-                    moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath, path, line);
+                    moduleBuilder.addIdentityrefType(line, path, getIdentityrefBase(typeBody));
                 } else {
                     type = parseTypeWithBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
                             yangModelPrefix, moduleBuilder.getActualNode());
@@ -384,7 +382,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
                     moduleBuilder.getActualNode());
             // add parent node of this type statement to dirty nodes
-            moduleBuilder.addDirtyNode(actualPath);
+            moduleBuilder.markActualNodeDirty();
             moduleBuilder.setType(type);
         }
 
@@ -744,7 +742,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             qname = new QName(namespace, revision, yangModelPrefix, nodeParameter);
         }
 
-        UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(qname, actualPath, line);
+        UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(line, qname);
         builder.setNodeType(nodeType);
         builder.setNodeParameter(nodeParameter);
         actualPath.push(nodeParameter);
index d913f5b..f139af8 100644 (file)
@@ -1080,6 +1080,7 @@ public final class ParserListenerUtils {
     public static TypeDefinition<?> parseTypeWithBody(final String moduleName, final String typeName,
             final Type_body_stmtsContext typeBody, final List<String> actualPath, final URI namespace,
             final Date revision, final String prefix, final Builder parent) {
+        final int line = typeBody.getStart().getLine();
         TypeDefinition<?> baseType = null;
 
         Integer fractionDigits = getFractionDigits(typeBody);
@@ -1087,7 +1088,7 @@ public final class ParserListenerUtils {
         List<PatternConstraint> patternStatements = getPatternConstraint(typeBody);
         List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
 
-        TypeConstraints constraints = new TypeConstraints(moduleName, typeBody.getStart().getLine());
+        TypeConstraints constraints = new TypeConstraints(moduleName, line);
         constraints.addFractionDigits(fractionDigits);
         constraints.addLengths(lengthStatements);
         constraints.addPatterns(patternStatements);
@@ -1115,6 +1116,9 @@ public final class ParserListenerUtils {
             } else if ("int64".equals(typeName)) {
                 intType = new Int64(baseTypePath);
             }
+            if(intType == null) {
+                throw new YangParseException(moduleName, line, "Unknown yang type "+ typeName);
+            }
             constraints.addRanges(intType.getRangeStatements());
             baseType = intType;
         } else if (typeName.startsWith("uint")) {
@@ -1128,6 +1132,9 @@ public final class ParserListenerUtils {
             } else if ("uint64".equals(typeName)) {
                 uintType = new Uint64(baseTypePath);
             }
+            if(uintType == null) {
+                throw new YangParseException(moduleName, line, "Unknown yang type "+ typeName);
+            }
             constraints.addRanges(uintType.getRangeStatements());
             baseType = uintType;
         } else if ("enumeration".equals(typeName)) {
index 64b06ad..87075e2 100644 (file)
@@ -501,7 +501,7 @@ public final class ParserUtils {
         }
 
         // set correct path for all cases
-        if(childNode instanceof ChoiceBuilder) {
+        if (childNode instanceof ChoiceBuilder) {
             ChoiceBuilder choiceBuilder = (ChoiceBuilder) childNode;
             for (ChoiceCaseBuilder choiceCaseBuilder : choiceBuilder.getCases()) {
                 correctAugmentChildPath(choiceCaseBuilder, childNode.getPath());
@@ -601,11 +601,12 @@ public final class ParserUtils {
 
     private static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, QName nodeQName,
             TypeDefinition<?> nodeType) {
-        QName nodeTypeQName = nodeType.getQName();
-        SchemaPath newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeTypeQName);
         TypeDefinition<?> result = null;
 
         if (nodeType != null) {
+            QName nodeTypeQName = nodeType.getQName();
+            SchemaPath newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeTypeQName);
+
             if (nodeType instanceof BinaryTypeDefinition) {
                 BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
 
index f029a33..b730445 100644 (file)
@@ -335,7 +335,7 @@ public class YangParserWithContextTest {
         List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
         assertEquals(1, unknownNodes.size());
 
-        UnknownSchemaNode un = unknownNodes.iterator().next();
+        UnknownSchemaNode un = unknownNodes.get(0);
         QName unType = un.getNodeType();
         assertEquals(URI.create("urn:simple.container.demo"), unType.getNamespace());
         assertEquals(simpleDateFormat.parse("2012-04-16"), unType.getRevision());
index 8745dda..ec224fa 100644 (file)
@@ -7,6 +7,8 @@
  */\r
 package org.opendaylight.controller.yang.model.api;\r
 \r
+import java.util.List;\r
+\r
 /**\r
  * Interface describing YANG 'deviation' statement.\r
  * <p>\r
@@ -43,4 +45,9 @@ public interface Deviation {
      */\r
     String getReference();\r
 \r
+    /**\r
+     * @return collection of all unknown nodes defined under this schema node.\r
+     */\r
+    public List<UnknownSchemaNode> getUnknownSchemaNodes();\r
+\r
 }\r