2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang.model.util;
11 import java.util.Collections;
12 import java.util.Date;
13 import java.util.List;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
23 * The <code>default</code> implementation of Instance Leafref Type Definition
26 * @see LeafrefTypeDefinition
28 public class Leafref implements LeafrefTypeDefinition {
29 private static final QName name = BaseTypes.constructQName("leafref");
30 private static final String description = "The leafref type is used to reference a "
31 + "particular leaf instance in the data tree.";
32 private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.9";
33 private final SchemaPath path;
34 private final RevisionAwareXPath xpath;
35 private final String units = "";
36 private final LeafrefTypeDefinition baseType;
38 private Leafref(final RevisionAwareXPath xpath) {
40 this.path = BaseTypes.schemaPath(name);
44 public Leafref(final List<String> actualPath, final URI namespace,
45 final Date revision, final RevisionAwareXPath xpath) {
47 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
49 baseType = new Leafref(xpath);
52 public Leafref(final List<String> actualPath, final URI namespace,
53 final Date revision, final LeafrefTypeDefinition baseType,
54 final RevisionAwareXPath xpath) {
56 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
58 this.baseType = baseType;
65 * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
68 public LeafrefTypeDefinition getBaseType() {
75 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
78 public String getUnits() {
86 * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
90 public Object getDefaultValue() {
97 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
100 public QName getQName() {
107 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
110 public SchemaPath getPath() {
118 * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
121 public String getDescription() {
128 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
131 public String getReference() {
138 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
141 public Status getStatus() {
142 return Status.CURRENT;
149 * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes
153 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
154 return Collections.emptyList();
161 * org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition
162 * #getPathStatement()
165 public RevisionAwareXPath getPathStatement() {
170 public int hashCode() {
171 final int prime = 31;
173 result = prime * result + ((path == null) ? 0 : path.hashCode());
174 result = prime * result + ((units == null) ? 0 : units.hashCode());
175 result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
180 public boolean equals(Object obj) {
187 if (getClass() != obj.getClass()) {
190 Leafref other = (Leafref) obj;
192 if (other.path != null) {
195 } else if (!path.equals(other.path)) {
199 if (other.units != null) {
202 } else if (!units.equals(other.units)) {
206 if (other.xpath != null) {
209 } else if (!xpath.equals(other.xpath)) {
216 public String toString() {
217 StringBuilder builder = new StringBuilder();
218 builder.append("Leafref [path=");
219 builder.append(path);
220 builder.append(", xpath=");
221 builder.append(xpath);
222 builder.append(", units=");
223 builder.append(units);
225 return builder.toString();