2 * Copyright (c) 2020 PANTHEON.tech, 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.yang.parser.rfc7950.stmt.meta;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import java.util.function.Function;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins;
22 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
23 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
28 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
31 * Specialization of {@link AbstractQNameStatementSupport} for {@code input} and {@code output} statements.
33 * @param <D> Declared Statement representation
34 * @param <E> Effective Statement representation
36 abstract class AbstractOperationContainerStatementSupport<D extends DeclaredStatement<QName>,
37 E extends SchemaTreeEffectiveStatement<D>> extends AbstractImplicitStatementSupport<D, E> {
38 private final Function<QNameModule, QName> createArgument;
40 AbstractOperationContainerStatementSupport(final StatementDefinition publicDefinition,
41 final YangParserConfiguration config, final Function<QNameModule, QName> createArgument) {
42 super(publicDefinition, uninstantiatedPolicy(), config);
43 this.createArgument = requireNonNull(createArgument);
47 public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
48 return createArgument.apply(StmtContextUtils.getRootModuleQName(ctx));
52 final @NonNull E copyDeclaredEffective(final Current<QName, D> stmt, final E original) {
53 return copyDeclaredEffective(
54 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
58 abstract @NonNull E copyDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
62 final @NonNull E copyUndeclaredEffective(final Current<QName, D> stmt, final E original) {
63 return copyUndeclaredEffective(
64 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
68 abstract @NonNull E copyUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt, @NonNull E original);
71 final @NonNull E createDeclaredEffective(final Current<QName, D> stmt,
72 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
74 return createDeclaredEffective(
75 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
76 } catch (SubstatementIndexingException e) {
77 throw new SourceException(e.getMessage(), stmt, e);
81 abstract @NonNull E createDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
82 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
85 final E createUndeclaredEffective(final Current<QName, D> stmt,
86 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
87 return createUndeclaredEffective(EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements),
91 abstract @NonNull E createUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
92 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);