Refactored YANG types resolving. 49/649/1
authorMartin Vitez <mvitez@cisco.com>
Tue, 16 Apr 2013 08:43:34 +0000 (10:43 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 24 Jul 2013 11:44:51 +0000 (13:44 +0200)
Fixed YANG union type parsing. Refactored code after PMD check.
Fixed organization statement in test files.

Signed-off-by: Martin Vitez <mvitez@cisco.com>
yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/TypeDefinition.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Leafref.java

index 0f098422ebf0fb843df8ca0774f98b710b98d96c..71b5d193dfc92d32f4070bd74990cd33d4819b0a 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.yang.model.api;\r
 \r
 \r
-public interface TypeDefinition<T extends TypeDefinition<T>> extends SchemaNode {\r
+public interface TypeDefinition<T extends TypeDefinition<?>> extends SchemaNode {\r
 \r
     T getBaseType();\r
 \r
index c82df2e079cfaa98a1bb70119ebc2860c80c4851..03f06387f1d70a251c82510dbdc5ec61dd3d1a95 100644 (file)
@@ -15,6 +15,9 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
+import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
+import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 public class ExtendedType implements TypeDefinition {
 
@@ -25,6 +28,12 @@ public class ExtendedType implements TypeDefinition {
     private final String reference;
     private final List<UnknownSchemaNode> unknownSchemaNodes;
 
+    private List<RangeConstraint> ranges = Collections.emptyList();
+    private List<LengthConstraint> lengths = Collections.emptyList();
+    private List<PatternConstraint> patterns = Collections.emptyList();
+    private Integer fractionDigits = null;
+
+
     private Status status;
     private String units;
     private Object defaultValue;
@@ -42,6 +51,11 @@ public class ExtendedType implements TypeDefinition {
         private String units = "";
         private Object defaultValue = null;
 
+        private List<RangeConstraint> ranges = Collections.emptyList();
+        private List<LengthConstraint> lengths = Collections.emptyList();
+        private List<PatternConstraint> patterns = Collections.emptyList();
+        private Integer fractionDigits = null;
+
         public Builder(final QName typeName, TypeDefinition<?> baseType,
                 final String description, final String reference) {
             this.typeName = typeName;
@@ -71,6 +85,32 @@ public class ExtendedType implements TypeDefinition {
             return this;
         }
 
+        public Builder ranges(final List<RangeConstraint> ranges) {
+            if(ranges != null) {
+                this.ranges = ranges;
+            }
+            return this;
+        }
+
+        public Builder lengths(final List<LengthConstraint> lengths) {
+            if(lengths != null) {
+                this.lengths = lengths;
+            }
+            return this;
+        }
+
+        public Builder patterns(final List<PatternConstraint> patterns) {
+            if(patterns != null) {
+                this.patterns = patterns;
+            }
+            return this;
+        }
+
+        public Builder fractionDigits(final Integer fractionDigits) {
+            this.fractionDigits = fractionDigits;
+            return this;
+        }
+
         public ExtendedType build() {
             return new ExtendedType(this);
         }
@@ -86,6 +126,11 @@ public class ExtendedType implements TypeDefinition {
         this.status = builder.status;
         this.units = builder.units;
         this.defaultValue = builder.defaultValue;
+
+        this.ranges = builder.ranges;
+        this.lengths = builder.lengths;
+        this.patterns = builder.patterns;
+        this.fractionDigits = builder.fractionDigits;
     }
 
     @Override
@@ -253,4 +298,20 @@ public class ExtendedType implements TypeDefinition {
         builder2.append("]");
         return builder2.toString();
     }
+
+    public List<RangeConstraint> getRanges() {
+        return ranges;
+    }
+
+    public List<LengthConstraint> getLengths() {
+        return lengths;
+    }
+
+    public List<PatternConstraint> getPatterns() {
+        return patterns;
+    }
+
+    public Integer getFractionDigits() {
+        return fractionDigits;
+    }
 }
index 32181162906b2d1ade73af544d883b61e7348282..9253895e3fec79af913029a020a3bc0e3113c057 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
 /**\r
  * The <code>default</code> implementation of Instance Leafref Type Definition\r
  * interface.\r
- * \r
+ *\r
  * @see LeafrefTypeDefinition\r
  */\r
 public class Leafref implements LeafrefTypeDefinition {\r
@@ -35,12 +35,12 @@ public class Leafref implements LeafrefTypeDefinition {
     private final String units = "";\r
     private final LeafrefTypeDefinition baseType;\r
 \r
-    private Leafref(final RevisionAwareXPath xpath) {\r
+    public Leafref(final RevisionAwareXPath xpath) {\r
         this.xpath = xpath;\r
         this.path = BaseTypes.schemaPath(name);\r
         this.baseType = this;\r
     }\r
-    \r
+\r
     public Leafref(final List<String> actualPath, final URI namespace,\r
             final Date revision, final RevisionAwareXPath xpath) {\r
         super();\r
@@ -48,7 +48,7 @@ public class Leafref implements LeafrefTypeDefinition {
         this.xpath = xpath;\r
         baseType = new Leafref(xpath);\r
     }\r
-    \r
+\r
     public Leafref(final List<String> actualPath, final URI namespace,\r
             final Date revision, final LeafrefTypeDefinition baseType,\r
             final RevisionAwareXPath xpath) {\r
@@ -60,7 +60,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()\r
      */\r
@@ -71,7 +71,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()\r
      */\r
     @Override\r
@@ -81,7 +81,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue\r
      * ()\r
@@ -93,7 +93,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()\r
      */\r
     @Override\r
@@ -103,7 +103,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()\r
      */\r
     @Override\r
@@ -113,7 +113,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()\r
      */\r
@@ -124,7 +124,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()\r
      */\r
     @Override\r
@@ -134,7 +134,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()\r
      */\r
     @Override\r
@@ -144,7 +144,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes\r
      * ()\r
@@ -156,7 +156,7 @@ public class Leafref implements LeafrefTypeDefinition {
 \r
     /*\r
      * (non-Javadoc)\r
-     * \r
+     *\r
      * @see\r
      * org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition\r
      * #getPathStatement()\r