Merge "Bug 1113 - ietf-restconf needs to specify the version of ietf-yangtypes that...
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / IdentityrefType.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
19
20 import com.google.common.base.Preconditions;
21
22 /**
23  * The <code>default</code> implementation of Identityref Type Definition
24  * interface.
25  *
26  * @see IdentityrefTypeDefinition
27  */
28 public final class IdentityrefType implements IdentityrefTypeDefinition {
29     private static final QName NAME = BaseTypes.IDENTITYREF_QNAME;
30     private final SchemaPath path;
31     private static final String DESCRIPTION = "The identityref type is used to reference an existing identity.";
32     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10";
33     private final IdentitySchemaNode identity;
34     private static final String UNITS = "";
35
36     /**
37      * Constructs new {@link IdentityrefTypeDefinition} definition.
38      *
39      * @param identity
40      * @param schemaPath
41      */
42     @Deprecated
43     public IdentityrefType(final IdentitySchemaNode identity, final SchemaPath schemaPath) {
44         this(schemaPath,identity);
45     }
46
47     private IdentityrefType(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
48         this.path = Preconditions.checkNotNull(path, "Path must be specified");
49         this.identity = Preconditions.checkNotNull(baseIdentity,"baseIdentity must be specified.");
50     }
51
52     /**
53      *
54      * Constructs new {@link IdentityrefTypeDefinition} definition.
55      *
56      * @param path Path to the definition.
57      * @param baseIdentity Base Identity, all derived identities are valid arguments for instance of this type.
58      * @return New identityref definition.
59      */
60     public static IdentityrefType create(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
61         return new IdentityrefType(path, baseIdentity);
62     }
63
64     @Override
65     public String getUnits() {
66         return UNITS;
67     }
68
69     @Override
70     public Object getDefaultValue() {
71         return identity;
72     }
73
74     @Override
75     public QName getQName() {
76         return NAME;
77     }
78
79     @Override
80     public SchemaPath getPath() {
81         return path;
82     }
83
84     @Override
85     public String getDescription() {
86         return DESCRIPTION;
87     }
88
89     @Override
90     public String getReference() {
91         return REFERENCE;
92     }
93
94     @Override
95     public Status getStatus() {
96         return Status.CURRENT;
97     }
98
99     @Override
100     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
101         return Collections.emptyList();
102     }
103
104     @Override
105     public IdentitySchemaNode getIdentity() {
106         return identity;
107     }
108
109     @Override
110     public IdentityrefTypeDefinition getBaseType() {
111         return null;
112     }
113
114     @Override
115     public String toString() {
116         return "identityref " + identity.getQName().getLocalName();
117     }
118
119 }