2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc8040;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.MoreObjects;
13 import com.google.common.base.Preconditions;
14 import java.util.Objects;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.YangDataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ContainerEffectiveStatementImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementBase;
27 * Effective statement representation of 'yang-data' extension defined in https://tools.ietf.org/html/rfc8040#section-8
30 public final class YangDataEffectiveStatement extends UnknownEffectiveStatementBase<String>
31 implements YangDataSchemaNode {
33 private final SchemaPath path;
34 private final QName maybeQNameArgument;
35 private final ContainerSchemaNode containerSchemaNode;
37 YangDataEffectiveStatement(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
40 QName maybeQNameArgumentInit;
42 maybeQNameArgumentInit = StmtContextUtils.qnameFromArgument(ctx, argument());
43 } catch (IllegalArgumentException e) {
44 maybeQNameArgumentInit = getNodeType();
46 this.maybeQNameArgument = maybeQNameArgumentInit;
48 path = ctx.getParentContext().getSchemaPath().get().createChild(maybeQNameArgument);
49 containerSchemaNode = Preconditions.checkNotNull(firstEffective(ContainerEffectiveStatementImpl.class));
54 public QName getQName() {
55 return maybeQNameArgument;
60 public SchemaPath getPath() {
66 public ContainerSchemaNode getContainer() {
67 return containerSchemaNode;
71 public int hashCode() {
72 return Objects.hash(maybeQNameArgument, path);
76 public boolean equals(final Object obj) {
81 if (!(obj instanceof YangDataEffectiveStatement)) {
85 final YangDataEffectiveStatement other = (YangDataEffectiveStatement) obj;
86 return Objects.equals(maybeQNameArgument, other.maybeQNameArgument) && Objects.equals(path, other.path);
90 public String toString() {
91 return MoreObjects.toStringHelper(this).add("qname", maybeQNameArgument).add("path", path).toString();