2 * Copyright (c) 2015 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.yangtools.yang.parser.stmt.rfc6020.effective.type;
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.YangConstants;
15 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
23 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.util.Leafref;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
29 public class LeafrefSpecificationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, LeafrefSpecification>
30 implements LeafrefTypeDefinition, TypeEffectiveStatement<LeafrefSpecification> {
32 public static final String LOCAL_NAME = "leafref";
33 private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, LOCAL_NAME);
34 private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
35 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.9";
36 private static final String UNITS = "";
38 private final SchemaPath path;
39 private RevisionAwareXPath xpath;
40 private Leafref leafrefInstance = null;
42 public LeafrefSpecificationEffectiveStatementImpl(final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx) {
45 path = ctx.getParentContext().getSchemaPath().get().createChild(QNAME);
47 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
48 if (effectiveStatement instanceof PathEffectiveStatementImpl) {
49 xpath = ((PathEffectiveStatementImpl) effectiveStatement).argument();
55 public RevisionAwareXPath getPathStatement() {
60 public LeafrefTypeDefinition getBaseType() {
65 public String getUnits() {
70 public Object getDefaultValue() {
75 public QName getQName() {
80 public SchemaPath getPath() {
85 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
86 return Collections.emptyList();
90 public String getDescription() {
95 public String getReference() {
100 public Status getStatus() {
101 return Status.CURRENT;
105 public int hashCode() {
106 final int prime = 31;
108 result = prime * result + Objects.hashCode(xpath);
113 public boolean equals(final Object obj) {
120 if (getClass() != obj.getClass()) {
123 LeafrefSpecificationEffectiveStatementImpl other = (LeafrefSpecificationEffectiveStatementImpl) obj;
124 return Objects.equals(xpath, other.xpath);
128 public String toString() {
129 StringBuilder builder = new StringBuilder();
130 builder.append("type ");
131 builder.append(QNAME);
132 builder.append(" [xpath=");
133 builder.append(xpath);
135 return builder.toString();
139 public TypeDefinition<?> getTypeDefinition() {
140 if (leafrefInstance != null) {
141 return leafrefInstance;
143 leafrefInstance = Leafref.create(path, xpath);
145 return leafrefInstance;