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
28 * <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>.
31 public final class YangDataEffectiveStatement extends UnknownEffectiveStatementBase<String>
32 implements YangDataSchemaNode {
34 private final SchemaPath path;
35 private final QName maybeQNameArgument;
36 private final ContainerSchemaNode containerSchemaNode;
38 YangDataEffectiveStatement(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
41 QName maybeQNameArgumentInit;
43 maybeQNameArgumentInit = StmtContextUtils.qnameFromArgument(ctx, argument());
44 } catch (IllegalArgumentException e) {
45 maybeQNameArgumentInit = getNodeType();
47 this.maybeQNameArgument = maybeQNameArgumentInit;
49 path = ctx.getParentContext().getSchemaPath().get().createChild(maybeQNameArgument);
50 containerSchemaNode = Preconditions.checkNotNull(firstEffective(ContainerEffectiveStatementImpl.class));
55 public QName getQName() {
56 return maybeQNameArgument;
61 public SchemaPath getPath() {
67 public ContainerSchemaNode getContainer() {
68 return containerSchemaNode;
72 public int hashCode() {
73 return Objects.hash(maybeQNameArgument, path);
77 public boolean equals(final Object obj) {
82 if (!(obj instanceof YangDataEffectiveStatement)) {
86 final YangDataEffectiveStatement other = (YangDataEffectiveStatement) obj;
87 return Objects.equals(maybeQNameArgument, other.maybeQNameArgument) && Objects.equals(path, other.path);
91 public String toString() {
92 return MoreObjects.toStringHelper(this).add("qname", maybeQNameArgument).add("path", path).toString();