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.api.stmt.DataTreeAwareEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
28 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractEffectiveUnknownSchmemaNode;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
32 final class YangDataEffectiveStatementImpl extends AbstractEffectiveUnknownSchmemaNode<String, YangDataStatement>
33 implements YangDataEffectiveStatement, YangDataSchemaNode {
34 private final @NonNull QName argumentQName;
35 private final @NonNull ContainerEffectiveStatement container;
37 YangDataEffectiveStatementImpl(final Current<String, YangDataStatement> stmt,
38 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final QName qname) {
39 super(stmt.declared(), stmt.argument(), stmt.history(), substatements);
40 argumentQName = requireNonNull(qname);
42 container = findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).get();
44 // TODO: this is strong binding of two API contracts. Unfortunately ContainerEffectiveStatement design is
46 verify(container instanceof ContainerSchemaNode, "Incompatible container %s", container);
50 public QName getQName() {
55 public ContainerEffectiveStatement getContainer() {
60 public ContainerSchemaNode getContainerSchemaNode() {
61 // Verified in the constructor
62 return (ContainerSchemaNode) container;
66 public YangDataEffectiveStatement asEffectiveStatement() {
71 protected <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends Map<K, V>> getNamespaceContents(
72 final Class<N> namespace) {
73 if (SchemaTreeAwareEffectiveStatement.Namespace.class.equals(namespace)
74 || DataTreeAwareEffectiveStatement.Namespace.class.equals(namespace)) {
75 @SuppressWarnings("unchecked")
76 final Map<K, V> ns = (Map<K, V>)Map.of(container.argument(), container);
77 return Optional.of(ns);
79 return super.getNamespaceContents(namespace);