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.meta.SubstatementValidator;
29 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
32 * Specialization of {@link AbstractQNameStatementSupport} for {@code input} and {@code output} statements.
34 * @param <D> Declared Statement representation
35 * @param <E> Effective Statement representation
37 abstract class AbstractOperationContainerStatementSupport<D extends DeclaredStatement<QName>,
38 E extends SchemaTreeEffectiveStatement<D>> extends AbstractImplicitStatementSupport<D, E> {
39 private final Function<QNameModule, QName> createArgument;
41 AbstractOperationContainerStatementSupport(final StatementDefinition publicDefinition,
42 final YangParserConfiguration config, final SubstatementValidator validator,
43 final Function<QNameModule, QName> createArgument) {
44 super(publicDefinition, uninstantiatedPolicy(), config, validator);
45 this.createArgument = requireNonNull(createArgument);
49 public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
50 return createArgument.apply(StmtContextUtils.getRootModuleQName(ctx));
54 final @NonNull E copyDeclaredEffective(final Current<QName, D> stmt, final E original) {
55 return copyDeclaredEffective(
56 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
60 abstract @NonNull E copyDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
64 final @NonNull E copyUndeclaredEffective(final Current<QName, D> stmt, final E original) {
65 return copyUndeclaredEffective(
66 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
70 abstract @NonNull E copyUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt, @NonNull E original);
73 final @NonNull E createDeclaredEffective(final Current<QName, D> stmt,
74 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
76 return createDeclaredEffective(
77 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
78 } catch (SubstatementIndexingException e) {
79 throw new SourceException(e.getMessage(), stmt, e);
83 abstract @NonNull E createDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
84 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
87 final E createUndeclaredEffective(final Current<QName, D> stmt,
88 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
89 return createUndeclaredEffective(EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements),
93 abstract @NonNull E createUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
94 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);