43def3464b4c8c7e9122e4aff1ccf90d1c0e3ea2
[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 com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import java.util.List;
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 /**
21  * The <code>default</code> implementation of Identityref Type Definition
22  * interface.
23  *
24  * @see IdentityrefTypeDefinition
25  * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#identityrefTypeBuilder(SchemaPath)} instead
26  */
27 @Deprecated
28 public final class IdentityrefType implements IdentityrefTypeDefinition {
29     private static final QName NAME = BaseTypes.IDENTITYREF_QNAME;
30     private static final String DESCRIPTION = "The identityref type is used to reference an existing identity.";
31     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10";
32     private static final String UNITS = "";
33
34     private final IdentitySchemaNode identity;
35     private final SchemaPath path;
36
37     private IdentityrefType(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
38         this.path = Preconditions.checkNotNull(path, "Path must be specified");
39         this.identity = Preconditions.checkNotNull(baseIdentity,"baseIdentity must be specified.");
40     }
41
42     /**
43      * Constructs a new {@link IdentityrefTypeDefinition} definition.
44      *
45      * @param path Path to the definition.
46      * @param baseIdentity Base Identity, all derived identities are valid arguments for instance of this type.
47      * @return New identityref definition.
48      */
49     public static IdentityrefType create(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
50         return new IdentityrefType(path, baseIdentity);
51     }
52
53     @Override
54     public String getUnits() {
55         return UNITS;
56     }
57
58     @Override
59     public Object getDefaultValue() {
60         return identity;
61     }
62
63     @Override
64     public QName getQName() {
65         return NAME;
66     }
67
68     @Override
69     public SchemaPath getPath() {
70         return path;
71     }
72
73     @Override
74     public String getDescription() {
75         return DESCRIPTION;
76     }
77
78     @Override
79     public String getReference() {
80         return REFERENCE;
81     }
82
83     @Override
84     public Status getStatus() {
85         return Status.CURRENT;
86     }
87
88     @Override
89     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
90         return Collections.emptyList();
91     }
92
93     @Override
94     public IdentitySchemaNode getIdentity() {
95         return identity;
96     }
97
98     @Override
99     public IdentityrefTypeDefinition getBaseType() {
100         return null;
101     }
102
103     @Override
104     public String toString() {
105         return "identityref " + identity.getQName().getLocalName();
106     }
107 }