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.yang.parser.rfc7950.stmt.meta;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.YangConstants;
17 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
22 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
24 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
25 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
26 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
27 import org.opendaylight.yangtools.yang.model.ri.stmt.ImplicitStatements;
28 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
29 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
33 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
36 public final class InputStatementSupport
37 extends AbstractOperationContainerStatementSupport<InputStatement, InputEffectiveStatement> {
38 private static final SubstatementValidator RFC6020_VALIDATOR = SubstatementValidator.builder(YangStmtMapping.INPUT)
39 .addAny(YangStmtMapping.ANYXML)
40 .addAny(YangStmtMapping.CHOICE)
41 .addAny(YangStmtMapping.CONTAINER)
42 .addAny(YangStmtMapping.GROUPING)
43 .addAny(YangStmtMapping.LEAF)
44 .addAny(YangStmtMapping.LEAF_LIST)
45 .addAny(YangStmtMapping.LIST)
46 .addAny(YangStmtMapping.TYPEDEF)
47 .addAny(YangStmtMapping.USES)
49 private static final SubstatementValidator RFC7950_VALIDATOR = SubstatementValidator.builder(YangStmtMapping.INPUT)
50 .addAny(YangStmtMapping.ANYDATA)
51 .addAny(YangStmtMapping.ANYXML)
52 .addAny(YangStmtMapping.CHOICE)
53 .addAny(YangStmtMapping.CONTAINER)
54 .addAny(YangStmtMapping.GROUPING)
55 .addAny(YangStmtMapping.LEAF)
56 .addAny(YangStmtMapping.LEAF_LIST)
57 .addAny(YangStmtMapping.LIST)
58 .addAny(YangStmtMapping.MUST)
59 .addAny(YangStmtMapping.TYPEDEF)
60 .addAny(YangStmtMapping.USES)
63 private final SubstatementValidator validator;
65 private InputStatementSupport(final YangParserConfiguration config, final SubstatementValidator validator) {
66 super(YangStmtMapping.INPUT, config, YangConstants::operationInputQName);
67 this.validator = requireNonNull(validator);
70 public static @NonNull InputStatementSupport rfc6020Instance(final YangParserConfiguration config) {
71 return new InputStatementSupport(config, RFC6020_VALIDATOR);
74 public static @NonNull InputStatementSupport rfc7950Instance(final YangParserConfiguration config) {
75 return new InputStatementSupport(config, RFC7950_VALIDATOR);
79 protected SubstatementValidator getSubstatementValidator() {
84 protected InputStatement createDeclared(final StmtContext<QName, InputStatement, ?> ctx,
85 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
86 final StatementOrigin origin = ctx.origin();
89 return ImplicitStatements.createInput(ctx.getArgument(), substatements);
91 return DeclaredStatements.createInput(ctx.getArgument(), substatements);
93 throw new IllegalStateException("Unhandled statement origin " + origin);
98 protected InputStatement attachDeclarationReference(final InputStatement stmt,
99 final DeclarationReference reference) {
100 return DeclaredStatementDecorators.decorateInput(stmt, reference);
104 InputEffectiveStatement copyDeclaredEffective(final int flags, final Current<QName, InputStatement> stmt,
105 final InputEffectiveStatement original) {
106 return EffectiveStatements.copyInput(original, stmt.effectivePath(), flags);
110 InputEffectiveStatement copyUndeclaredEffective(final int flags, final Current<QName, InputStatement> stmt,
111 final InputEffectiveStatement original) {
112 return EffectiveStatements.copyInput(original, stmt.effectivePath(), flags);
116 InputEffectiveStatement createDeclaredEffective(final int flags, final Current<QName, InputStatement> stmt,
117 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
119 return EffectiveStatements.createInput(stmt.declared(), stmt.effectivePath(), flags, substatements);
120 } catch (SubstatementIndexingException e) {
121 throw new SourceException(e.getMessage(), stmt, e);
126 InputEffectiveStatement createUndeclaredEffective(final int flags, final Current<QName, InputStatement> stmt,
127 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
129 return EffectiveStatements.createInput(stmt.effectivePath(), flags, substatements);
130 } catch (SubstatementIndexingException e) {
131 throw new SourceException(e.getMessage(), stmt, e);