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.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
21 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
22 import org.opendaylight.yangtools.yang.model.util.Leafref;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
28 public class LeafrefSpecificationEffectiveStatementImpl extends
29 EffectiveStatementBase<String, TypeStatement.LeafrefSpecification> implements LeafrefTypeDefinition, TypeDefinitionEffectiveBuilder {
31 public static final String LOCAL_NAME = "leafref";
32 private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, LOCAL_NAME);
33 private static final SchemaPath PATH = SchemaPath.create(true, QNAME);
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, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
45 path = Utils.getSchemaPath(ctx.getParentContext()).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 Leafref buildType() {
141 if (leafrefInstance != null) {
142 return leafrefInstance;
144 leafrefInstance = Leafref.create(path, xpath);
146 return leafrefInstance;