BUG-4658: fix default value in BooleanType
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / IdentityrefType.java
index d7ba3dc771d5143c5536ae987acdf313e0a35664..9f0ed190169f5dca0040fde597cb46bea88520b0 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@@ -21,18 +22,32 @@ import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
  * interface.
  *
  * @see IdentityrefTypeDefinition
+ * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#identityrefTypeBuilder(SchemaPath)} instead
  */
+@Deprecated
 public final class IdentityrefType implements IdentityrefTypeDefinition {
-    private final QName name = BaseTypes.constructQName("identityref");
-    private final SchemaPath path;
+    private static final QName NAME = BaseTypes.IDENTITYREF_QNAME;
     private static final String DESCRIPTION = "The identityref type is used to reference an existing identity.";
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10";
-    private final QName identity;
     private static final String UNITS = "";
 
-    public IdentityrefType(QName identity, SchemaPath schemaPath) {
-        this.identity = identity;
-        this.path = schemaPath;
+    private final IdentitySchemaNode identity;
+    private final SchemaPath path;
+
+    private IdentityrefType(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
+        this.path = Preconditions.checkNotNull(path, "Path must be specified");
+        this.identity = Preconditions.checkNotNull(baseIdentity,"baseIdentity must be specified.");
+    }
+
+    /**
+     * Constructs a new {@link IdentityrefTypeDefinition} definition.
+     *
+     * @param path Path to the definition.
+     * @param baseIdentity Base Identity, all derived identities are valid arguments for instance of this type.
+     * @return New identityref definition.
+     */
+    public static IdentityrefType create(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
+        return new IdentityrefType(path, baseIdentity);
     }
 
     @Override
@@ -42,12 +57,12 @@ public final class IdentityrefType implements IdentityrefTypeDefinition {
 
     @Override
     public Object getDefaultValue() {
-        return identity;
+        return null;
     }
 
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
     @Override
@@ -76,7 +91,7 @@ public final class IdentityrefType implements IdentityrefTypeDefinition {
     }
 
     @Override
-    public QName getIdentity() {
+    public IdentitySchemaNode getIdentity() {
         return identity;
     }
 
@@ -87,7 +102,6 @@ public final class IdentityrefType implements IdentityrefTypeDefinition {
 
     @Override
     public String toString() {
-        return "identityref " + identity.getLocalName();
+        return "identityref " + identity.getQName().getLocalName();
     }
-
 }