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
8 package org.opendaylight.yangtools.rfc8040.parser;
10 import static com.google.common.base.Verify.verify;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.collect.ImmutableList;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.rfc8040.model.api.YangDataEffectiveStatement;
19 import org.opendaylight.yangtools.rfc8040.model.api.YangDataSchemaNode;
20 import org.opendaylight.yangtools.rfc8040.model.api.YangDataStatement;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
25 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractEffectiveUnknownSchmemaNode;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
30 final class YangDataEffectiveStatementImpl extends AbstractEffectiveUnknownSchmemaNode<String, YangDataStatement>
31 implements YangDataEffectiveStatement, YangDataSchemaNode {
32 private final @NonNull QName argumentQName;
33 private final @NonNull ContainerEffectiveStatement container;
35 YangDataEffectiveStatementImpl(final Current<String, YangDataStatement> stmt,
36 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final QName qname) {
37 super(stmt.declared(), stmt.argument(), stmt.history(), substatements);
38 argumentQName = requireNonNull(qname);
40 container = findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).get();
42 // TODO: this is strong binding of two API contracts. Unfortunately ContainerEffectiveStatement design is
44 verify(container instanceof ContainerSchemaNode, "Incompatible container %s", container);
48 public QName getQName() {
53 public ContainerEffectiveStatement getContainer() {
58 public ContainerSchemaNode getContainerSchemaNode() {
59 // Verified in the constructor
60 return (ContainerSchemaNode) container;
64 public YangDataEffectiveStatement asEffectiveStatement() {
69 protected <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends Map<K, V>> getNamespaceContents(
70 final Class<N> namespace) {
71 if (SchemaTreeNamespace.class.equals(namespace) || DataTreeNamespace.class.equals(namespace)) {
72 @SuppressWarnings("unchecked")
73 final Map<K, V> ns = (Map<K, V>)Map.of(container.argument(), container);
74 return Optional.of(ns);
76 return super.getNamespaceContents(namespace);