d17843af898b44adb1d6a5b2c9d140e446e2675b
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / Leafref.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.controller.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
19
20 /**
21  * The <code>default</code> implementation of Instance Leafref Type Definition
22  * interface.
23  *
24  * @see LeafrefTypeDefinition
25  */
26 public final class Leafref implements LeafrefTypeDefinition {
27     private static final QName name = BaseTypes.constructQName("leafref");
28     private static final String description = "The leafref type is used to reference a "
29             + "particular leaf instance in the data tree.";
30     private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.9";
31     private final SchemaPath path;
32     private final RevisionAwareXPath xpath;
33     private final String units = "";
34     private final LeafrefTypeDefinition baseType;
35
36     private Leafref(final RevisionAwareXPath xpath) {
37         this.xpath = xpath;
38         this.path = BaseTypes.schemaPath(name);
39         this.baseType = this;
40     }
41
42     public Leafref(final SchemaPath path, final RevisionAwareXPath xpath) {
43         super();
44         this.path = path;
45         this.xpath = xpath;
46         baseType = new Leafref(xpath);
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see
53      * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
54      */
55     @Override
56     public LeafrefTypeDefinition getBaseType() {
57         return baseType;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
64      */
65     @Override
66     public String getUnits() {
67         return units;
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see
74      * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
75      * ()
76      */
77     @Override
78     public Object getDefaultValue() {
79         return this;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
86      */
87     @Override
88     public QName getQName() {
89         return name;
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
96      */
97     @Override
98     public SchemaPath getPath() {
99         return path;
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see
106      * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
107      */
108     @Override
109     public String getDescription() {
110         return description;
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
117      */
118     @Override
119     public String getReference() {
120         return reference;
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
127      */
128     @Override
129     public Status getStatus() {
130         return Status.CURRENT;
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see
137      * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes
138      * ()
139      */
140     @Override
141     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
142         return Collections.emptyList();
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see
149      * org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition
150      * #getPathStatement()
151      */
152     @Override
153     public RevisionAwareXPath getPathStatement() {
154         return xpath;
155     }
156
157     @Override
158     public int hashCode() {
159         final int prime = 31;
160         int result = 1;
161         result = prime * result + ((path == null) ? 0 : path.hashCode());
162         result = prime * result + ((units == null) ? 0 : units.hashCode());
163         result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
164         return result;
165     }
166
167     @Override
168     public boolean equals(Object obj) {
169         if (this == obj) {
170             return true;
171         }
172         if (obj == null) {
173             return false;
174         }
175         if (getClass() != obj.getClass()) {
176             return false;
177         }
178         Leafref other = (Leafref) obj;
179         if (path == null) {
180             if (other.path != null) {
181                 return false;
182             }
183         } else if (!path.equals(other.path)) {
184             return false;
185         }
186         if (units == null) {
187             if (other.units != null) {
188                 return false;
189             }
190         } else if (!units.equals(other.units)) {
191             return false;
192         }
193         if (xpath == null) {
194             if (other.xpath != null) {
195                 return false;
196             }
197         } else if (!xpath.equals(other.xpath)) {
198             return false;
199         }
200         return true;
201     }
202
203     @Override
204     public String toString() {
205         StringBuilder builder = new StringBuilder();
206         builder.append("Leafref [path=");
207         builder.append(path);
208         builder.append(", xpath=");
209         builder.append(xpath);
210         builder.append(", units=");
211         builder.append(units);
212         builder.append("]");
213         return builder.toString();
214     }
215 }