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.Utils;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
30 public class LeafrefSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, LeafrefSpecification>
31 implements LeafrefTypeDefinition, TypeEffectiveStatement<LeafrefSpecification> {
33 public static final String LOCAL_NAME = "leafref";
34 private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, LOCAL_NAME);
35 private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
36 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.9";
37 private static final String UNITS = "";
39 private final SchemaPath path;
40 private RevisionAwareXPath xpath;
41 private Leafref leafrefInstance = null;
43 public LeafrefSpecificationEffectiveStatementImpl(final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx) {
46 path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
48 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
49 if (effectiveStatement instanceof PathEffectiveStatementImpl) {
50 xpath = ((PathEffectiveStatementImpl) effectiveStatement).argument();
56 public RevisionAwareXPath getPathStatement() {
61 public LeafrefTypeDefinition getBaseType() {
66 public String getUnits() {
71 public Object getDefaultValue() {
76 public QName getQName() {
81 public SchemaPath getPath() {
86 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
87 return Collections.emptyList();
91 public String getDescription() {
96 public String getReference() {
101 public Status getStatus() {
102 return Status.CURRENT;
106 public int hashCode() {
107 final int prime = 31;
109 result = prime * result + Objects.hashCode(xpath);
114 public boolean equals(final Object obj) {
121 if (getClass() != obj.getClass()) {
124 LeafrefSpecificationEffectiveStatementImpl other = (LeafrefSpecificationEffectiveStatementImpl) obj;
125 return Objects.equals(xpath, other.xpath);
129 public String toString() {
130 StringBuilder builder = new StringBuilder();
131 builder.append("type ");
132 builder.append(QNAME);
133 builder.append(" [xpath=");
134 builder.append(xpath);
136 return builder.toString();
140 public TypeDefinition<?> getTypeDefinition() {
141 if (leafrefInstance != null) {
142 return leafrefInstance;
144 leafrefInstance = Leafref.create(path, xpath);
146 return leafrefInstance;