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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
12 import org.opendaylight.yangtools.yang.model.util.Leafref;
13 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
14 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
15 import java.util.Collections;
16 import java.util.List;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.YangConstants;
19 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.Status;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
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 RevisionAwareXPath xpath;
39 private final SchemaPath path;
41 public LeafrefSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
44 path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
46 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
47 if (effectiveStatement instanceof PathEffectiveStatementImpl) {
48 xpath = ((PathEffectiveStatementImpl) effectiveStatement).argument();
54 public RevisionAwareXPath getPathStatement() {
59 public LeafrefTypeDefinition getBaseType() {
64 public String getUnits() {
69 public Object getDefaultValue() {
74 public QName getQName() {
79 public SchemaPath getPath() {
84 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
85 return Collections.emptyList();
89 public String getDescription() {
94 public String getReference() {
99 public Status getStatus() {
100 return Status.CURRENT;
104 public int hashCode() {
105 final int prime = 31;
107 result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
112 public boolean equals(final Object obj) {
119 if (getClass() != obj.getClass()) {
122 LeafrefSpecificationEffectiveStatementImpl other = (LeafrefSpecificationEffectiveStatementImpl) obj;
124 if (other.xpath != null) {
127 } else if (!xpath.equals(other.xpath)) {
134 public String toString() {
135 StringBuilder builder = new StringBuilder();
136 builder.append("type ");
137 builder.append(QNAME);
138 builder.append(" [xpath=");
139 builder.append(xpath);
141 return builder.toString();
144 private Leafref leafrefInstance = null;
147 public Leafref buildType() {
149 if (leafrefInstance != null) {
150 return leafrefInstance;
152 leafrefInstance = Leafref.create(path, xpath);
154 return leafrefInstance;