Added YANG typedef support in the YANG parser 84/84/2
authorMartin Vitez <mvitez@cisco.com>
Thu, 28 Mar 2013 13:19:31 +0000 (14:19 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Thu, 28 Mar 2013 14:54:37 +0000 (15:54 +0100)
Added javadoc to builders
Added JUnit test
Fixed hashCode and equals implementation (now only based on QName) for schema Node TOs.

Change-Id: I0d064391ac8de2c77258d3817ce4f7f50ea90350
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
21 files changed:
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.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/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/UnknownTypeDefinition.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/UnknownType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/YangTypesConverter.java

index 06855cf..b96347e 100644 (file)
@@ -1,26 +1,32 @@
-/*
- * 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.model.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.Status;
-
-
-/**
- * Interface for all builders of SchemaNode nodes.
- */
-public interface SchemaNodeBuilder extends Builder {
-
-       QName getQName();
-       void setPath(SchemaPath schemaPath);
-       void setDescription(String description);
-       void setReference(String reference);
-       void setStatus(Status status);
-
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.yang.model.parser.builder.api;\r
+\r
+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.parser.builder.impl.UnknownSchemaNodeBuilder;\r
+\r
+/**\r
+ * Interface for all builders of SchemaNode nodes.\r
+ */\r
+public interface SchemaNodeBuilder extends Builder {\r
+\r
+    QName getQName();\r
+\r
+    void setPath(SchemaPath schemaPath);\r
+\r
+    void setDescription(String description);\r
+\r
+    void setReference(String reference);\r
+\r
+    void setStatus(Status status);\r
+\r
+    void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder);\r
+\r
+}\r
index fc7ef22..a303b96 100644 (file)
@@ -1,24 +1,28 @@
-/*
- * 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.model.parser.builder.api;
-
-import org.opendaylight.controller.yang.common.QName;
-import org.opendaylight.controller.yang.model.api.TypeDefinition;
-
-
-/**
- * Interface for builders of 'typedef' statement.
- */
-public interface TypeDefinitionBuilder {
-
-       QName getQName();
-       TypeDefinition<?> getBaseType();
-       TypeDefinition<?> build();
-       void setUnits(String units);
-
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.yang.model.parser.builder.api;\r
+\r
+import org.opendaylight.controller.yang.common.QName;\r
+import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
+\r
+/**\r
+ * Interface for builders of 'typedef' statement.\r
+ */\r
+public interface TypeDefinitionBuilder {\r
+\r
+    QName getQName();\r
+\r
+    TypeDefinition<?> getBaseType();\r
+\r
+    TypeDefinition<?> build();\r
+\r
+    void setUnits(String units);\r
+\r
+    void setDefaultValue(Object defaultValue);\r
+\r
+}\r
index 953b22e..9b965da 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;
@@ -43,6 +44,7 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
     private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     ContainerSchemaNodeBuilder(QName qname) {
         super(qname);
@@ -80,6 +82,13 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         }
         instance.setUses(uses);
 
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         instance.setConstraints(constraintsBuilder.build());
         instance.setAvailableAugmentations(augmentations);
 
@@ -140,6 +149,11 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         instance.setPresenceContainer(presence);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private class ContainerSchemaNodeImpl implements ContainerSchemaNode {
 
         private final QName qname;
@@ -155,6 +169,7 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         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 boolean presence;
 
         private ContainerSchemaNodeImpl(QName qname) {
@@ -315,7 +330,13 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
 
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-            return Collections.emptyList();
+            return unknownSchemaNodes;
+        }
+
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
         }
 
         @Override
@@ -323,6 +344,7 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
             final int prime = 31;
             int result = 1;
             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+            result = prime * result + ((path == null) ? 0 : path.hashCode());
             return result;
         }
 
@@ -345,6 +367,13 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
             } else if (!qname.equals(other.qname)) {
                 return false;
             }
+            if (path == null) {
+                if (other.path != null) {
+                    return false;
+                }
+            } else if (!path.equals(other.path)) {
+                return false;
+            }
             return true;
         }
 
index 735feb1..fa5c495 100644 (file)
@@ -22,12 +22,12 @@ public class ExtensionBuilder implements SchemaNodeBuilder {
 
     private final ExtensionDefinitionImpl instance;
     private final QName qname;
-    private final List<UnknownSchemaNodeBuilder> addedExtensions;
+    private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     ExtensionBuilder(QName qname) {
         this.qname = qname;
         instance = new ExtensionDefinitionImpl(qname);
-        addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
     }
 
     @Override
@@ -73,6 +73,11 @@ public class ExtensionBuilder implements SchemaNodeBuilder {
         instance.setStatus(status);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private static class ExtensionDefinitionImpl implements ExtensionDefinition {
         private final QName qname;
         private SchemaPath schemaPath;
index 23c74fd..b861700 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.List;
 
@@ -21,6 +22,7 @@ public class FeatureBuilder implements SchemaNodeBuilder {
 
     private final FeatureDefinitionImpl instance;
     private final QName qname;
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     FeatureBuilder(QName qname) {
         this.qname = qname;
@@ -29,6 +31,13 @@ public class FeatureBuilder implements SchemaNodeBuilder {
 
     @Override
     public FeatureDefinitionImpl build() {
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         return instance;
     }
 
@@ -57,6 +66,11 @@ public class FeatureBuilder implements SchemaNodeBuilder {
         instance.setStatus(status);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private static class FeatureDefinitionImpl implements FeatureDefinition {
         private final QName qname;
         private SchemaPath path;
@@ -117,18 +131,18 @@ public class FeatureBuilder implements SchemaNodeBuilder {
             return unknownSchemaNodes;
         }
 
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
             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());
             return result;
         }
 
@@ -158,27 +172,6 @@ public class FeatureBuilder implements SchemaNodeBuilder {
             } 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;
-            }
             return true;
         }
 
@@ -187,10 +180,7 @@ public class FeatureBuilder implements SchemaNodeBuilder {
             StringBuilder sb = new StringBuilder(
                     FeatureDefinitionImpl.class.getSimpleName());
             sb.append("[name=" + qname);
-            sb.append(", path=" + path);
-            sb.append(", description=" + description);
-            sb.append(", reference=" + reference);
-            sb.append(", status=" + status + "]");
+            sb.append(", path=" + path + "]");
             return sb.toString();
         }
     }
index 1bacca8..03dd15b 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,6 +35,7 @@ public class GroupingBuilderImpl implements GroupingBuilder {
     private final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     GroupingBuilderImpl(QName qname) {
         this.instance = new GroupingDefinitionImpl(qname);
@@ -69,6 +71,13 @@ public class GroupingBuilderImpl implements GroupingBuilder {
         }
         instance.setUses(usesNodeDefinitions);
 
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         return instance;
     }
 
@@ -120,16 +129,22 @@ public class GroupingBuilderImpl implements GroupingBuilder {
         usesNodes.add(usesBuilder);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private static class GroupingDefinitionImpl implements GroupingDefinition {
         private final QName qname;
         private SchemaPath path;
         private String description;
         private String reference;
         private Status status;
-        private Map<QName, DataSchemaNode> childNodes;
-        private Set<GroupingDefinition> groupings;
-        private Set<TypeDefinition<?>> typeDefinitions;
-        private Set<UsesNode> uses;
+        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 GroupingDefinitionImpl(QName qname) {
             this.qname = qname;
@@ -214,7 +229,13 @@ public class GroupingBuilderImpl implements GroupingBuilder {
 
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-            return Collections.emptyList();
+            return unknownSchemaNodes;
+        }
+
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
         }
 
         @Override
@@ -240,21 +261,6 @@ public class GroupingBuilderImpl implements GroupingBuilder {
             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;
         }
 
@@ -284,55 +290,6 @@ public class GroupingBuilderImpl implements GroupingBuilder {
             } 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;
         }
 
index 99d3e64..5a9fdb5 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.List;
 
@@ -26,13 +27,13 @@ public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
 
     private final LeafListSchemaNodeImpl instance;
     private final QName qname;
-    private final ConstraintsBuilder constraintsBuilder;
+    private final ConstraintsBuilder constraintsBuilder = new ConstraintsBuilder();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     private TypeDefinition<?> type;
 
     LeafListSchemaNodeBuilder(QName qname) {
         this.qname = qname;
         instance = new LeafListSchemaNodeImpl(qname);
-        constraintsBuilder = new ConstraintsBuilder();
     }
 
     @Override
@@ -98,6 +99,11 @@ public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
         instance.setUserOrdered(userOrdered);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
         private final QName qname;
         private SchemaPath path;
@@ -206,24 +212,18 @@ public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
             return unknownSchemaNodes;
         }
 
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
             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 + (augmenting ? 1231 : 1237);
-            result = prime * result + (configuration ? 1231 : 1237);
-            result = prime * result
-                    + ((constraints == null) ? 0 : constraints.hashCode());
-            result = prime * result + ((type == null) ? 0 : type.hashCode());
-            result = prime * result + (userOrdered ? 1231 : 1237);
             return result;
         }
 
@@ -253,50 +253,6 @@ public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
             } 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 (augmenting != other.augmenting) {
-                return false;
-            }
-            if (configuration != other.configuration) {
-                return false;
-            }
-            if (constraints == null) {
-                if (other.constraints != null) {
-                    return false;
-                }
-            } else if (!constraints.equals(other.constraints)) {
-                return false;
-            }
-            if (type == null) {
-                if (other.type != null) {
-                    return false;
-                }
-            } else if (!type.equals(other.type)) {
-                return false;
-            }
-            if (userOrdered != other.userOrdered) {
-                return false;
-            }
             return true;
         }
 
index 5c28e1b..bd18ba5 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.List;
 
@@ -26,17 +27,24 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
 
     private final QName qname;
     private final LeafSchemaNodeImpl instance;
-    private final ConstraintsBuilder constraintsBuilder;
+    private final ConstraintsBuilder constraintsBuilder = new ConstraintsBuilder();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     private TypeDefinition<?> type;
 
     LeafSchemaNodeBuilder(QName qname) {
         this.qname = qname;
         instance = new LeafSchemaNodeImpl(qname);
-        constraintsBuilder = new ConstraintsBuilder();
     }
 
     @Override
     public LeafSchemaNode build() {
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         instance.setConstraints(constraintsBuilder.build());
         return instance;
     }
@@ -94,6 +102,11 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
         instance.setType(type);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private class LeafSchemaNodeImpl implements LeafSchemaNode {
         private final QName qname;
         private SchemaPath path;
@@ -194,23 +207,18 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
             return unknownSchemaNodes;
         }
 
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
             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 + (augmenting ? 1231 : 1237);
-            result = prime * result + (configuration ? 1231 : 1237);
-            result = prime * result
-                    + ((constraints == null) ? 0 : constraints.hashCode());
-            result = prime * result + ((type == null) ? 0 : type.hashCode());
             return result;
         }
 
@@ -240,47 +248,6 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
             } 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 (augmenting != other.augmenting) {
-                return false;
-            }
-            if (configuration != other.configuration) {
-                return false;
-            }
-            if (constraints == null) {
-                if (other.constraints != null) {
-                    return false;
-                }
-            } else if (!constraints.equals(other.constraints)) {
-                return false;
-            }
-            if (type == null) {
-                if (other.type != null) {
-                    return false;
-                }
-            } else if (!type.equals(other.type)) {
-                return false;
-            }
             return true;
         }
 
index 2a4befe..ccca99c 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;
@@ -44,6 +45,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
     private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     ListSchemaNodeBuilder(QName qname) {
         super(qname);
@@ -81,6 +83,13 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements
         }
         instance.setGroupings(groupingDefinitions);
 
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         instance.setConstraints(constraintsBuilder.build());
         instance.setAvailableAugmentations(augmentations);
 
@@ -147,6 +156,11 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements
         instance.setUserOrdered(userOrdered);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private class ListSchemaNodeImpl implements ListSchemaNode {
         private final QName qname;
         private SchemaPath path;
@@ -339,36 +353,18 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements
             return unknownSchemaNodes;
         }
 
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
             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
-                    + ((keyDefinition == null) ? 0 : keyDefinition.hashCode());
-            result = prime * result + (augmenting ? 1231 : 1237);
-            result = prime * result + (configuration ? 1231 : 1237);
-            result = prime * result
-                    + ((constraints == null) ? 0 : constraints.hashCode());
-            result = prime * result
-                    + ((augmentations == null) ? 0 : augmentations.hashCode());
-            result = prime * result
-                    + ((childNodes == null) ? 0 : childNodes.hashCode());
-            result = prime
-                    * result
-                    + ((typeDefinitions == null) ? 0 : typeDefinitions
-                            .hashCode());
-            result = prime * result
-                    + ((groupings == null) ? 0 : groupings.hashCode());
-            result = prime * result + ((uses == null) ? 0 : uses.hashCode());
-            result = prime * result + (userOrdered ? 1231 : 1237);
             return result;
         }
 
@@ -398,85 +394,6 @@ public class ListSchemaNodeBuilder 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 (keyDefinition == null) {
-                if (other.keyDefinition != null) {
-                    return false;
-                }
-            } else if (!keyDefinition.equals(other.keyDefinition)) {
-                return false;
-            }
-            if (augmenting != other.augmenting) {
-                return false;
-            }
-            if (configuration != other.configuration) {
-                return false;
-            }
-            if (constraints == null) {
-                if (other.constraints != null) {
-                    return false;
-                }
-            } else if (!constraints.equals(other.constraints)) {
-                return false;
-            }
-            if (augmentations == null) {
-                if (other.augmentations != null) {
-                    return false;
-                }
-            } else if (!augmentations.equals(other.augmentations)) {
-                return false;
-            }
-            if (childNodes == null) {
-                if (other.childNodes != null) {
-                    return false;
-                }
-            } else if (!childNodes.equals(other.childNodes)) {
-                return false;
-            }
-            if (typeDefinitions == null) {
-                if (other.typeDefinitions != null) {
-                    return false;
-                }
-            } else if (!typeDefinitions.equals(other.typeDefinitions)) {
-                return false;
-            }
-            if (groupings == null) {
-                if (other.groupings != null) {
-                    return false;
-                }
-            } else if (!groupings.equals(other.groupings)) {
-                return false;
-            }
-            if (uses == null) {
-                if (other.uses != null) {
-                    return false;
-                }
-            } else if (!uses.equals(other.uses)) {
-                return false;
-            }
-            if (userOrdered != other.userOrdered) {
-                return false;
-            }
             return true;
         }
 
index 783b21e..d2010c6 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;
@@ -38,6 +39,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
     private final NotificationDefinitionImpl instance;
     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) {
         super(qname);
@@ -74,6 +76,13 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         }
         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;
     }
 
@@ -107,6 +116,11 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
         instance.setStatus(status);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private class NotificationDefinitionImpl implements NotificationDefinition {
 
         private final QName qname;
@@ -214,6 +228,12 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements
             return unknownSchemaNodes;
         }
 
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
             return childNodes.get(name);
@@ -237,19 +257,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;
         }
 
@@ -279,55 +286,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 +293,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();
         }
     }
index 822a835..28ee667 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.HashSet;
 import java.util.List;
@@ -37,6 +38,7 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder,
     private ContainerSchemaNodeBuilder outputBuilder;
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     RpcDefinitionBuilder(QName qname) {
         this.qname = qname;
@@ -64,6 +66,13 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder,
         }
         instance.setGroupings(groupings);
 
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         return instance;
     }
 
@@ -122,6 +131,11 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder,
                 "Can not add uses node to rpc definition: rpc can not contains uses nodes.");
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     @Override
     public int hashCode() {
         return qname.hashCode();
@@ -245,26 +259,17 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder,
             return unknownSchemaNodes;
         }
 
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if(unknownSchemaNodes != null) {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
             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
-                    + ((input == null) ? 0 : input.hashCode());
-            result = prime * result
-                    + ((output == null) ? 0 : output.hashCode());
-            result = prime * result
-                    + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode());
-            result = prime * result
-                    + ((groupings == null) ? 0 : groupings.hashCode());
             return result;
         }
 
@@ -287,62 +292,6 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder,
             } else if (!qname.equals(other.qname)) {
                 return false;
             }
-            if (path == null) {
-                if (other.path != null) {
-                    return false;
-                }
-            } 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 (input == null) {
-                if (other.input != null) {
-                    return false;
-                }
-            } else if (!input.equals(other.input)) {
-                return false;
-            }
-            if (output == null) {
-                if (other.output != null) {
-                    return false;
-                }
-            } else if (!output.equals(other.output)) {
-                return false;
-            }
-            if (typeDefinitions == null) {
-                if (other.typeDefinitions != null) {
-                    return false;
-                }
-            } else if (!typeDefinitions.equals(other.typeDefinitions)) {
-                return false;
-            }
-            if (groupings == null) {
-                if (other.groupings != null) {
-                    return false;
-                }
-            } else if (!groupings.equals(other.groupings)) {
-                return false;
-            }
             return true;
         }
 
index 1a2c43d..3a8813f 100644 (file)
@@ -32,6 +32,7 @@ public class TypedefBuilder implements TypeDefinitionBuilder,
     private String reference;
     private Status status;
     private String units;
+    private Object defaultValue;
 
     TypedefBuilder(QName qname) {
         this.qname = qname;
@@ -53,6 +54,7 @@ public class TypedefBuilder implements TypeDefinitionBuilder,
                 instance.setPath(schemaPath);
                 instance.setBaseType(baseType);
                 instance.setUnits(units);
+                instance.setDefaultValue(defaultValue);
                 return instance;
             } else {
                 // type
@@ -96,6 +98,11 @@ public class TypedefBuilder implements TypeDefinitionBuilder,
         this.units = units;
     }
 
+    @Override
+    public void setDefaultValue(Object defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+
     @Override
     public TypeDefinition<?> getType() {
         return baseType;
@@ -111,6 +118,11 @@ public class TypedefBuilder implements TypeDefinitionBuilder,
         return baseType;
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        // TODO
+    }
+
     private static class TypeDefinitionImpl<T extends TypeDefinition<T>>
             implements TypeDefinition<T> {
 
@@ -119,6 +131,7 @@ public class TypedefBuilder implements TypeDefinitionBuilder,
         private String description;
         private String reference;
         private Status status = Status.CURRENT;
+        private Object defaultValue;
         private T baseType;
         private String units;
         private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
@@ -188,8 +201,11 @@ public class TypedefBuilder implements TypeDefinitionBuilder,
 
         @Override
         public Object getDefaultValue() {
-            // TODO Auto-generated method stub
-            return null;
+            return defaultValue;
+        }
+
+        private void setDefaultValue(Object defaultValue) {
+            this.defaultValue = defaultValue;
         }
 
         @Override
index d0bb01c..91c6ed1 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.List;
 
@@ -20,6 +21,7 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
 
     private final QName qname;
     private final UnknownSchemaNodeImpl instance;
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     UnknownSchemaNodeBuilder(final QName qname) {
         this.qname = qname;
@@ -29,6 +31,12 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
 
     @Override
     public UnknownSchemaNode build() {
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
         return instance;
     }
 
@@ -57,6 +65,11 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
         instance.setStatus(status);
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
+        addedUnknownNodes.add(unknownSchemaNodeBuilder);
+    }
+
     private static class UnknownSchemaNodeImpl implements UnknownSchemaNode {
         private final QName qname;
         private SchemaPath path;
index d86b49d..d7c6711 100644 (file)
@@ -26,7 +26,22 @@ import org.antlr.v4.runtime.tree.ParseTree;
 import org.antlr.v4.runtime.tree.ParseTreeWalker;
 import org.opendaylight.controller.antlrv4.code.gen.YangLexer;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.controller.model.api.type.BitsTypeDefinition;
+import org.opendaylight.controller.model.api.type.BitsTypeDefinition.Bit;
+import org.opendaylight.controller.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.controller.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.controller.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.controller.model.api.type.LengthConstraint;
+import org.opendaylight.controller.model.api.type.PatternConstraint;
+import org.opendaylight.controller.model.api.type.RangeConstraint;
+import org.opendaylight.controller.model.api.type.StringTypeDefinition;
+import org.opendaylight.controller.model.util.BaseConstraints;
+import org.opendaylight.controller.model.util.BinaryType;
+import org.opendaylight.controller.model.util.BitsType;
+import org.opendaylight.controller.model.util.StringType;
 import org.opendaylight.controller.model.util.UnknownType;
+import org.opendaylight.controller.model.util.YangTypesConverter;
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
@@ -37,6 +52,7 @@ import org.opendaylight.controller.yang.model.api.NotificationDefinition;
 import org.opendaylight.controller.yang.model.api.RpcDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder;
@@ -72,22 +88,85 @@ public class YangModelParserImpl implements YangModelParser {
         return new SchemaContextImpl(modules);
     }
 
+    private Map<String, TreeMap<Date, ModuleBuilder>> loadFiles(
+            String... yangFiles) {
+        final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<String, TreeMap<Date, ModuleBuilder>>();
+
+        final YangModelParserListenerImpl yangModelParser = new YangModelParserListenerImpl();
+        final ParseTreeWalker walker = new ParseTreeWalker();
+
+        List<ParseTree> trees = parseFiles(yangFiles);
+
+        ModuleBuilder[] builders = new ModuleBuilder[trees.size()];
+
+        for (int i = 0; i < trees.size(); i++) {
+            walker.walk(yangModelParser, trees.get(i));
+            builders[i] = yangModelParser.getModuleBuilder();
+        }
+
+        for (ModuleBuilder builder : builders) {
+            final String builderName = builder.getName();
+            Date builderRevision = builder.getRevision();
+            if (builderRevision == null) {
+                builderRevision = createEpochTime();
+            }
+
+            TreeMap<Date, ModuleBuilder> builderByRevision = modules
+                    .get(builderName);
+            if (builderByRevision == null) {
+                builderByRevision = new TreeMap<Date, ModuleBuilder>();
+            }
+            builderByRevision.put(builderRevision, builder);
+
+            modules.put(builderName, builderByRevision);
+        }
+        return modules;
+    }
+
+    private List<ParseTree> parseFiles(String... yangFileNames) {
+        List<ParseTree> trees = new ArrayList<ParseTree>();
+        for (String fileName : yangFileNames) {
+            trees.add(parseFile(fileName));
+        }
+        return trees;
+    }
+
+    private ParseTree parseFile(String yangFileName) {
+        ParseTree result = null;
+        try {
+            final File yangFile = new File(yangFileName);
+            final FileInputStream inStream = new FileInputStream(yangFile);
+            final ANTLRInputStream input = new ANTLRInputStream(inStream);
+            final YangLexer lexer = new YangLexer(input);
+            final CommonTokenStream tokens = new CommonTokenStream(lexer);
+            final YangParser parser = new YangParser(tokens);
+            result = parser.yang();
+        } catch (IOException e) {
+            logger.warn("Exception while reading yang file: " + yangFileName, e);
+        }
+        return result;
+    }
+
     private Set<Module> build(Map<String, TreeMap<Date, ModuleBuilder>> modules) {
         // first validate
-        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
-            for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
+        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules
+                .entrySet()) {
+            for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue()
+                    .entrySet()) {
                 ModuleBuilder moduleBuilder = childEntry.getValue();
                 validateBuilder(modules, moduleBuilder);
             }
         }
-
         // then build
         final Set<Module> result = new HashSet<Module>();
-        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules
+                .entrySet()) {
             final Map<Date, Module> modulesByRevision = new HashMap<Date, Module>();
-            for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
+            for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue()
+                    .entrySet()) {
                 ModuleBuilder moduleBuilder = childEntry.getValue();
-                modulesByRevision.put(childEntry.getKey(),moduleBuilder.build());
+                modulesByRevision.put(childEntry.getKey(),
+                        moduleBuilder.build());
                 result.add(moduleBuilder.build());
             }
         }
@@ -95,47 +174,175 @@ public class YangModelParserImpl implements YangModelParser {
         return result;
     }
 
-    private void validateBuilder(Map<String, TreeMap<Date, ModuleBuilder>> modules, ModuleBuilder builder) {
+    private void validateBuilder(
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            ModuleBuilder builder) {
         resolveTypedefs(modules, builder);
         resolveAugments(modules, builder);
     }
 
-    private void resolveTypedefs(Map<String, TreeMap<Date, ModuleBuilder>> modules, ModuleBuilder builder) {
-        Map<List<String>, TypeAwareBuilder> dirtyNodes = builder.getDirtyNodes();
+    /**
+     * Search for dirty nodes (node which contains UnknownType) and resolve
+     * unknown types.
+     *
+     * @param modules
+     *            all available modules
+     * @param builder
+     *            current module
+     */
+    private void resolveTypedefs(
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            ModuleBuilder builder) {
+        Map<List<String>, TypeAwareBuilder> dirtyNodes = builder
+                .getDirtyNodes();
         if (dirtyNodes.size() == 0) {
             return;
         } else {
-            for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes.entrySet()) {
-                TypeAwareBuilder tab = entry.getValue();
-                TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(modules,entry.getValue(), builder);
-                tab.setType(tdb.build());
+            for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes
+                    .entrySet()) {
+                TypeAwareBuilder typeToResolve = entry.getValue();
+                Map<TypeDefinitionBuilder, TypeConstraints> foundedTypeDefinitionBuilder = findTypeDefinitionBuilderWithConstraints(
+                        modules, entry.getValue(), builder);
+                TypeDefinitionBuilder targetType = foundedTypeDefinitionBuilder
+                        .entrySet().iterator().next().getKey();
+                TypeConstraints constraints = foundedTypeDefinitionBuilder
+                        .entrySet().iterator().next().getValue();
+
+                UnknownType ut = (UnknownType) typeToResolve.getType();
+
+                // RANGE
+                List<RangeConstraint> ranges = ut.getRangeStatements();
+                resolveRanges(ranges, typeToResolve, targetType, modules,
+                        builder);
+
+                // LENGTH
+                List<LengthConstraint> lengths = ut.getLengthStatements();
+                resolveLengths(lengths, typeToResolve, targetType, modules,
+                        builder);
+
+                // PATTERN
+                List<PatternConstraint> patterns = ut.getPatterns();
+
+                // Fraction Digits
+                Integer fractionDigits = ut.getFractionDigits();
+
+                TypeDefinition<?> type = targetType.getBaseType();
+                String typeName = type.getQName().getLocalName();
+
+                // MERGE CONSTRAINTS (enumeration and leafref omitted because
+                // they have no restrictions)
+                if (type instanceof DecimalTypeDefinition) {
+                    List<RangeConstraint> fullRanges = new ArrayList<RangeConstraint>();
+                    fullRanges.addAll(constraints.getRanges());
+                    fullRanges.addAll(ranges);
+                    Integer fd = fractionDigits == null ? constraints
+                            .getFractionDigits() : fractionDigits;
+                    type = YangTypesConverter.javaTypeForBaseYangDecimal64Type(
+                            fullRanges, fd);
+                } else if (type instanceof IntegerTypeDefinition) {
+                    List<RangeConstraint> fullRanges = new ArrayList<RangeConstraint>();
+                    fullRanges.addAll(constraints.getRanges());
+                    fullRanges.addAll(ranges);
+                    if (typeName.startsWith("int")) {
+                        type = YangTypesConverter
+                                .javaTypeForBaseYangSignedIntegerType(typeName,
+                                        fullRanges);
+                    } else {
+                        type = YangTypesConverter
+                                .javaTypeForBaseYangUnsignedIntegerType(
+                                        typeName, fullRanges);
+                    }
+                } else if (type instanceof StringTypeDefinition) {
+                    List<LengthConstraint> fullLengths = new ArrayList<LengthConstraint>();
+                    fullLengths.addAll(constraints.getLengths());
+                    fullLengths.addAll(lengths);
+                    List<PatternConstraint> fullPatterns = new ArrayList<PatternConstraint>();
+                    fullPatterns.addAll(constraints.getPatterns());
+                    fullPatterns.addAll(patterns);
+                    type = new StringType(fullLengths, fullPatterns);
+                } else if (type instanceof BitsTypeDefinition) {
+                    // TODO: add 'length' restriction to BitsType
+                    BitsTypeDefinition bitsType = (BitsTypeDefinition) type;
+                    List<Bit> bits = bitsType.getBits();
+                    type = new BitsType(bits);
+                } else if (type instanceof BinaryTypeDefinition) {
+                    type = new BinaryType(null, lengths, null);
+                } else if (typeName.equals("instance-identifier")) {
+                    // TODO: instance-identifier
+                    /*
+                     * boolean requireInstance = isRequireInstance(typeBody);
+                     * type = new InstanceIdentifier(null, requireInstance);
+                     */
+                }
+                typeToResolve.setType(type);
             }
         }
     }
 
-    private TypeDefinitionBuilder findTypeDefinitionBuilder(Map<String, TreeMap<Date, ModuleBuilder>> modules, TypeAwareBuilder typeBuilder, ModuleBuilder builder) {
+    private TypeDefinitionBuilder findTypeDefinitionBuilder(
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            TypeAwareBuilder typeBuilder, ModuleBuilder builder) {
+        Map<TypeDefinitionBuilder, TypeConstraints> result = findTypeDefinitionBuilderWithConstraints(
+                modules, typeBuilder, builder);
+        return result.entrySet().iterator().next().getKey();
+    }
+
+    private Map<TypeDefinitionBuilder, TypeConstraints> findTypeDefinitionBuilderWithConstraints(
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            TypeAwareBuilder typeBuilder, ModuleBuilder builder) {
+        return findTypeDefinitionBuilderWithConstraints(new TypeConstraints(),
+                modules, typeBuilder, builder);
+    }
+
+    /**
+     * Traverse through all referenced types chain until base YANG type is
+     * founded.
+     *
+     * @param constraints
+     *            current type constraints
+     * @param modules
+     *            all available modules
+     * @param typeBuilder
+     *            type builder which contains type
+     * @param builder
+     *            current module
+     * @return map, where key is type referenced and value is its constraints
+     */
+    private Map<TypeDefinitionBuilder, TypeConstraints> findTypeDefinitionBuilderWithConstraints(
+            TypeConstraints constraints,
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            TypeAwareBuilder typeBuilder, ModuleBuilder builder) {
+        Map<TypeDefinitionBuilder, TypeConstraints> result = new HashMap<TypeDefinitionBuilder, TypeConstraints>();
+
         UnknownType type = (UnknownType) typeBuilder.getType();
         QName typeQName = type.getQName();
         String typeName = type.getQName().getLocalName();
         String prefix = typeQName.getPrefix();
 
+        // search for module which contains referenced typedef
         ModuleBuilder dependentModuleBuilder;
         if (prefix.equals(builder.getPrefix())) {
             dependentModuleBuilder = builder;
         } else {
-            ModuleImport dependentModuleImport = getDependentModuleImport(builder, prefix);
+            ModuleImport dependentModuleImport = getModuleImport(builder,
+                    prefix);
             String dependentModuleName = dependentModuleImport.getModuleName();
             Date dependentModuleRevision = dependentModuleImport.getRevision();
-            TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
-            if(dependentModuleRevision == null) {
-                dependentModuleBuilder = moduleBuildersByRevision.lastEntry().getValue();
+            TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules
+                    .get(dependentModuleName);
+            if (dependentModuleRevision == null) {
+                dependentModuleBuilder = moduleBuildersByRevision.lastEntry()
+                        .getValue();
             } else {
-                dependentModuleBuilder = moduleBuildersByRevision.get(dependentModuleRevision);
+                dependentModuleBuilder = moduleBuildersByRevision
+                        .get(dependentModuleRevision);
             }
         }
 
-        final Set<TypeDefinitionBuilder> typedefs = dependentModuleBuilder.getModuleTypedefs();
-
+        // pull all typedef statements from dependent module...
+        final Set<TypeDefinitionBuilder> typedefs = dependentModuleBuilder
+                .getModuleTypedefs();
+        // and search for referenced typedef
         TypeDefinitionBuilder lookedUpBuilder = null;
         for (TypeDefinitionBuilder tdb : typedefs) {
             QName qname = tdb.getQName();
@@ -145,15 +352,65 @@ public class YangModelParserImpl implements YangModelParser {
             }
         }
 
-        if (lookedUpBuilder.getBaseType() instanceof UnknownType) {
-            return findTypeDefinitionBuilder(modules, (TypeAwareBuilder) lookedUpBuilder, dependentModuleBuilder);
+        // if referenced type is UnknownType again, search recursively with
+        // current constraints
+        TypeDefinition<?> referencedType = lookedUpBuilder.getBaseType();
+        if (referencedType instanceof UnknownType) {
+            UnknownType unknown = (UnknownType) lookedUpBuilder.getBaseType();
+
+            final List<RangeConstraint> ranges = unknown.getRangeStatements();
+            constraints.addRanges(ranges);
+            final List<LengthConstraint> lengths = unknown
+                    .getLengthStatements();
+            constraints.addLengths(lengths);
+            final List<PatternConstraint> patterns = unknown.getPatterns();
+            constraints.addPatterns(patterns);
+            return findTypeDefinitionBuilderWithConstraints(constraints,
+                    modules, (TypeAwareBuilder) lookedUpBuilder,
+                    dependentModuleBuilder);
         } else {
-            return lookedUpBuilder;
+            // pull restriction from this base type and add them to
+            // 'constraints'
+            if (referencedType instanceof DecimalTypeDefinition) {
+                constraints.addRanges(((DecimalTypeDefinition) referencedType)
+                        .getRangeStatements());
+                constraints
+                        .setFractionDigits(((DecimalTypeDefinition) referencedType)
+                                .getFractionDigits());
+            } else if (referencedType instanceof IntegerTypeDefinition) {
+                constraints.addRanges(((IntegerTypeDefinition) referencedType)
+                        .getRangeStatements());
+            } else if (referencedType instanceof StringTypeDefinition) {
+                constraints.addPatterns(((StringTypeDefinition) referencedType)
+                        .getPatterns());
+            } else if (referencedType instanceof BitsTypeDefinition) {
+                // TODO: add 'length' restriction to BitsType
+            } else if (referencedType instanceof BinaryTypeDefinition) {
+                // TODO
+            } else if (referencedType instanceof InstanceIdentifierTypeDefinition) {
+                // TODO: instance-identifier
+            }
+
+            result.put(lookedUpBuilder, constraints);
+            // return lookedUpBuilder;
+            return result;
         }
     }
 
-    private void resolveAugments(Map<String, TreeMap<Date, ModuleBuilder>> modules, ModuleBuilder builder) {
-        Set<AugmentationSchemaBuilder> augmentBuilders = builder.getAddedAugments();
+    /**
+     * Go through all augmentation definitions and resolve them. This means find
+     * referenced node and add child nodes to it.
+     *
+     * @param modules
+     *            all available modules
+     * @param builder
+     *            current module
+     */
+    private void resolveAugments(
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            ModuleBuilder builder) {
+        Set<AugmentationSchemaBuilder> augmentBuilders = builder
+                .getAddedAugments();
 
         Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();
         for (AugmentationSchemaBuilder augmentBuilder : augmentBuilders) {
@@ -164,21 +421,26 @@ public class YangModelParserImpl implements YangModelParser {
                 prefix = pathPart.getPrefix();
                 augmentTargetPath.add(pathPart.getLocalName());
             }
-            ModuleImport dependentModuleImport = getDependentModuleImport(builder, prefix);
+            ModuleImport dependentModuleImport = getModuleImport(builder,
+                    prefix);
             String dependentModuleName = dependentModuleImport.getModuleName();
             augmentTargetPath.add(0, dependentModuleName);
 
             Date dependentModuleRevision = dependentModuleImport.getRevision();
 
-            TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
+            TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules
+                    .get(dependentModuleName);
             ModuleBuilder dependentModule;
-            if(dependentModuleRevision == null) {
-                dependentModule = moduleBuildersByRevision.lastEntry().getValue();
+            if (dependentModuleRevision == null) {
+                dependentModule = moduleBuildersByRevision.lastEntry()
+                        .getValue();
             } else {
-                dependentModule = moduleBuildersByRevision.get(dependentModuleRevision);
+                dependentModule = moduleBuildersByRevision
+                        .get(dependentModuleRevision);
             }
 
-            AugmentationTargetBuilder augmentTarget = (AugmentationTargetBuilder) dependentModule.getNode(augmentTargetPath);
+            AugmentationTargetBuilder augmentTarget = (AugmentationTargetBuilder) dependentModule
+                    .getNode(augmentTargetPath);
             AugmentationSchema result = augmentBuilder.build();
             augmentTarget.addAugmentation(result);
             fillAugmentTarget(augmentBuilder, (ChildNodeBuilder) augmentTarget);
@@ -187,6 +449,12 @@ public class YangModelParserImpl implements YangModelParser {
         builder.setAugmentations(augments);
     }
 
+    /**
+     * Add all augment's child nodes to given target.
+     *
+     * @param augment
+     * @param target
+     */
     private void fillAugmentTarget(AugmentationSchemaBuilder augment,
             ChildNodeBuilder target) {
         for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
@@ -195,72 +463,143 @@ public class YangModelParserImpl implements YangModelParser {
         }
     }
 
-    private Map<String, TreeMap<Date, ModuleBuilder>> loadFiles(String... yangFiles) {
-        final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<String, TreeMap<Date, ModuleBuilder>>();
-
-        final YangModelParserListenerImpl yangModelParser = new YangModelParserListenerImpl();
-        final ParseTreeWalker walker = new ParseTreeWalker();
-
-        List<ParseTree> trees = parseFiles(yangFiles);
-
-        ModuleBuilder[] builders = new ModuleBuilder[trees.size()];
-
-        for (int i = 0; i < trees.size(); i++) {
-            walker.walk(yangModelParser, trees.get(i));
-            builders[i] = yangModelParser.getModuleBuilder();
-        }
-
-        for (ModuleBuilder builder : builders) {
-            final String builderName = builder.getName();
-            Date builderRevision = builder.getRevision();
-            if(builderRevision == null) {
-                builderRevision = createEpochTime();
-            }
-
-            TreeMap<Date, ModuleBuilder> builderByRevision = modules.get(builderName);
-            if (builderByRevision == null) {
-                builderByRevision = new TreeMap<Date, ModuleBuilder>();
+    /**
+     * Get module import referenced by given prefix.
+     *
+     * @param builder
+     *            module to search
+     * @param prefix
+     *            prefix associated with import
+     * @return ModuleImport based on given prefix
+     */
+    private ModuleImport getModuleImport(ModuleBuilder builder, String prefix) {
+        ModuleImport moduleImport = null;
+        for (ModuleImport mi : builder.getModuleImports()) {
+            if (mi.getPrefix().equals(prefix)) {
+                moduleImport = mi;
+                break;
             }
-            builderByRevision.put(builderRevision, builder);
-
-            modules.put(builderName, builderByRevision);
         }
-        return modules;
+        return moduleImport;
     }
 
-    private List<ParseTree> parseFiles(String... yangFileNames) {
-        List<ParseTree> trees = new ArrayList<ParseTree>();
-        for (String fileName : yangFileNames) {
-            trees.add(parseFile(fileName));
+    /**
+     * Helper method for resolving special 'min' or 'max' values in range
+     * constraint
+     *
+     * @param ranges
+     *            ranges to resolve
+     * @param typeToResolve
+     *            type to resolve
+     * @param targetType
+     *            target type
+     * @param modules
+     *            all available modules
+     * @param builder
+     *            current module
+     */
+    private void resolveRanges(List<RangeConstraint> ranges,
+            TypeAwareBuilder typeToResolve, TypeDefinitionBuilder targetType,
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            ModuleBuilder builder) {
+        if (ranges != null && ranges.size() > 0) {
+            Long min = (Long) ranges.get(0).getMin();
+            Long max = (Long) ranges.get(ranges.size() - 1).getMax();
+            // if range contains one of the special values 'min' or 'max'
+            if (min.equals(Long.MIN_VALUE) || max.equals(Long.MAX_VALUE)) {
+                Long[] values = parseRangeConstraint(typeToResolve, targetType,
+                        modules, builder);
+                if (min.equals(Long.MIN_VALUE)) {
+                    min = values[0];
+                    RangeConstraint oldFirst = ranges.get(0);
+                    RangeConstraint newFirst = BaseConstraints.rangeConstraint(
+                            min, oldFirst.getMax(), oldFirst.getDescription(),
+                            oldFirst.getReference());
+                    ranges.set(0, newFirst);
+                }
+                if (max.equals(Long.MAX_VALUE)) {
+                    max = values[1];
+                    RangeConstraint oldLast = ranges.get(ranges.size() - 1);
+                    RangeConstraint newLast = BaseConstraints.rangeConstraint(
+                            oldLast.getMin(), max, oldLast.getDescription(),
+                            oldLast.getReference());
+                    ranges.set(ranges.size() - 1, newLast);
+                }
+            }
         }
-        return trees;
     }
 
-    private ParseTree parseFile(String yangFileName) {
-        ParseTree result = null;
-        try {
-            final File yangFile = new File(yangFileName);
-            final FileInputStream inStream = new FileInputStream(yangFile);
-            final ANTLRInputStream input = new ANTLRInputStream(inStream);
-            final YangLexer lexer = new YangLexer(input);
-            final CommonTokenStream tokens = new CommonTokenStream(lexer);
-            final YangParser parser = new YangParser(tokens);
-            result = parser.yang();
-        } catch (IOException e) {
-            logger.warn("Exception while reading yang file: " + yangFileName, e);
+    /**
+     * Helper method for resolving special 'min' or 'max' values in length
+     * constraint
+     *
+     * @param ranges
+     *            ranges to resolve
+     * @param typeToResolve
+     *            type to resolve
+     * @param targetType
+     *            target type
+     * @param modules
+     *            all available modules
+     * @param builder
+     *            current module
+     */
+    private void resolveLengths(List<LengthConstraint> lengths,
+            TypeAwareBuilder typeToResolve, TypeDefinitionBuilder targetType,
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            ModuleBuilder builder) {
+        if (lengths != null && lengths.size() > 0) {
+            Long min = lengths.get(0).getMin();
+            Long max = lengths.get(lengths.size() - 1).getMax();
+            // if length contains one of the special values 'min' or 'max'
+            if (min.equals(Long.MIN_VALUE) || max.equals(Long.MAX_VALUE)) {
+                Long[] values = parseRangeConstraint(typeToResolve, targetType,
+                        modules, builder);
+                if (min.equals(Long.MIN_VALUE)) {
+                    min = values[0];
+                    LengthConstraint oldFirst = lengths.get(0);
+                    LengthConstraint newFirst = BaseConstraints
+                            .lengthConstraint(min, oldFirst.getMax(),
+                                    oldFirst.getDescription(),
+                                    oldFirst.getReference());
+                    lengths.set(0, newFirst);
+                }
+                if (max.equals(Long.MAX_VALUE)) {
+                    max = values[1];
+                    LengthConstraint oldLast = lengths.get(lengths.size() - 1);
+                    LengthConstraint newLast = BaseConstraints
+                            .lengthConstraint(oldLast.getMin(), max,
+                                    oldLast.getDescription(),
+                                    oldLast.getReference());
+                    lengths.set(lengths.size() - 1, newLast);
+                }
+            }
         }
-        return result;
     }
 
-    private ModuleImport getDependentModuleImport(ModuleBuilder builder, String prefix) {
-        ModuleImport moduleImport = null;
-        for (ModuleImport mi : builder.getModuleImports()) {
-            if (mi.getPrefix().equals(prefix)) {
-                moduleImport = mi;
-                break;
-            }
+    private Long[] parseRangeConstraint(TypeAwareBuilder typeToResolve,
+            TypeDefinitionBuilder targetType,
+            Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            ModuleBuilder builder) {
+        TypeDefinition<?> targetBaseType = targetType.getBaseType();
+
+        if (targetBaseType instanceof IntegerTypeDefinition) {
+            IntegerTypeDefinition itd = (IntegerTypeDefinition) targetBaseType;
+            List<RangeConstraint> ranges = itd.getRangeStatements();
+            Long min = (Long) ranges.get(0).getMin();
+            Long max = (Long) ranges.get(ranges.size() - 1).getMax();
+            return new Long[] { min, max };
+        } else if (targetBaseType instanceof DecimalTypeDefinition) {
+            DecimalTypeDefinition dtd = (DecimalTypeDefinition) targetBaseType;
+            List<RangeConstraint> ranges = dtd.getRangeStatements();
+            Long min = (Long) ranges.get(0).getMin();
+            Long max = (Long) ranges.get(ranges.size() - 1).getMax();
+            return new Long[] { min, max };
+        } else {
+            return parseRangeConstraint(typeToResolve,
+                    findTypeDefinitionBuilder(modules, typeToResolve, builder),
+                    modules, builder);
         }
-        return moduleImport;
     }
 
     private Date createEpochTime() {
@@ -318,4 +657,45 @@ public class YangModelParserImpl implements YangModelParser {
         }
     }
 
+    private static class TypeConstraints {
+        private final List<RangeConstraint> ranges = new ArrayList<RangeConstraint>();
+        private final List<LengthConstraint> lengths = new ArrayList<LengthConstraint>();
+        private final List<PatternConstraint> patterns = new ArrayList<PatternConstraint>();
+        private Integer fractionDigits;
+
+        public List<RangeConstraint> getRanges() {
+            return ranges;
+        }
+
+        public void addRanges(List<RangeConstraint> ranges) {
+            this.ranges.addAll(0, ranges);
+        }
+
+        public List<LengthConstraint> getLengths() {
+            return lengths;
+        }
+
+        public void addLengths(List<LengthConstraint> lengths) {
+            this.lengths.addAll(0, lengths);
+        }
+
+        public List<PatternConstraint> getPatterns() {
+            return patterns;
+        }
+
+        public void addPatterns(List<PatternConstraint> patterns) {
+            this.patterns.addAll(0, patterns);
+        }
+
+        public Integer getFractionDigits() {
+            return fractionDigits;
+        }
+
+        public void setFractionDigits(Integer fractionDigits) {
+            if (fractionDigits != null) {
+                this.fractionDigits = fractionDigits;
+            }
+        }
+    }
+
 }
index 022798e..d5dfa9a 100644 (file)
@@ -932,10 +932,12 @@ public class YangModelBuilderUtil {
             List<RangeConstraint> rangeStatements = getRangeConstraints(ctx);
             List<LengthConstraint> lengthStatements = getLengthConstraints(ctx);
             List<PatternConstraint> patternStatements = getPatternConstraint(ctx);
+            Integer fractionDigits = getFractionDigits(ctx);
 
             ut.rangeStatements(rangeStatements);
             ut.lengthStatements(lengthStatements);
             ut.patterns(patternStatements);
+            ut.fractionDigits(fractionDigits);
         }
 
         return ut.build();
@@ -973,7 +975,10 @@ public class YangModelBuilderUtil {
             type = YangTypesConverter.javaTypeForBaseYangDecimal64Type(
                     rangeStatements, fractionDigits);
         } else if (typeName.startsWith("int") || typeName.startsWith("uint")) {
-            type = YangTypesConverter.javaTypeForBaseYangIntegerType(typeName,
+            type = YangTypesConverter.javaTypeForBaseYangSignedIntegerType(typeName,
+                    rangeStatements);
+        } else if(typeName.startsWith("uint")) {
+            type = YangTypesConverter.javaTypeForBaseYangUnsignedIntegerType(typeName,
                     rangeStatements);
         } else if (typeName.equals("enumeration")) {
             type = new EnumerationType(enumConstants);
@@ -990,7 +995,7 @@ public class YangModelBuilderUtil {
             type = new Leafref(xpath);
         } else if (typeName.equals("binary")) {
             type = new BinaryType(null, lengthStatements, null);
-        } else if (typeName.equals("instanceidentifier")) {
+        } else if (typeName.equals("instance-identifier")) {
             boolean requireInstance = isRequireInstance(typeBody);
             type = new InstanceIdentifier(null, requireInstance);
         }
index 74cfed5..889290f 100644 (file)
@@ -9,17 +9,24 @@ package org.opendaylight.controller.yang.model.parser.impl;
 
 import static org.junit.Assert.*;
 
-import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.controller.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.controller.model.api.type.PatternConstraint;
+import org.opendaylight.controller.model.api.type.RangeConstraint;
+import org.opendaylight.controller.model.util.Decimal64;
 import org.opendaylight.controller.model.util.Int32;
+import org.opendaylight.controller.model.util.StringType;
 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
 import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 
 public class YangModelParserTest {
@@ -29,7 +36,7 @@ public class YangModelParserTest {
     private YangModelParser tested;
 
     @Before
-    public void init() throws IOException {
+    public void init() {
         tested = new YangModelParserImpl();
     }
 
@@ -68,13 +75,14 @@ public class YangModelParserTest {
 
         ListSchemaNode list = (ListSchemaNode)container.getDataChildByName("ifEntry");
         assertNotNull(list);
+        assertEquals(1, list.getAvailableAugmentations().size());
 
         LeafSchemaNode leaf = (LeafSchemaNode)list.getDataChildByName("ds0ChannelNumber");
         assertNotNull(leaf);
     }
 
     @Test
-    public void testTypeDef() {
+    public void testTypedefRangesResolving() {
         Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
         assertEquals(2, modules.size());
 
@@ -87,7 +95,141 @@ public class YangModelParserTest {
         assertNotNull(m1);
 
         LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("testleaf");
+        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
+        assertTrue(testleaf.getType().getBaseType() instanceof Int32);
+        Int32 baseTypeCast = (Int32)baseType;
+        List<RangeConstraint> ranges = baseTypeCast.getRangeStatements();
+        assertEquals(2, ranges.size());
+        RangeConstraint range = ranges.get(0);
+        assertEquals(2L, range.getMin());
+        assertEquals(20L, range.getMax());
+    }
+
+    @Test
+    public void testTypedefPatternsResolving() {
+        Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
+        assertEquals(2, modules.size());
+
+        Module m1 = null;
+        for(Module m : modules) {
+            if(m.getName().equals("types1")) {
+                m1 = m;
+            }
+        }
+        assertNotNull(m1);
+
+        LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("test-string-leaf");
+        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
+        assertTrue(testleaf.getType().getBaseType() instanceof StringType);
+        StringType baseTypeCast = (StringType)baseType;
+
+        Set<String> expectedRegularExpressions = new HashSet<String>();
+        expectedRegularExpressions.add("[a-k]*");
+        expectedRegularExpressions.add("[b-u]*");
+        expectedRegularExpressions.add("[e-z]*");
+
+        Set<String> actualRegularExpressions = new HashSet<String>();
+        List<PatternConstraint> patterns = baseTypeCast.getPatterns();
+        for(PatternConstraint pc : patterns) {
+            actualRegularExpressions.add(pc.getRegularExpression());
+        }
+
+        assertEquals(expectedRegularExpressions, actualRegularExpressions);
+    }
+
+    @Test
+    public void testTypedefLengthsResolving() {
+        Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
+        assertEquals(2, modules.size());
+
+        Module m1 = null;
+        for(Module m : modules) {
+            if(m.getName().equals("types1")) {
+                m1 = m;
+            }
+        }
+        assertNotNull(m1);
+
+        LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("test-int-leaf");
+        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
+        assertTrue(testleaf.getType().getBaseType() instanceof IntegerTypeDefinition);
+        Int32 baseTypeCast = (Int32)baseType;
+
+        Long[][] expectedRanges = new Long[3][2];
+        expectedRanges[0] = new Long[]{10L, 20L};
+        expectedRanges[1] = new Long[]{12L, 18L};
+        expectedRanges[2] = new Long[]{14L, 16L};
+
+        List<RangeConstraint> actualRanges = baseTypeCast.getRangeStatements();
+        assertEquals(3, actualRanges.size());
+        for(int i = 0; i < actualRanges.size(); i++) {
+            assertEquals(expectedRanges[i][0], actualRanges.get(i).getMin());
+            assertEquals(expectedRanges[i][1], actualRanges.get(i).getMax());
+        }
+    }
+
+    @Test
+    public void testTypeDef() {
+        Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
+        assertEquals(2, modules.size());
+
+        Module m2 = null;
+        for(Module m : modules) {
+            if(m.getName().equals("types2")) {
+                m2 = m;
+            }
+        }
+        assertNotNull(m2);
+
+        LeafSchemaNode testleaf = (LeafSchemaNode)m2.getDataChildByName("nested-type-leaf");
+        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
         assertTrue(testleaf.getType().getBaseType() instanceof Int32);
+        Int32 baseTypeCast = (Int32)baseType;
+        List<RangeConstraint> ranges = baseTypeCast.getRangeStatements();
+        assertEquals(2, ranges.size());
+        RangeConstraint range = ranges.get(0);
+        assertEquals(2L, range.getMin());
+        assertEquals(20L, range.getMax());
+    }
+
+    @Test
+    public void testTypedefDecimal1() {
+        Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
+        assertEquals(2, modules.size());
+
+        Module m1 = null;
+        for(Module m : modules) {
+            if(m.getName().equals("types1")) {
+                m1 = m;
+            }
+        }
+        assertNotNull(m1);
+
+        LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("test-decimal-leaf");
+        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
+        assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
+        Decimal64 baseTypeCast = (Decimal64)baseType;
+        assertEquals(4, (int)baseTypeCast.getFractionDigits());
+    }
+
+    @Test
+    public void testTypedefDecimal2() {
+        Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
+        assertEquals(2, modules.size());
+
+        Module m1 = null;
+        for(Module m : modules) {
+            if(m.getName().equals("types1")) {
+                m1 = m;
+            }
+        }
+        assertNotNull(m1);
+
+        LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("test-decimal-leaf2");
+        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
+        assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
+        Decimal64 baseTypeCast = (Decimal64)baseType;
+        assertEquals(5, (int)baseTypeCast.getFractionDigits());
     }
 
 }
index 2c796a9..0d5fba7 100644 (file)
@@ -1,39 +1,57 @@
-module types1 {
-       yang-version 1;
-    namespace "urn:simple.container.demo";
-    prefix "t1";
-    
-    import types2 {
-         prefix "data";
-         revision-date 2013-02-27;
-     }
-    
-    organization "Cisco";
-    contact "WILL-BE-DEFINED-LATER";
-    
-    revision "2013-02-27" {
-        reference " WILL BE DEFINED LATER";
-    }
-    
-    container interfaces {
-         list ifEntry {
-             key "ifIndex";
-
-             leaf ifIndex {
-                 type uint32;
-                 units minutes;
-             }
-             
-             leaf ifMtu {
-                 type int32;
-             }
-         }
-     }
-     
-       leaf testleaf {
-               type data:my-base-int32-type {
-                       range "11..max";
-               }
-       } 
-
-}
+module types1 {\r
+    yang-version 1;\r
+    namespace "urn:simple.container.demo";\r
+    prefix "t1";\r
+    \r
+    import types2 {\r
+         prefix "data";\r
+         revision-date 2013-02-27;\r
+     }\r
+    \r
+    organization "Cisco";\r
+    contact "WILL-BE-DEFINED-LATER";\r
+    \r
+    revision "2013-02-27" {\r
+        reference " WILL BE DEFINED LATER";\r
+    }\r
+    \r
+    container interfaces {\r
+         list ifEntry {\r
+             key "ifIndex";\r
+\r
+             leaf ifIndex {\r
+                 type uint32;\r
+                 units minutes;\r
+             }\r
+             \r
+             leaf ifMtu {\r
+                 type int32;\r
+             }\r
+         }\r
+     }\r
+     \r
+    leaf testleaf {\r
+        type data:my-base-int32-type {\r
+            range "min..max";\r
+        }\r
+    }\r
+    \r
+    leaf test-string-leaf {\r
+        type data:my-string-type-ext;\r
+    }\r
+    \r
+    leaf test-int-leaf {\r
+        type data:my-int-type-ext;\r
+    }\r
+    \r
+    leaf test-decimal-leaf {\r
+        type data:my-decimal-type {\r
+            fraction-digits 4;\r
+        }\r
+    }\r
+    \r
+    leaf test-decimal-leaf2 {\r
+        type data:my-decimal-type-ext;\r
+    }\r
+\r
+}\r
index 9d12207..aea5fb4 100644 (file)
-module types2 {
-       yang-version 1;
-    namespace "urn:simple.types.data.demo";
-    prefix "t2";
-    
-    import types1 {
-         prefix "if";
-         revision-date 2013-02-27;
-     }
-
-    organization "Cisco";
-    contact "WILL-BE-DEFINED-LATER";
-    description "This is types-data test description";
-
-    revision "2013-02-27" {
-        reference " WILL BE DEFINED LATER";
-    }
-    
-    
-     augment "/if:interfaces/if:ifEntry" {
-         when "if:ifType='ds0'";
-         leaf ds0ChannelNumber {
-             type string;
-         }
-     }
-     
-     leaf if-name {
-       type leafref {
-               path "/interface/name";
-        }
-     }
-     
-     leaf name {
-       type string;
-     }
-     
-     typedef my-base-int32-type {
-               type int32 {
-               range "0..32";
-        }
-       }
-
-}
+module types2 {\r
+    yang-version 1;\r
+    namespace "urn:simple.types.data.demo";\r
+    prefix "t2";\r
+    \r
+    import types1 {\r
+         prefix "if";\r
+         revision-date 2013-02-27;\r
+     }\r
+\r
+    organization "Cisco";\r
+    contact "WILL-BE-DEFINED-LATER";\r
+    description "This is types-data test description";\r
+\r
+    revision "2013-02-27" {\r
+        reference " WILL BE DEFINED LATER";\r
+    }\r
+    \r
+    typedef my-base-int32-type {\r
+        type int32 {\r
+            range "2..20";\r
+        }\r
+    }\r
+\r
+     typedef my-type1 {\r
+         type my-base-int32-type {\r
+            range "11..max";\r
+        }\r
+    }\r
+    \r
+    typedef my-string-type {\r
+        type string {\r
+            pattern "[a-k]*";\r
+        }\r
+    }\r
+    \r
+    typedef my-string-type2 {\r
+        type my-string-type {\r
+            pattern "[b-u]*";\r
+        }\r
+    }\r
+    \r
+    typedef my-string-type-ext {\r
+        type my-string-type2 {\r
+            pattern "[e-z]*";\r
+        }\r
+    }\r
+    \r
+    typedef my-int-type {\r
+        type int32 {\r
+            range "10..20";\r
+        }\r
+    }\r
+    \r
+    typedef my-int-type2 {\r
+        type my-int-type {\r
+            range "12..18";\r
+        }\r
+    }\r
+    \r
+    typedef my-int-type-ext {\r
+        type my-int-type2 {\r
+            range "14..16";\r
+        }\r
+    }\r
+    \r
+    typedef my-decimal-type {\r
+        type decimal64 {\r
+            fraction-digits 6;\r
+        }\r
+    }\r
+    \r
+    typedef my-decimal-type-ext {\r
+        type decimal64 {\r
+            fraction-digits 5;\r
+        }\r
+    }\r
+\r
+    augment "/if:interfaces/if:ifEntry" {\r
+        when "if:ifType='ds0'";\r
+        leaf ds0ChannelNumber {\r
+            type string;\r
+        }\r
+    }\r
+\r
+    leaf if-name {\r
+        type leafref {\r
+            path "/interface/name";\r
+        }\r
+    }\r
+     \r
+    leaf name {\r
+        type string;\r
+    }\r
+     \r
+    leaf nested-type-leaf {\r
+        type my-type1;\r
+    }\r
+\r
+}\r
index a4da8f7..f5f3b17 100644 (file)
@@ -14,11 +14,14 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition;
 public interface UnknownTypeDefinition extends\r
         TypeDefinition<UnknownTypeDefinition> {\r
 \r
-    public List<RangeConstraint> getRangeStatements();\r
+    List<RangeConstraint> getRangeStatements();\r
 \r
-    public List<LengthConstraint> getLengthStatements();\r
+    List<LengthConstraint> getLengthStatements();\r
 \r
-    public List<PatternConstraint> getPatterns();\r
+    List<PatternConstraint> getPatterns();\r
+\r
+    LengthConstraint getLengthConstraint();\r
+\r
+    Integer getFractionDigits();\r
 \r
-    public LengthConstraint getLengthConstraint();\r
 }\r
index 1553ce0..7ad57a7 100644 (file)
@@ -31,6 +31,7 @@ public class UnknownType implements UnknownTypeDefinition {
     private final List<RangeConstraint> rangeStatements;\r
     private final List<UnknownSchemaNode> extensions;\r
     private final LengthConstraint lengthConstraint;\r
+    private final Integer fractionDigits;\r
 \r
     private final Status status;\r
     private final String units;\r
@@ -49,6 +50,7 @@ public class UnknownType implements UnknownTypeDefinition {
         private List<RangeConstraint> rangeStatements = Collections.emptyList();\r
         private List<UnknownSchemaNode> extensions = Collections.emptyList();\r
         private LengthConstraint lengthConstraint = null;\r
+        private Integer fractionDigits = null;\r
 \r
         private Status status = Status.CURRENT;\r
         private String units = "";\r
@@ -104,6 +106,11 @@ public class UnknownType implements UnknownTypeDefinition {
             return this;\r
         }\r
 \r
+        public Builder fractionDigits(final Integer fractionDigits) {\r
+            this.fractionDigits = fractionDigits;\r
+            return this;\r
+        }\r
+\r
         public Builder status(Status status) {\r
             this.status = status;\r
             return this;\r
@@ -137,11 +144,12 @@ public class UnknownType implements UnknownTypeDefinition {
         this.status = builder.status;\r
         this.units = builder.units;\r
         this.defaultValue = builder.defaultValue;\r
+        this.fractionDigits = builder.fractionDigits;\r
     }\r
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()\r
      */\r
@@ -152,7 +160,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()\r
      */\r
     @Override\r
@@ -162,7 +170,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue\r
      * ()\r
@@ -174,7 +182,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()\r
      */\r
     @Override\r
@@ -184,7 +192,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()\r
      */\r
     @Override\r
@@ -194,7 +202,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()\r
      */\r
@@ -205,7 +213,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()\r
      */\r
     @Override\r
@@ -215,7 +223,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()\r
      */\r
     @Override\r
@@ -225,7 +233,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes\r
      * ()\r
@@ -237,7 +245,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition\r
      * #getRangeStatements()\r
@@ -249,7 +257,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition\r
      * #getLengthStatements()\r
@@ -261,7 +269,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition\r
      * #getPatterns()\r
@@ -273,7 +281,7 @@ public class UnknownType implements UnknownTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.type.UnknownTypeDefinition\r
      * #getLengthConstraint()\r
@@ -283,6 +291,11 @@ public class UnknownType implements UnknownTypeDefinition {
         return lengthConstraint;\r
     }\r
 \r
+    @Override\r
+    public Integer getFractionDigits() {\r
+        return fractionDigits;\r
+    }\r
+\r
     @Override\r
     public int hashCode() {\r
         final int prime = 31;\r
@@ -437,4 +450,5 @@ public class UnknownType implements UnknownTypeDefinition {
         builder2.append("]");\r
         return builder2.toString();\r
     }\r
+\r
 }\r
index 7f485c3..1b96adf 100644 (file)
@@ -92,29 +92,29 @@ public class YangTypesConverter {
     }\r
 \r
     public static TypeDefinition<IntegerTypeDefinition> javaTypeForBaseYangSignedIntegerType(\r
-            String typeName) {\r
+            String typeName, List<RangeConstraint> ranges) {\r
         if (typeName.equals("int8")) {\r
-            return new Int8();\r
+            return new Int8(ranges, null, null);\r
         } else if (typeName.equals("int16")) {\r
-            return new Int16();\r
+            return new Int16(ranges, null, null);\r
         } else if (typeName.equals("int32")) {\r
-            return new Int32();\r
+            return new Int32(ranges, null, null);\r
         } else if (typeName.equals("int64")) {\r
-            return new Int64();\r
+            return new Int64(ranges, null, null);\r
         }\r
         return null;\r
     }\r
 \r
     public static TypeDefinition<UnsignedIntegerTypeDefinition> javaTypeForBaseYangUnsignedIntegerType(\r
-            final String typeName) {\r
+            final String typeName, List<RangeConstraint> ranges) {\r
         if (typeName.equals("uint8")) {\r
-            return new Uint8();\r
+            return new Uint8(ranges, null, null);\r
         } else if (typeName.equals("uint16")) {\r
-            return new Uint16();\r
+            return new Uint16(ranges, null, null);\r
         } else if (typeName.equals("uint32")) {\r
-            return new Uint32();\r
+            return new Uint32(ranges, null, null);\r
         } else if (typeName.equals("uint64")) {\r
-            return new Uint64();\r
+            return new Uint64(ranges, null, null);\r
         }\r
         return null;\r
     }\r