Fixed SchemaPath resolution for base YANG types. 73/673/1
authorMartin Vitez <mvitez@cisco.com>
Fri, 26 Apr 2013 09:42:59 +0000 (11:42 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 24 Jul 2013 11:44:52 +0000 (13:44 +0200)
Refactored refine statement parsing.

Change-Id: Ic00b86c611f1f56b69d9e09bf197d9ddb79da145
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/ExtendedType.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/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/UnionType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java

index 3907cc13e5d4bc314619885644935a9a74875ced..c2ae7d304a8c1ca9bae54b109e94f3b46d023ef4 100644 (file)
@@ -46,6 +46,20 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
     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 76048519e7f226653f220aa73aff85dae7ed5681..31a62ececda6f4e2a652adac5b7c90449be0c837 100644 (file)
@@ -42,7 +42,26 @@ public abstract class AbstractUnsignedInteger implements
     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
+     * @param namespace
+     * @param revision
      * @param name
      * @param description
      * @param minRange
index 70298a7e07bf3e9bd94d3b743e3c1b649f022396..253fe484f0459a7f410014814a549166c5477dbd 100644 (file)
@@ -7,8 +7,10 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -20,43 +22,55 @@ import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
 
 /**
  * The <code>default</code> implementation of Binary Type Definition interface.
- * 
+ *
  * @see BinaryTypeDefinition
  */
 public class BinaryType implements BinaryTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("binary");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    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<LengthConstraint> lengthConstraints;
     private String units = "";
 
-    /**
-     * 
-     */
-    public BinaryType() {
+    private BinaryType() {
+        super();
+
+        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.baseType = this;
+    }
+
+    public BinaryType(final List<String> actualPath, final URI namespace,
+            final Date revision) {
         super();
-        
+
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-        lengthConstraints = Collections.unmodifiableList(constraints);
-        bytes = Collections.emptyList();
+        this.lengthConstraints = Collections.unmodifiableList(constraints);
+        this.bytes = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BinaryType();
     }
 
     /**
-     * 
-     * 
+     *
+     *
      * @param bytes
      * @param lengthConstraints
      * @param units
      */
-    public BinaryType(final List<Byte> bytes,
+    public BinaryType(final List<String> actualPath, final URI namespace,
+            final Date revision, 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, "", ""));
@@ -64,9 +78,11 @@ public class BinaryType implements BinaryTypeDefinition {
         } else {
             this.lengthConstraints = Collections.unmodifiableList(lengthConstraints);
         }
-        
+
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.bytes = Collections.unmodifiableList(bytes);
         this.units = units;
+        this.baseType = new BinaryType();
     }
 
     /*
@@ -76,7 +92,7 @@ public class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public BinaryTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index e6c118934e72ef78f9e958b21765f36a56fe5720..717c24ed5083c2b89cc47fd0fa9a6b473aaa4d6d 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * 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
 */
+ * 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.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -16,22 +18,21 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
 
-
 /**
  * The <code>default</code> implementation of Bits Type Definition interface.
- * 
+ *
  * @see BitsTypeDefinition
  */
 public class BitsType implements BitsTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("bits");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
-    private final String description = "The bits built-in type represents a bit set.  " +
-               "That is, a bits value is a set of flags identified by small integer position " +
-               "numbers starting at 0.  Each bit number has an assigned name.";
-    
-    private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
+    private final SchemaPath path;
+    private final String description = "The bits built-in type represents a bit set.  "
+            + "That is, a bits value is a set of flags identified by small integer position "
+            + "numbers starting at 0.  Each bit number has an assigned name.";
 
+    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 = "";
 
@@ -39,52 +40,72 @@ public class BitsType implements BitsTypeDefinition {
      * Default constructor. <br>
      * Instantiates Bits type as empty bits list.
      */
-    public BitsType() {
+    private BitsType() {
         super();
-        bits = Collections.emptyList();
+        this.bits = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
+    public BitsType(final List<String> actualPath, final URI namespace,
+            final Date revision) {
+        super();
+        this.bits = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BitsType();
     }
 
     /**
-     * Constructor with explicit definition of bits assigned to
-     * BitsType.
-     * 
+     * Constructor with explicit definition of bits assigned to BitsType.
+     *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param bits
      *            The bits assigned for Bits Type
      */
-    public BitsType(final List<Bit> bits) {
+    public BitsType(final List<String> actualPath, final URI namespace,
+            final Date revision, final List<Bit> bits) {
         super();
         this.bits = Collections.unmodifiableList(bits);
         this.units = "";
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BitsType();
     }
 
     /**
-     * Constructor with explicit definition of bits assigned to
-     * BitsType and Units.
-     * <br>
+     * 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
+     *
+     * @param bits
+     *            The bits assigned for Bits Type
+     * @param units
+     *            units for bits type
      */
-    public BitsType(List<Bit> bits, String units) {
+    public BitsType(final List<String> actualPath, final URI namespace,
+            final Date revision, List<Bit> bits, String units) {
         super();
         this.bits = Collections.unmodifiableList(bits);
         this.units = units;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BitsType();
     }
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public BitsTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
      */
     @Override
@@ -94,8 +115,10 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+     * ()
      */
     @Override
     public Object getDefaultValue() {
@@ -104,7 +127,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
      */
     @Override
@@ -114,7 +137,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
      */
     @Override
@@ -124,8 +147,9 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
     public String getDescription() {
@@ -134,7 +158,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
      */
     @Override
@@ -144,7 +168,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
      */
     @Override
index 9717ff66a6a1791f5c1c90408028986b4e3ea2f5..f588bf425c9ae4ed2f6deabd91cf723bc6b9d2fd 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * 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
 */
+ * 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.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -18,62 +20,82 @@ import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
 
 /**
  * The <code>default</code> implementation of Boolean Type Definition interface.
- * 
+ *
  * @see BooleanTypeDefinition
  */
 public class BooleanType implements BooleanTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("boolean");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    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 = "";
 
     /**
      * Default constructor with default value set to "false".
      */
-    public BooleanType() {
+    private BooleanType() {
+        super();
+        this.defaultValue = false;
+        this.path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
+    public BooleanType(final List<String> actualPath, final URI namespace,
+            final Date revision) {
         super();
-        defaultValue = false;
+        this.defaultValue = false;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BooleanType();
     }
 
     /**
      * Boolean Type constructor.
-     * 
-     * @param defaultValue Default Value
+     *
+     * @param defaultValue
+     *            Default Value
      */
-    public BooleanType(final Boolean defaultValue) {
+    public BooleanType(final List<String> actualPath, final URI namespace,
+            final Date revision, final Boolean defaultValue) {
         super();
         this.defaultValue = defaultValue;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BooleanType();
     }
 
     /**
      * Boolean Type constructor.
-     * 
-     * @param defaultValue Default Value
-     * @param units Units
+     *
+     * @param defaultValue
+     *            Default Value
+     * @param units
+     *            Units
      */
-    public BooleanType(final Boolean defaultValue, final String units) {
+    public BooleanType(final List<String> actualPath, final URI namespace,
+            final Date revision, final Boolean defaultValue, final String units) {
         super();
         this.defaultValue = defaultValue;
         this.units = units;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BooleanType();
     }
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public BooleanTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
      */
     @Override
@@ -83,8 +105,10 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+     * ()
      */
     @Override
     public Object getDefaultValue() {
@@ -93,7 +117,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
      */
     @Override
@@ -103,7 +127,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
      */
     @Override
@@ -113,8 +137,9 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
     public String getDescription() {
@@ -123,7 +148,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
      */
     @Override
@@ -133,7 +158,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
      */
     @Override
index 158865aec9dff12a3d21f50b8e06f08e2beec151..adb4c1a3cb00a21f6993c4de9e8140cc86d29674 100644 (file)
@@ -43,6 +43,7 @@ public class Decimal64 implements DecimalTypeDefinition {
 
     private final List<RangeConstraint> rangeStatements;
     private final Integer fractionDigits;
+    private final DecimalTypeDefinition baseType;
 
     /**
      * Default Decimal64 Type Constructor. <br>
@@ -61,6 +62,17 @@ public class Decimal64 implements DecimalTypeDefinition {
      * @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 List<String> actualPath, final URI namespace,
             final Date revision, final Integer fractionDigits) {
         super();
@@ -71,6 +83,7 @@ public class Decimal64 implements DecimalTypeDefinition {
         this.fractionDigits = fractionDigits;
         rangeStatements = defaultRangeStatements();
         this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new Decimal64(fractionDigits);
     }
 
     /**
@@ -87,6 +100,9 @@ public class Decimal64 implements DecimalTypeDefinition {
      * 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
@@ -104,10 +120,12 @@ public class Decimal64 implements DecimalTypeDefinition {
         if (rangeStatements == null || rangeStatements.isEmpty()) {
             this.rangeStatements = defaultRangeStatements();
         } else {
-            this.rangeStatements = Collections.unmodifiableList(rangeStatements);
+            this.rangeStatements = Collections
+                    .unmodifiableList(rangeStatements);
         }
         this.fractionDigits = fractionDigits;
         this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new Decimal64(fractionDigits);
     }
 
     /**
@@ -123,6 +141,9 @@ public class Decimal64 implements DecimalTypeDefinition {
      * 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
@@ -131,11 +152,10 @@ public class Decimal64 implements DecimalTypeDefinition {
      *            Range Constraint Statements
      * @param fractionDigits
      *            integer between 1 and 18 inclusively
-     *
-     * @exception IllegalArgumentException
      */
     public Decimal64(final List<String> actualPath, final URI namespace,
-            final Date revision, final String units, final BigDecimal defaultValue,
+            final Date revision, final String units,
+            final BigDecimal defaultValue,
             final List<RangeConstraint> rangeStatements,
             final Integer fractionDigits) {
         super();
@@ -148,12 +168,14 @@ public class Decimal64 implements DecimalTypeDefinition {
             this.rangeStatements = defaultRangeStatements();
 
         } else {
-            this.rangeStatements = Collections.unmodifiableList(rangeStatements);
+            this.rangeStatements = Collections
+                    .unmodifiableList(rangeStatements);
         }
         this.units = units;
         this.defaultValue = defaultValue;
         this.fractionDigits = fractionDigits;
         this.path = BaseTypes.schemaPath(name);
+        this.baseType = new Decimal64(fractionDigits);
     }
 
     /**
@@ -175,7 +197,7 @@ public class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public DecimalTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
index 9a7b13ddb3e0e9f34c611111348169a7b558dc9b..1b5abb22093080657f00037ecd2e017324214c03 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -19,13 +21,25 @@ import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;
 public class EmptyType implements EmptyTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("empty");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    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 List<String> actualPath,
+            final URI namespace, final Date revision) {
+        path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new EmptyType();
+    }
 
     @Override
     public EmptyTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
index 2057a42eb6490bf659d11149ff85bb138326634b..86bde24d62d8131314f0f1d37b7e8ed61552f72e 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * 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
 */
+ * 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.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -33,7 +35,6 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     private List<PatternConstraint> patterns = Collections.emptyList();
     private Integer fractionDigits = null;
 
-
     private Status status;
     private String units;
     private Object defaultValue;
@@ -46,7 +47,8 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private final String description;
         private final String reference;
 
-        private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
+        private List<UnknownSchemaNode> unknownSchemaNodes = Collections
+                .emptyList();
         private Status status = Status.CURRENT;
         private String units = "";
         private Object defaultValue = null;
@@ -56,11 +58,23 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private List<PatternConstraint> patterns = Collections.emptyList();
         private Integer fractionDigits = null;
 
+        public Builder(final List<String> actualPath, final URI namespace,
+                final Date revision, final QName typeName,
+                TypeDefinition<?> baseType, final String description,
+                final String reference) {
+            this.typeName = typeName;
+            this.baseType = baseType;
+            this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+            this.description = description;
+            this.reference = reference;
+        }
+
         public Builder(final QName typeName, TypeDefinition<?> baseType,
-                final String description, final String reference) {
+                final String description, final String reference,
+                SchemaPath path) {
             this.typeName = typeName;
             this.baseType = baseType;
-            this.path = BaseTypes.schemaPath(typeName);
+            this.path = path;
             this.description = description;
             this.reference = reference;
         }
@@ -80,27 +94,28 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
             return this;
         }
 
-        public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
+        public Builder unknownSchemaNodes(
+                final List<UnknownSchemaNode> unknownSchemaNodes) {
             this.unknownSchemaNodes = unknownSchemaNodes;
             return this;
         }
 
         public Builder ranges(final List<RangeConstraint> ranges) {
-            if(ranges != null) {
+            if (ranges != null) {
                 this.ranges = ranges;
             }
             return this;
         }
 
         public Builder lengths(final List<LengthConstraint> lengths) {
-            if(lengths != null) {
+            if (lengths != null) {
                 this.lengths = lengths;
             }
             return this;
         }
 
         public Builder patterns(final List<PatternConstraint> patterns) {
-            if(patterns != null) {
+            if (patterns != null) {
                 this.patterns = patterns;
             }
             return this;
@@ -188,8 +203,10 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         result = prime * result
                 + ((description == null) ? 0 : description.hashCode());
-        result = prime * result
-                + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode());
+        result = prime
+                * result
+                + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes
+                        .hashCode());
         result = prime * result + ((path == null) ? 0 : path.hashCode());
         result = prime * result
                 + ((reference == null) ? 0 : reference.hashCode());
index 3837f72a8ae6d937e6d96f2e4c79da2865330a41..533318e39e3c15e8ac5fc1fcde2ac5d36fb669f0 100644 (file)
@@ -7,7 +7,9 @@
   */\r
 package org.opendaylight.controller.yang.model.util;\r
 \r
+import java.net.URI;\r
 import java.util.Collections;\r
+import java.util.Date;\r
 import java.util.List;\r
 \r
 import org.opendaylight.controller.yang.common.QName;\r
@@ -24,16 +26,32 @@ import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition
 public class IdentityrefType implements IdentityrefTypeDefinition {\r
 \r
     private final QName name = BaseTypes.constructQName("identityref");\r
-    private final SchemaPath path = BaseTypes.schemaPath(name);\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
-    public IdentityrefType(QName identity) {\r
+    private IdentityrefType(QName identity) {\r
         this.identity = identity;\r
+        this.path = BaseTypes.schemaPath(name);\r
+        this.baseType = this;\r
+    }\r
+\r
+    public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
+        this.identity = identity;\r
+        this.path = schemaPath;\r
+        this.baseType = new IdentityrefType(identity);\r
+    }\r
+\r
+    public IdentityrefType(final List<String> actualPath,\r
+            final URI namespace, final Date revision, final QName identity) {\r
+        this.identity = identity;\r
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);\r
+        this.baseType = new IdentityrefType(identity);\r
     }\r
 \r
     @Override\r
@@ -83,7 +101,7 @@ public class IdentityrefType implements IdentityrefTypeDefinition {
 \r
     @Override\r
     public IdentityrefTypeDefinition getBaseType() {\r
-        return this;\r
+        return baseType;\r
     }\r
 \r
 }\r
index e4f62546f68abfebdfbc295869b223c3c4d170f3..e39b1fa02646feec0263417e1e39e54ac4d5585c 100644 (file)
@@ -7,7 +7,9 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -30,31 +32,42 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
                "uniquely identify a particular instance node in the data tree.";
     private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13";
 
-    private final transient SchemaPath path = BaseTypes.schemaPath(name);
+    private final transient SchemaPath path;
     private final RevisionAwareXPath xpath;
     private final String units = "";
-
+    private final InstanceIdentifierTypeDefinition baseType;
     private final boolean requireInstance;
 
-    public InstanceIdentifier(RevisionAwareXPath xpath, 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 List<String> actualPath, final URI namespace,
+            final Date revision, RevisionAwareXPath xpath, boolean requireInstance) {
         super();
+        path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.xpath = xpath;
         this.requireInstance = requireInstance;
+        this.baseType = new InstanceIdentifier(xpath, requireInstance);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public InstanceIdentifierTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
      */
     @Override
@@ -64,7 +77,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
      */
     @Override
@@ -74,7 +87,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
      */
     @Override
@@ -84,7 +97,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
      */
     @Override
@@ -94,7 +107,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
@@ -104,7 +117,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
      */
     @Override
@@ -114,7 +127,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
      */
     @Override
@@ -124,7 +137,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes()
      */
     @Override
@@ -134,7 +147,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
      * getPathStatement()
      */
@@ -145,7 +158,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
      * requireInstance()
      */
index 750dff5c7a5e9d88094c728f097a7e1c0ca81809..0e100dc79077d846d2f0ae83ce3dd4768cefdcec 100644 (file)
@@ -28,10 +28,18 @@ public class Int16 extends AbstractSignedInteger {
     private 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 List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Int16();
+
     }
 
     public Int16(final List<String> actualPath, final URI namespace,
@@ -39,11 +47,12 @@ public class Int16 extends AbstractSignedInteger {
             final String units, final Short defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
         this.defaultValue = defaultValue;
+        this.baseType = new Int16();
     }
 
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
index da356309a504735f5644eced96fbebedd81addf2..fb777c5992399aed543986684f2e94acd0531cd6 100644 (file)
@@ -30,15 +30,23 @@ public class Int32 extends AbstractSignedInteger {
     private 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 List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int32();
     }
 
     public Int32(final List<String> actualPath, final URI namespace,
             final Date revision, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int32();
         this.defaultValue = defaultValue;
     }
 
@@ -46,6 +54,7 @@ public class Int32 extends AbstractSignedInteger {
             final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Int32();
         this.defaultValue = defaultValue;
     }
 
@@ -57,7 +66,7 @@ public class Int32 extends AbstractSignedInteger {
      */
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 4b05bc59e72a9f011f36809e864a9b767217451d..b22412012b0e8d54c8bbe3819dd09ba1678f255d 100644 (file)
@@ -28,15 +28,23 @@ public class Int64 extends AbstractSignedInteger {
     private 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 List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int64();
     }
 
     public Int64(final List<String> actualPath, final URI namespace,
             final Date revision, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int64();
         this.defaultValue = defaultValue;
     }
 
@@ -44,6 +52,7 @@ public class Int64 extends AbstractSignedInteger {
             final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Int64();
         this.defaultValue = defaultValue;
     }
 
@@ -54,7 +63,7 @@ public class Int64 extends AbstractSignedInteger {
      */
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 6a917b252f4bd916bca5359add44bc4dd3c1262b..8b0fbe1fa7148197807db9ebbfc2e6b1b997091f 100644 (file)
@@ -29,15 +29,23 @@ public class Int8 extends AbstractSignedInteger {
     private 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 List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
+        this.baseType = new Int8();
     }
 
     public Int8(final List<String> actualPath, final URI namespace,
             final Date revision, final Byte defaultValue) {
         super(actualPath, namespace, revision, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
+        this.baseType = new Int8();
         this.defaultValue = defaultValue;
     }
 
@@ -45,6 +53,7 @@ public class Int8 extends AbstractSignedInteger {
             final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Byte defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Int8();
         this.defaultValue = defaultValue;
     }
 
@@ -55,7 +64,7 @@ public class Int8 extends AbstractSignedInteger {
      */
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index f58075bf307d9d6d2bd4f2012620dc4970426c7a..b4e2d6b9ad867dd3e4c3fac226be78c0fdd7a774 100644 (file)
@@ -36,6 +36,17 @@ public class StringType implements StringTypeDefinition {
     private final List<LengthConstraint> lengthStatements;
     private final List<PatternConstraint> patterns;
     private 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.
@@ -47,13 +58,15 @@ public class StringType implements StringTypeDefinition {
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
         lengthStatements = Collections.unmodifiableList(constraints);
-
-        this.patterns = Collections.emptyList();
+        patterns = Collections.emptyList();
+        baseType = new StringType();
     }
 
     /**
      *
-     *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param lengthStatements
      * @param patterns
      */
@@ -70,6 +83,7 @@ public class StringType implements StringTypeDefinition {
             this.lengthStatements = Collections.unmodifiableList(lengthStatements);
         }
         this.patterns = Collections.unmodifiableList(patterns);
+        baseType = new StringType();
     }
 
     /**
@@ -85,7 +99,7 @@ public class StringType implements StringTypeDefinition {
             final List<LengthConstraint> lengthStatements,
             final List<PatternConstraint> patterns, final String units) {
         super();
-        path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.defaultValue = defaultValue;
         if(lengthStatements == null || lengthStatements.size() == 0) {
             final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
@@ -94,8 +108,9 @@ public class StringType implements StringTypeDefinition {
         } else {
             this.lengthStatements = Collections.unmodifiableList(lengthStatements);
         }
-        this.patterns = patterns;
+        this.patterns = Collections.unmodifiableList(patterns);
         this.units = units;
+        this.baseType = new StringType();
     }
 
     /*
@@ -105,7 +120,7 @@ public class StringType implements StringTypeDefinition {
      */
     @Override
     public StringTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 9db4ea9df878cdbc72da18ef30ebd431a99d0fdb..5764cb26c7bd0d616ac0ce9575d3fa9f752189c0 100644 (file)
@@ -26,15 +26,23 @@ public 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 List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint16();
     }
 
     public Uint16(final List<String> actualPath,
             final URI namespace, final Date revision, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint16();
         this.defaultValue = defaultValue;
     }
 
@@ -42,6 +50,7 @@ public class Uint16 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint16();
         this.defaultValue = defaultValue;
     }
 
@@ -53,7 +62,7 @@ public class Uint16 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 75f9b49693e41ad01015156b31836334c02e330f..47af1e1c986d4ad10680833690be31b645c9e06c 100644 (file)
@@ -26,15 +26,23 @@ public class Uint32 extends AbstractUnsignedInteger {
     private static final QName name = BaseTypes.constructQName("uint32");
     private 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 List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint32();
     }
 
     public Uint32(final List<String> actualPath,
             final URI namespace, final Date revision, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint32();
         this.defaultValue = defaultValue;
     }
 
@@ -42,6 +50,7 @@ public class Uint32 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint32();
         this.defaultValue = defaultValue;
     }
 
@@ -53,7 +62,7 @@ public class Uint32 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 05ea8c9e0983f98687a950fc8c2cffbc841c1328..f9c2aa3c90a15f41acb9700bae152aa953a237a9 100644 (file)
@@ -30,15 +30,23 @@ public class Uint64 extends AbstractUnsignedInteger {
     private 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 List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint64();
     }
 
     public Uint64(final List<String> actualPath,
             final URI namespace, final Date revision, final BigInteger defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint64();
         this.defaultValue = defaultValue;
     }
 
@@ -46,6 +54,7 @@ public class Uint64 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final BigInteger defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint64();
         this.defaultValue = defaultValue;
     }
 
@@ -57,7 +66,7 @@ public class Uint64 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index aa1e6cacfbf3e315b0604d35114df1360f6e325b..ece0eb5c3f37dba7d132160e47ecd9130e253c62 100644 (file)
@@ -29,15 +29,23 @@ public class Uint8 extends AbstractUnsignedInteger {
     private 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 List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint8();
     }
 
     public Uint8(final List<String> actualPath,
             final URI namespace, final Date revision, final Short defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint8();
         this.defaultValue = defaultValue;
     }
 
@@ -45,6 +53,7 @@ public class Uint8 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Short defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint8();
         this.defaultValue = defaultValue;
     }
 
@@ -55,7 +64,7 @@ public class Uint8 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index ad40393291d748a0a428fed9674789589e0e0d0e..1063f3b22b6bfe4720af2539803f6296875c9c72 100644 (file)
@@ -7,7 +7,9 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -20,23 +22,34 @@ import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
 public class UnionType implements UnionTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("union");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    private final SchemaPath path;
     private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
-
+    private final UnionTypeDefinition baseType;
     private final List<TypeDefinition<?>> types;
 
+    private UnionType(List<TypeDefinition<?>> types) {
+        if(types == null) {
+            throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
+        }
+        path = BaseTypes.schemaPath(name);
+        this.types = types;
+        this.baseType = this;
+    }
 
-    public UnionType(List<TypeDefinition<?>> types) {
+    public UnionType(final List<String> actualPath, final URI namespace,
+            final Date revision, List<TypeDefinition<?>> types) {
         if(types == null) {
             throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
         }
+        path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.types = types;
+        this.baseType = new UnionType(types);
     }
 
     @Override
     public UnionTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
@@ -86,8 +99,12 @@ public class UnionType implements UnionTypeDefinition {
 
     @Override
     public int hashCode() {
-        // TODO: implement hashcode
-        return 4;
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        result = prime * result + ((types == null) ? 0 : types.hashCode());
+        return result;
     }
 
     @Override
index f3db85cf9a0242ab0f90d2753e0d1408368e4b36..6d41321bfd0cb5042c150f3f77779e9f68cc344a 100644 (file)
@@ -9,39 +9,16 @@ package org.opendaylight.controller.yang.model.util;
 \r
 import java.net.URI;\r
 import java.util.Date;\r
-import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.List;\r
-import java.util.Map;\r
 import java.util.Set;\r
 \r
-import org.opendaylight.controller.yang.common.QName;\r
 import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;\r
 \r
 public class YangTypesConverter {\r
-\r
-    private static final Map<String, TypeDefinition<? extends TypeDefinition<?>>> baseYangTypeMap = new HashMap<String, TypeDefinition<? extends TypeDefinition<?>>>();\r
     private static final Set<String> baseYangTypes = new HashSet<String>();\r
 \r
-    private static final TypeDefinition<BinaryTypeDefinition> BINARY = new BinaryType();\r
-    private static final TypeDefinition<BitsTypeDefinition> BITS = new BitsType();\r
-    private static final TypeDefinition<BooleanTypeDefinition> BOOLEAN_TYPE = new BooleanType();\r
-    private static final TypeDefinition<EmptyTypeDefinition> EMPTY_TYPE = new EmptyType();\r
-    private static final TypeDefinition<InstanceIdentifierTypeDefinition> INST_ID_TYPE = new InstanceIdentifier(\r
-            null, true);\r
-\r
     static {\r
-        baseYangTypeMap.put("binary", BINARY);\r
-        baseYangTypeMap.put("bits", BITS);\r
-        baseYangTypeMap.put("boolean", BOOLEAN_TYPE);\r
-        baseYangTypeMap.put("empty", EMPTY_TYPE);\r
-        baseYangTypeMap.put("instance-identifier", INST_ID_TYPE);\r
-\r
         baseYangTypes.add("binary");\r
         baseYangTypes.add("bits");\r
         baseYangTypes.add("boolean");\r
@@ -67,40 +44,45 @@ public class YangTypesConverter {
         return baseYangTypes.contains(type);\r
     }\r
 \r
-    public static TypeDefinition<?> javaTypeForBaseYangType(QName typeQName) {\r
-        TypeDefinition<?> type = baseYangTypeMap.get(typeQName.getLocalName());\r
-        return type;\r
-    }\r
-\r
     public static TypeDefinition<?> javaTypeForBaseYangType(\r
             List<String> actualPath, URI namespace, Date revision,\r
             String typeName) {\r
+        TypeDefinition<?> type = null;\r
 \r
         if (typeName.startsWith("int")) {\r
             if (typeName.equals("int8")) {\r
-                return new Int8(actualPath, namespace, revision);\r
+                type = new Int8(actualPath, namespace, revision);\r
             } else if (typeName.equals("int16")) {\r
-                return new Int16(actualPath, namespace, revision);\r
+                type = new Int16(actualPath, namespace, revision);\r
             } else if (typeName.equals("int32")) {\r
-                return new Int32(actualPath, namespace, revision);\r
+                type = new Int32(actualPath, namespace, revision);\r
             } else if (typeName.equals("int64")) {\r
-                return new Int64(actualPath, namespace, revision);\r
+                type = new Int64(actualPath, namespace, revision);\r
             }\r
         } else if (typeName.startsWith("uint")) {\r
             if (typeName.equals("uint8")) {\r
-                return new Uint8(actualPath, namespace, revision);\r
+                type = new Uint8(actualPath, namespace, revision);\r
             } else if (typeName.equals("uint16")) {\r
-                return new Uint16(actualPath, namespace, revision);\r
+                type = new Uint16(actualPath, namespace, revision);\r
             } else if (typeName.equals("uint32")) {\r
-                return new Uint32(actualPath, namespace, revision);\r
+                type = new Uint32(actualPath, namespace, revision);\r
             } else if (typeName.equals("uint64")) {\r
-                return new Uint64(actualPath, namespace, revision);\r
+                type = new Uint64(actualPath, namespace, revision);\r
             }\r
-        } else if (typeName.equals("string")) {\r
-            return new StringType(actualPath, namespace, revision);\r
+        } else if ("string".equals(typeName)) {\r
+            type = new StringType(actualPath, namespace, revision);\r
+        } else if("binary".equals(typeName)) {\r
+            type = new BinaryType(actualPath, namespace, revision);\r
+        } else if("bits".equals(typeName)) {\r
+            type = new BitsType(actualPath, namespace, revision);\r
+        } else if("boolean".equals(typeName)) {\r
+            type = new BooleanType(actualPath, namespace, revision);\r
+        } else if("empty".equals(typeName)) {\r
+            type = new EmptyType(actualPath, namespace, revision);\r
+        } else if("instance-identifier".equals(typeName)) {\r
+            type = new InstanceIdentifier(actualPath, namespace, revision, null, true);\r
         }\r
 \r
-        TypeDefinition<?> type = baseYangTypeMap.get(typeName);\r
         return type;\r
     }\r
 \r