Added line number to error messages.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / NotificationBuilder.java
index 783b21e04b717ba63695c008ce3545e03e4ec782..f2a0a07777e713498a2dbd2290f80163749c77e7 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.yang.model.parser.builder.impl;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -34,93 +35,119 @@ import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder
 
 public class NotificationBuilder extends AbstractChildNodeBuilder implements
         TypeDefinitionAwareBuilder, SchemaNodeBuilder {
-
     private final NotificationDefinitionImpl instance;
+    private final int line;
+    private SchemaPath schemaPath;
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
-    NotificationBuilder(QName qname) {
+    NotificationBuilder(final QName qname, final int line) {
         super(qname);
+        this.line = line;
         instance = new NotificationDefinitionImpl(qname);
     }
 
     @Override
     public SchemaNode build() {
+        instance.setPath(schemaPath);
+
         // CHILD NODES
-        Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
+        final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
         for (DataSchemaNodeBuilder node : childNodes) {
             childs.put(node.getQName(), node.build());
         }
         instance.setChildNodes(childs);
 
         // GROUPINGS
-        Set<GroupingDefinition> groupingDefinitions = new HashSet<GroupingDefinition>();
+        final Set<GroupingDefinition> groupingDefs = new HashSet<GroupingDefinition>();
         for (GroupingBuilder builder : groupings) {
-            groupingDefinitions.add(builder.build());
+            groupingDefs.add(builder.build());
         }
-        instance.setGroupings(groupingDefinitions);
+        instance.setGroupings(groupingDefs);
 
         // TYPEDEFS
-        Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
+        final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
         for (TypeDefinitionBuilder entry : addedTypedefs) {
             typedefs.add(entry.build());
         }
         instance.setTypeDefinitions(typedefs);
 
         // USES
-        Set<UsesNode> uses = new HashSet<UsesNode>();
+        final Set<UsesNode> uses = new HashSet<UsesNode>();
         for (UsesNodeBuilder builder : addedUsesNodes) {
             uses.add(builder.build());
         }
         instance.setUses(uses);
 
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         return instance;
     }
 
     @Override
-    public void addTypedef(TypeDefinitionBuilder type) {
+    public int getLine() {
+        return line;
+    }
+
+    @Override
+    public void addTypedef(final TypeDefinitionBuilder type) {
         addedTypedefs.add(type);
     }
 
     @Override
-    public void addUsesNode(UsesNodeBuilder usesNodeBuilder) {
+    public void addUsesNode(final UsesNodeBuilder usesNodeBuilder) {
         addedUsesNodes.add(usesNodeBuilder);
     }
 
+    @Override
+    public SchemaPath getPath() {
+        return schemaPath;
+    }
+
     @Override
     public void setPath(SchemaPath schemaPath) {
-        instance.setPath(schemaPath);
+        this.schemaPath = schemaPath;
     }
 
     @Override
-    public void setDescription(String description) {
+    public void setDescription(final String description) {
         instance.setDescription(description);
     }
 
     @Override
-    public void setReference(String reference) {
+    public void setReference(final String reference) {
         instance.setReference(reference);
     }
 
     @Override
-    public void setStatus(Status status) {
+    public void setStatus(final Status status) {
         instance.setStatus(status);
     }
 
-    private class NotificationDefinitionImpl implements NotificationDefinition {
+    @Override
+    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
+        addedUnknownNodes.add(unknownNode);
+    }
 
+    private class NotificationDefinitionImpl implements NotificationDefinition {
         private final QName qname;
         private SchemaPath path;
         private String description;
         private String reference;
-        private Status status;
+        private Status status = Status.CURRENT;
         private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
         private Set<GroupingDefinition> groupings = Collections.emptySet();
         private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
         private Set<UsesNode> uses = Collections.emptySet();
-        private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
-        private NotificationDefinitionImpl(QName qname) {
+        private NotificationDefinitionImpl(final QName qname) {
             this.qname = qname;
         }
 
@@ -134,7 +161,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             return path;
         }
 
-        private void setPath(SchemaPath path) {
+        private void setPath(final SchemaPath path) {
             this.path = path;
         }
 
@@ -143,7 +170,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             return description;
         }
 
-        private void setDescription(String description) {
+        private void setDescription(final String description) {
             this.description = description;
         }
 
@@ -162,7 +189,9 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         }
 
         private void setStatus(Status status) {
-            this.status = status;
+            if (status != null) {
+                this.status = status;
+            }
         }
 
         @Override
@@ -171,7 +200,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         }
 
         private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
-            if(childNodes != null) {
+            if (childNodes != null) {
                 this.childNodes = childNodes;
             }
         }
@@ -182,7 +211,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         }
 
         private void setGroupings(Set<GroupingDefinition> groupings) {
-            if(groupings != null) {
+            if (groupings != null) {
                 this.groupings = groupings;
             }
         }
@@ -193,7 +222,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         }
 
         private void setUses(Set<UsesNode> uses) {
-            if(uses != null) {
+            if (uses != null) {
                 this.uses = uses;
             }
         }
@@ -203,15 +232,23 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             return typeDefinitions;
         }
 
-        private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
-            if(typeDefinitions != null) {
+        private void setTypeDefinitions(
+                final Set<TypeDefinition<?>> typeDefinitions) {
+            if (typeDefinitions != null) {
                 this.typeDefinitions = typeDefinitions;
             }
         }
 
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-            return unknownSchemaNodes;
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(
+                final List<UnknownSchemaNode> unknownNodes) {
+            if (unknownNodes != null) {
+                this.unknownNodes = unknownNodes;
+            }
         }
 
         @Override
@@ -237,19 +274,6 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             int result = 1;
             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
             result = prime * result + ((path == null) ? 0 : path.hashCode());
-            result = prime * result
-                    + ((description == null) ? 0 : description.hashCode());
-            result = prime * result
-                    + ((reference == null) ? 0 : reference.hashCode());
-            result = prime * result
-                    + ((status == null) ? 0 : status.hashCode());
-            result = prime * result
-                    + ((childNodes == null) ? 0 : childNodes.hashCode());
-            result = prime * result
-                    + ((groupings == null) ? 0 : groupings.hashCode());
-            result = prime * result
-                    + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode());
-            result = prime * result + ((uses == null) ? 0 : uses.hashCode());
             return result;
         }
 
@@ -264,7 +288,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             if (getClass() != obj.getClass()) {
                 return false;
             }
-            NotificationDefinitionImpl other = (NotificationDefinitionImpl) obj;
+            final NotificationDefinitionImpl other = (NotificationDefinitionImpl) obj;
             if (qname == null) {
                 if (other.qname != null) {
                     return false;
@@ -279,55 +303,6 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             } else if (!path.equals(other.path)) {
                 return false;
             }
-            if (description == null) {
-                if (other.description != null) {
-                    return false;
-                }
-            } else if (!description.equals(other.description)) {
-                return false;
-            }
-            if (reference == null) {
-                if (other.reference != null) {
-                    return false;
-                }
-            } else if (!reference.equals(other.reference)) {
-                return false;
-            }
-            if (status == null) {
-                if (other.status != null) {
-                    return false;
-                }
-            } else if (!status.equals(other.status)) {
-                return false;
-            }
-            if (childNodes == null) {
-                if (other.childNodes != null) {
-                    return false;
-                }
-            } else if (!childNodes.equals(other.childNodes)) {
-                return false;
-            }
-            if (groupings == null) {
-                if (other.groupings != null) {
-                    return false;
-                }
-            } else if (!groupings.equals(other.groupings)) {
-                return false;
-            }
-            if (typeDefinitions == null) {
-                if (other.typeDefinitions != null) {
-                    return false;
-                }
-            } else if (!typeDefinitions.equals(other.typeDefinitions)) {
-                return false;
-            }
-            if (uses == null) {
-                if (other.uses != null) {
-                    return false;
-                }
-            } else if (!uses.equals(other.uses)) {
-                return false;
-            }
             return true;
         }
 
@@ -335,7 +310,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         public String toString() {
             StringBuilder sb = new StringBuilder(
                     NotificationDefinitionImpl.class.getSimpleName());
-            sb.append("[qname=" + qname + "]");
+            sb.append("[qname=" + qname + ", path=" + path + "]");
             return sb.toString();
         }
     }