Modified construction of built-in yang types. 79/679/1
authorMartin Vitez <mvitez@cisco.com>
Wed, 5 Jun 2013 14:18:01 +0000 (16:18 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 24 Jul 2013 11:44:52 +0000 (13:44 +0200)
Base yang types can not be restricted now. Every restriction causes creation of new ExtendedType with default yang type as base type.
Updated tests.

Change-Id: I04b2a0a069dcf4f7b3a3d1220c742fed047cba3a
Signed-off-by: Martin Vitez <mvitez@cisco.com>
21 files changed:
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EnumerationType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Leafref.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java

index 0af3c81c6ac3e570c716a3376cf3549d8f3f16fe..baefbf40fe97d413a377a25fc9ba5ebe4e159d94 100644 (file)
@@ -35,29 +35,13 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  *
  */
 public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
-
     private final QName name;
     private final SchemaPath path;
     private final String description;
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
-
     private final String units;
     private final List<RangeConstraint> rangeStatements;
 
-    protected AbstractSignedInteger(final QName name, final String description,
-            final Number minRange, final Number maxRange, final String units) {
-        this.name = name;
-        this.description = description;
-        this.path = BaseTypes.schemaPath(name);
-        this.units = units;
-        this.rangeStatements = new ArrayList<RangeConstraint>();
-        final String rangeDescription = "Integer values between " + minRange
-                + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
-                maxRange, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
-    }
-
     /**
      * @param name
      * @param description
index 013d80d79911c127ef4f3823a2fc996bf70c044f..6d5b5be8a0378dfa27fee06687e6174c860a1078 100644 (file)
@@ -36,25 +36,9 @@ public abstract class AbstractUnsignedInteger implements
     private final SchemaPath path;
     private final String description;
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
-
     private final String units;
     private final List<RangeConstraint> rangeStatements;
 
-    protected AbstractUnsignedInteger(final QName name,
-            final String description, final Number minRange,
-            final Number maxRange, final String units) {
-        this.name = name;
-        this.description = description;
-        this.path = BaseTypes.schemaPath(name);
-        this.units = units;
-        this.rangeStatements = new ArrayList<RangeConstraint>();
-        final String rangeDescription = "Integer values between " + minRange
-                + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
-                maxRange, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
-    }
-
     /**
      *
      * @param actualPath
index 74214dc0c77973a9f5b07777ea77d0735c33f9fc..ea09b65b5daa1382847faff9a4429eadee79d5fd 100644 (file)
@@ -24,65 +24,33 @@ import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
  * @see BinaryTypeDefinition
  */
 public final class BinaryType implements BinaryTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("binary");
     private final SchemaPath path;
     private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
     private final BinaryTypeDefinition baseType;
-    private List<Byte> bytes;
+    private final List<Byte> bytes;
     private final List<LengthConstraint> lengthConstraints;
-    private String units = "";
-
-    private BinaryType() {
-        super();
+    private final String units = "";
 
+    public BinaryType(final SchemaPath path) {
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
                 ""));
         this.lengthConstraints = Collections.unmodifiableList(constraints);
         this.bytes = Collections.emptyList();
-        this.path = BaseTypes.schemaPath(name);
+        this.path = path;
         this.baseType = this;
     }
 
-    public BinaryType(final SchemaPath path) {
-        super();
-
+    public BinaryType(final SchemaPath path, final List<Byte> bytes) {
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
                 ""));
         this.lengthConstraints = Collections.unmodifiableList(constraints);
-        this.bytes = Collections.emptyList();
-        this.path = path;
-        this.baseType = new BinaryType();
-    }
-
-    /**
-     *
-     *
-     * @param bytes
-     * @param lengthConstraints
-     * @param units
-     */
-    public BinaryType(final SchemaPath path, final List<Byte> bytes,
-            final List<LengthConstraint> lengthConstraints, final String units) {
-        super();
-
-        if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
-            final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-            constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE,
-                    "", ""));
-            this.lengthConstraints = Collections.unmodifiableList(constraints);
-        } else {
-            this.lengthConstraints = Collections
-                    .unmodifiableList(lengthConstraints);
-        }
-
-        this.path = path;
         this.bytes = Collections.unmodifiableList(bytes);
-        this.units = units;
-        this.baseType = new BinaryType();
+        this.path = path;
+        this.baseType = this;
     }
 
     /*
index 51e0306e8b8737c1e7450c6fe60a8767b6c43280..94391d2288eace0dc4b6d9265d97ee06893e2dcb 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
  * @see BitsTypeDefinition
  */
 public final class BitsType implements BitsTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("bits");
     private final SchemaPath path;
     private final String description = "The bits built-in type represents a bit set.  "
@@ -32,24 +31,17 @@ public final class BitsType implements BitsTypeDefinition {
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
     private final BitsTypeDefinition baseType;
     private final List<Bit> bits;
-    private String units = "";
+    private final String units = "";
 
     /**
      * Default constructor. <br>
      * Instantiates Bits type as empty bits list.
      */
-    private BitsType() {
-        super();
-        this.bits = Collections.emptyList();
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public BitsType(final SchemaPath path) {
         super();
         this.bits = Collections.emptyList();
         this.path = path;
-        this.baseType = new BitsType();
+        this.baseType = this;
     }
 
     /**
@@ -64,27 +56,8 @@ public final class BitsType implements BitsTypeDefinition {
     public BitsType(final SchemaPath path, final List<Bit> bits) {
         super();
         this.bits = Collections.unmodifiableList(bits);
-        this.units = "";
-        this.path = path;
-        this.baseType = new BitsType();
-    }
-
-    /**
-     * Constructor with explicit definition of bits assigned to BitsType and
-     * Units. <br>
-     * The default value of Bits Type is List of bits.
-     *
-     * @param bits
-     *            The bits assigned for Bits Type
-     * @param units
-     *            units for bits type
-     */
-    public BitsType(final SchemaPath path, List<Bit> bits, String units) {
-        super();
-        this.bits = Collections.unmodifiableList(bits);
-        this.units = units;
         this.path = path;
-        this.baseType = new BitsType();
+        this.baseType = this;
     }
 
     /*
index 0cda67c27fe2cf7158c8561bdb44281fb1f24b48..04b2dc90d1ac66f507926d0e9edff0c51b63f682 100644 (file)
@@ -22,30 +22,22 @@ import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
  * @see BooleanTypeDefinition
  */
 public final class BooleanType implements BooleanTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("boolean");
     private final SchemaPath path;
     private final String description = "The boolean built-in type represents a boolean value.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5";
     private final BooleanTypeDefinition baseType;
     private final Boolean defaultValue;
-    private String units = "";
+    private final String units = "";
 
     /**
      * Default constructor with default value set to "false".
      */
-    private BooleanType() {
-        super();
-        this.defaultValue = false;
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public BooleanType(final SchemaPath path) {
         super();
         this.defaultValue = false;
         this.path = path;
-        this.baseType = new BooleanType();
+        this.baseType = this;
     }
 
     /**
@@ -58,23 +50,7 @@ public final class BooleanType implements BooleanTypeDefinition {
         super();
         this.defaultValue = defaultValue;
         this.path = path;
-        this.baseType = new BooleanType();
-    }
-
-    /**
-     * Boolean Type constructor.
-     *
-     * @param defaultValue
-     *            Default Value
-     * @param units
-     *            Units
-     */
-    public BooleanType(final SchemaPath path, final Boolean defaultValue, final String units) {
-        super();
-        this.defaultValue = defaultValue;
-        this.units = units;
-        this.path = path;
-        this.baseType = new BooleanType();
+        this.baseType = this;
     }
 
     /*
index 6a070837bd8e9f3f79cec5c02639ffbdd7f0965b..1387da9b1cf5ead763a14d21b8b3d784ecc6ceb5 100644 (file)
@@ -26,11 +26,10 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  * @see DecimalTypeDefinition
  */
 public final class Decimal64 implements DecimalTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("decimal64");
     private final SchemaPath path;
-    private String units = "";
-    private BigDecimal defaultValue = null;
+    private final String units = "";
+    private final BigDecimal defaultValue = null;
 
     private final String description = "The decimal64 type represents a subset of the real numbers, which can "
             + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
@@ -54,25 +53,14 @@ public final class Decimal64 implements DecimalTypeDefinition {
      * If the fraction digits are not defined inner the definition boundaries
      * the constructor will throw {@link IllegalArgumentException}
      *
+     * @param path
      * @param fractionDigits
      *            integer between 1 and 18 inclusively
      *
      * @see DecimalTypeDefinition
      * @exception IllegalArgumentException
      */
-    private Decimal64(final Integer fractionDigits) {
-        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
-            throw new IllegalArgumentException(
-                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
-        }
-        this.fractionDigits = fractionDigits;
-        this.rangeStatements = defaultRangeStatements();
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public Decimal64(final SchemaPath path, final Integer fractionDigits) {
-        super();
         if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
             throw new IllegalArgumentException(
                     "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
@@ -80,97 +68,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
         this.fractionDigits = fractionDigits;
         rangeStatements = defaultRangeStatements();
         this.path = path;
-        this.baseType = new Decimal64(fractionDigits);
-    }
-
-    /**
-     * Decimal64 Type Constructor. <br>
-     *
-     * If parameter <code>Range Statements</code> is <code>null</code> or
-     * defined as <code>empty List</code> the constructor automatically assigns
-     * the boundaries as min and max value defined for Decimal64 in <a
-     * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The
-     * decimal64 Built-In Type</a> <br>
-     * <br>
-     * The fractions digits MUST be defined as integer between 1 and 18
-     * inclusively as defined interface {@link DecimalTypeDefinition} <br>
-     * If the fraction digits are not defined inner the definition boundaries
-     * the constructor will throw {@link IllegalArgumentException}
-     *
-     * @param actualPath
-     * @param namespace
-     * @param revision
-     * @param rangeStatements
-     *            Range Constraint Statements
-     * @param fractionDigits
-     *            integer between 1 and 18 inclusively
-     * @exception IllegalArgumentException
-     */
-    public Decimal64(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            Integer fractionDigits) {
-        super();
-        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
-            throw new IllegalArgumentException(
-                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
-        }
-        if (rangeStatements == null || rangeStatements.isEmpty()) {
-            this.rangeStatements = defaultRangeStatements();
-        } else {
-            this.rangeStatements = Collections
-                    .unmodifiableList(rangeStatements);
-        }
-        this.fractionDigits = fractionDigits;
-        this.path = path;
-        this.baseType = new Decimal64(fractionDigits);
-    }
-
-    /**
-     * Decimal64 Type Constructor. <br>
-     * If parameter <code>Range Statements</code> is <code>null</code> or
-     * defined as <code>empty List</code> the constructor automatically assigns
-     * the boundaries as min and max value defined for Decimal64 in <a
-     * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The
-     * decimal64 Built-In Type</a> <br>
-     * <br>
-     * The fractions digits MUST be defined as integer between 1 and 18
-     * inclusively as defined interface {@link DecimalTypeDefinition} <br>
-     * If the fraction digits are not defined inner the definition boundaries
-     * the constructor will throw {@link IllegalArgumentException}
-     *
-     * @param actualPath
-     * @param namespace
-     * @param revision
-     * @param units
-     *            units associated with the type
-     * @param defaultValue
-     *            Default Value for type
-     * @param rangeStatements
-     *            Range Constraint Statements
-     * @param fractionDigits
-     *            integer between 1 and 18 inclusively
-     */
-    public Decimal64(final SchemaPath path, final String units,
-            final BigDecimal defaultValue,
-            final List<RangeConstraint> rangeStatements,
-            final Integer fractionDigits) {
-        super();
-        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
-            throw new IllegalArgumentException(
-                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
-        }
-
-        if (rangeStatements == null || rangeStatements.isEmpty()) {
-            this.rangeStatements = defaultRangeStatements();
-
-        } else {
-            this.rangeStatements = Collections
-                    .unmodifiableList(rangeStatements);
-        }
-        this.units = units;
-        this.defaultValue = defaultValue;
-        this.fractionDigits = fractionDigits;
-        this.path = path;
-        this.baseType = new Decimal64(fractionDigits);
+        this.baseType = this;
     }
 
     /**
index 424f313efae6b20ccf35cf78e6b12057594114e0..0e542bc019f3e5fa043fc8fe769bf5457df9d6ea 100644 (file)
@@ -17,21 +17,15 @@ import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;
 
 public final class EmptyType implements EmptyTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("empty");
     private final SchemaPath path;
     private final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#page-131";
     private final EmptyTypeDefinition baseType;
 
-    private EmptyType() {
-        path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public EmptyType(final SchemaPath path) {
         this.path = path;
-        this.baseType = new EmptyType();
+        this.baseType = this;
     }
 
     @Override
index 175ea100ca0919c51f8f9a08e841bc9b13cffc9e..de7ee3060347df9337479de99db162c554da0bf8 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition;
  * @see EnumTypeDefinition
  */
 public final class EnumerationType implements EnumTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("enumeration");
     private final SchemaPath path;
     private final String description = "The enumeration built-in type represents values from a set of assigned names.";
@@ -30,32 +29,24 @@ public final class EnumerationType implements EnumTypeDefinition {
 
     private final EnumPair defaultEnum;
     private final List<EnumPair> enums;
-    private String units = "";
+    private final String units = "";
     private final EnumTypeDefinition baseType;
 
-    private EnumerationType(final List<EnumPair> enums) {
-        this.path = BaseTypes.schemaPath(name);
-        this.enums = Collections.unmodifiableList(enums);
-        this.defaultEnum = null;
-        baseType = this;
-    }
-
     public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
         super();
         this.path = path;
         this.enums = Collections.unmodifiableList(enums);
         this.defaultEnum = null;
-        baseType = new EnumerationType(enums);
+        this.baseType = this;
     }
 
     public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
-            final List<EnumPair> enums, final String units) {
+            final List<EnumPair> enums) {
         super();
         this.path = path;
-        baseType = new EnumerationType(enums);
+        this.baseType = this;
         this.defaultEnum = defaultEnum;
         this.enums = Collections.unmodifiableList(enums);
-        this.units = units;
     }
 
     /*
index 6c4598131e496b405e1183ae521b44e507fb00ce..30f0013d240e7e713882eba614efd4d0cd467091 100644 (file)
@@ -22,27 +22,18 @@ import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition
  * @see IdentityrefTypeDefinition\r
  */\r
 public final class IdentityrefType implements IdentityrefTypeDefinition {\r
-\r
     private final QName name = BaseTypes.constructQName("identityref");\r
     private final SchemaPath path;\r
     private final String description = "The identityref type is used to reference an existing identity.";\r
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10";\r
     private final IdentityrefTypeDefinition baseType;\r
-\r
     private final QName identity;\r
-\r
-    private String units = "";\r
-\r
-    private IdentityrefType(QName identity) {\r
-        this.identity = identity;\r
-        this.path = BaseTypes.schemaPath(name);\r
-        this.baseType = this;\r
-    }\r
+    private final String units = "";\r
 \r
     public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
         this.identity = identity;\r
         this.path = schemaPath;\r
-        this.baseType = new IdentityrefType(identity);\r
+        this.baseType = this;\r
     }\r
 \r
     @Override\r
index 4c17fa6154248fb711c7bd844feb60e65cfd4ba3..8139d5b50b50bb302d1e5802b5a01ac74c8545b8 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDef
  * @see InstanceIdentifierTypeDefinition
  */
 public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
-
     private static final QName name = BaseTypes
             .constructQName("instance-identifier");
     private static final String description = "The instance-identifier built-in type is used to " +
@@ -36,20 +35,12 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     private final InstanceIdentifierTypeDefinition baseType;
     private final boolean requireInstance;
 
-    private InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) {
-        super();
-        path = BaseTypes.schemaPath(name);
-        this.xpath = xpath;
-        this.requireInstance = requireInstance;
-        this.baseType = this;
-    }
-
     public InstanceIdentifier(final SchemaPath path, RevisionAwareXPath xpath, boolean requireInstance) {
         super();
         this.path = path;
         this.xpath = xpath;
         this.requireInstance = requireInstance;
-        this.baseType = new InstanceIdentifier(xpath, requireInstance);
+        this.baseType = this;
     }
 
     /*
index 0a24bf2d059166a65345775cbd34734e83813005..829cd140b18a04740e26ba75b4ab5c851e514866 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int16 built-in type. <br>
@@ -22,29 +19,15 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  * @see AbstractSignedInteger
  */
 public final class Int16 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int16");
-    private Short defaultValue = null;
+    private final Short defaultValue = null;
     private static final String description = "int16  represents integer values between -32768 and 32767, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int16() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int16(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Int16();
-
-    }
+        this.baseType = this;
 
-    public Int16(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final Short defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.defaultValue = defaultValue;
-        this.baseType = new Int16();
     }
 
     @Override
index 8d16e268c35c610750d6e129cbcc1d1ad6882e13..025448262e713a43f26356205f83fa107cc5e636 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int32 built-in type. <br>
@@ -24,34 +21,14 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  *
  */
 public final class Int32 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int32");
-    private Integer defaultValue = null;
+    private final Integer defaultValue = null;
     private static final String description = "int32  represents integer values between -2147483648 and 2147483647, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int32() {
-        super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int32(final SchemaPath path) {
         super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int32();
-    }
-
-    public Int32(final SchemaPath path, final Integer defaultValue) {
-        super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int32();
-        this.defaultValue = defaultValue;
-    }
-
-    public Int32(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final Integer defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Int32();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index 92e92a94a276b8ee22b8c51932db82c5b40d4ea8..d51dcc7a8136912cf83188bd0d2c61becddfbb79 100644 (file)
@@ -7,12 +7,9 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int64 built-in type. <br>
@@ -22,34 +19,15 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  *
  */
 public final class Int64 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int64");
-    private Long defaultValue = null;
+    private final Long defaultValue = null;
     private static final String description =
             "int64  represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int64() {
-        super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int64(final SchemaPath path) {
         super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int64();
-    }
-
-    public Int64(final SchemaPath path, final Long defaultValue) {
-        super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
-        this.baseType = new Int64();
-        this.defaultValue = defaultValue;
-    }
-
-    public Int64(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Long defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Int64();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index f77eebad5223cdc32476ccafa219c873e6d9329d..9f205955492a767ca10e43f4f4aa5979ff1f879f 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
 /**
  * Implementation of Yang int8 built-in type. <br>
@@ -22,34 +19,14 @@ import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
  * @see AbstractSignedInteger
  */
 public final class Int8 extends AbstractSignedInteger {
-
     private static final QName name = BaseTypes.constructQName("int8");
-    private Byte defaultValue = null;
+    private final Byte defaultValue = null;
     private static final String description = "represents integer values between -128 and 127, inclusively.";
     private final IntegerTypeDefinition baseType;
 
-    private Int8() {
-        super(name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Int8(final SchemaPath path) {
         super(path, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
-        this.baseType = new Int8();
-    }
-
-    public Int8(final SchemaPath path, final Byte defaultValue) {
-        super(path, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
-        this.baseType = new Int8();
-        this.defaultValue = defaultValue;
-    }
-
-    public Int8(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final Byte defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Int8();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index d17843af898b44adb1d6a5b2c9d140e446e2675b..bd42903184b68a472bf93caa670fe752f1d0c34e 100644 (file)
@@ -33,17 +33,10 @@ public final class Leafref implements LeafrefTypeDefinition {
     private final String units = "";
     private final LeafrefTypeDefinition baseType;
 
-    private Leafref(final RevisionAwareXPath xpath) {
-        this.xpath = xpath;
-        this.path = BaseTypes.schemaPath(name);
-        this.baseType = this;
-    }
-
     public Leafref(final SchemaPath path, final RevisionAwareXPath xpath) {
-        super();
         this.path = path;
         this.xpath = xpath;
-        baseType = new Leafref(xpath);
+        baseType = this;
     }
 
     /*
index 018ba00042d7ec27e9ee9c182c74ea56effdb98b..b430e801dd1be3093a3110605795117de3680e33 100644 (file)
@@ -25,27 +25,16 @@ import org.opendaylight.controller.yang.model.api.type.StringTypeDefinition;
  * @see StringTypeDefinition
  */
 public final class StringType implements StringTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("string");
     private final SchemaPath path;
-    private String defaultValue = "";
+    private final String defaultValue = "";
     private final String description = "";
     private final String reference = "";
     private final List<LengthConstraint> lengthStatements;
     private final List<PatternConstraint> patterns;
-    private String units = "";
+    private final String units = "";
     private final StringTypeDefinition baseType;
 
-    private StringType() {
-        super();
-        path = BaseTypes.schemaPath(name);
-        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-        constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-        lengthStatements = Collections.unmodifiableList(constraints);
-        patterns = Collections.emptyList();
-        baseType = this;
-    }
-
     /**
      * Default Constructor.
      */
@@ -56,56 +45,7 @@ public final class StringType implements StringTypeDefinition {
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
         lengthStatements = Collections.unmodifiableList(constraints);
         patterns = Collections.emptyList();
-        baseType = new StringType();
-    }
-
-    /**
-     *
-     * @param actualPath
-     * @param namespace
-     * @param revision
-     * @param lengthStatements
-     * @param patterns
-     */
-    public StringType(final SchemaPath path, final List<LengthConstraint> lengthStatements,
-            final List<PatternConstraint> patterns) {
-        super();
-        this.path = path;
-        if(lengthStatements == null || lengthStatements.size() == 0) {
-            final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-            constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-            this.lengthStatements = Collections.unmodifiableList(constraints);
-        } else {
-            this.lengthStatements = Collections.unmodifiableList(lengthStatements);
-        }
-        this.patterns = Collections.unmodifiableList(patterns);
-        baseType = new StringType();
-    }
-
-    /**
-     *
-     *
-     * @param defaultValue
-     * @param lengthStatements
-     * @param patterns
-     * @param units
-     */
-    public StringType(final SchemaPath path, final String defaultValue,
-            final List<LengthConstraint> lengthStatements,
-            final List<PatternConstraint> patterns, final String units) {
-        super();
-        this.path = path;
-        this.defaultValue = defaultValue;
-        if(lengthStatements == null || lengthStatements.size() == 0) {
-            final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-            constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-            this.lengthStatements = Collections.unmodifiableList(constraints);
-        } else {
-            this.lengthStatements = Collections.unmodifiableList(lengthStatements);
-        }
-        this.patterns = Collections.unmodifiableList(patterns);
-        this.units = units;
-        this.baseType = new StringType();
+        baseType = this;
     }
 
     /*
index 95b438b509f8258c722aa403ee64a8ac08985411..79ae4674b0b48971005c09ad76cad8d528b6a215 100644 (file)
@@ -7,11 +7,8 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -21,33 +18,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint16 extends AbstractUnsignedInteger {
-
     private static final QName name = BaseTypes.constructQName("uint16");
     private Integer defaultValue = null;
     private static final String description = "uint16 represents integer values between 0 and 65535, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint16() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint16(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint16();
-    }
-
-    public Uint16(final SchemaPath path, final Integer defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint16();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint16(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Integer defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint16();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index e530e02bbb79357518ccf67fe5fd968da500ac47..fddf0c4008f9c172486a891f49012ef466412a1b 100644 (file)
@@ -7,11 +7,8 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -21,33 +18,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint32 extends AbstractUnsignedInteger {
-
     private static final QName name = BaseTypes.constructQName("uint32");
-    private Long defaultValue = null;
+    private final Long defaultValue = null;
     private static final String description = "uint32 represents integer values between 0 and 4294967295, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint32() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint32(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint32();
-    }
-
-    public Uint32(final SchemaPath path, final Long defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint32();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint32(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Long defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint32();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index a4aabb56c659bc939431fa8a581c83b091d7a63a..9252c08f577715c6744201d1a1b507373ff6f9e8 100644 (file)
@@ -8,11 +8,9 @@
 package org.opendaylight.controller.yang.model.util;
 
 import java.math.BigInteger;
-import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -23,35 +21,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint64 extends AbstractUnsignedInteger {
-
     private static final QName name = BaseTypes.constructQName("uint64");
-
-    private BigInteger defaultValue = null;
+    private final BigInteger defaultValue = null;
     private static final String description = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint64() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint64(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint64();
-    }
-
-    public Uint64(final SchemaPath path, final BigInteger defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint64();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint64(final SchemaPath path,
-            final List<RangeConstraint> rangeStatements, final String units,
-            final BigInteger defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint64();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index c369e037763c7ec821cac453dfe9a413d70d1901..fa9d35ea291b2635aab13dc8f420df9dde1a4b86 100644 (file)
@@ -7,11 +7,8 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
-import java.util.List;
-
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
@@ -25,32 +22,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
 public final class Uint8 extends AbstractUnsignedInteger {
 
     private static final QName name = BaseTypes.constructQName("uint8");
-    private Short defaultValue = null;
+    private final Short defaultValue = null;
     private static final String description =
             "uint8  represents integer values between 0 and 255, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
-    private Uint8() {
-        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = this;
-    }
-
     public Uint8(final SchemaPath path) {
         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint8();
-    }
-
-    public Uint8(final SchemaPath path, final Short defaultValue) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
-        this.baseType = new Uint8();
-        this.defaultValue = defaultValue;
-    }
-
-    public Uint8(final SchemaPath path, final List<RangeConstraint> rangeStatements,
-            final String units, final Short defaultValue) {
-        super(path, name, description, rangeStatements, units);
-        this.baseType = new Uint8();
-        this.defaultValue = defaultValue;
+        this.baseType = this;
     }
 
     /*
index 82849891f9b42b64c9043237598986b007d78403..76d53d5b38b872bd2558be82f340e37b4717ea01 100644 (file)
@@ -52,25 +52,25 @@ public final class YangTypesConverter {
             String typeName) {\r
         TypeDefinition<?> type = null;\r
 \r
-        SchemaPath path = createSchemaPath(actualPath, namespace, revision);\r
+        SchemaPath path = createSchemaPath(actualPath, namespace, revision, typeName);\r
         if (typeName.startsWith("int")) {\r
-            if (typeName.equals("int8")) {\r
+            if ("int8".equals(typeName)) {\r
                 type = new Int8(path);\r
-            } else if (typeName.equals("int16")) {\r
+            } else if ("int16".equals(typeName)) {\r
                 type = new Int16(path);\r
-            } else if (typeName.equals("int32")) {\r
+            } else if ("int32".equals(typeName)) {\r
                 type = new Int32(path);\r
-            } else if (typeName.equals("int64")) {\r
+            } else if ("int64".equals(typeName)) {\r
                 type = new Int64(path);\r
             }\r
         } else if (typeName.startsWith("uint")) {\r
-            if (typeName.equals("uint8")) {\r
+            if ("uint8".equals(typeName)) {\r
                 type = new Uint8(path);\r
-            } else if (typeName.equals("uint16")) {\r
+            } else if ("uint16".equals(typeName)) {\r
                 type = new Uint16(path);\r
-            } else if (typeName.equals("uint32")) {\r
+            } else if ("uint32".equals(typeName)) {\r
                 type = new Uint32(path);\r
-            } else if (typeName.equals("uint64")) {\r
+            } else if ("uint64".equals(typeName)) {\r
                 type = new Uint64(path);\r
             }\r
         } else if ("string".equals(typeName)) {\r
@@ -88,11 +88,18 @@ public final class YangTypesConverter {
         return type;\r
     }\r
 \r
-    private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision) {\r
+    private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision, String typeName) {\r
+        List<String> correctPath = new ArrayList<String>(actualPath);\r
+        // remove module name\r
+        correctPath.remove(0);\r
+\r
         List<QName> path = new ArrayList<QName>();\r
-        for(String element : actualPath) {\r
+        for(String element : correctPath) {\r
             path.add(new QName(namespace, revision, element));\r
         }\r
+        // add type qname\r
+        QName typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);\r
+        path.add(typeQName);\r
         return new SchemaPath(path, true);\r
     }\r
 \r