2 * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
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.ActionStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
28 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
29 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
34 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
35 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.ChildSchemaNodes;
36 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
37 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.effective.ActionEffectiveStatementImpl;
39 public class ActionStatementImpl extends AbstractDeclaredStatement<QName> implements ActionStatement {
40 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
41 YangStmtMapping.ACTION)
42 .addOptional(YangStmtMapping.DESCRIPTION)
43 .addAny(YangStmtMapping.GROUPING)
44 .addAny(YangStmtMapping.IF_FEATURE)
45 .addOptional(YangStmtMapping.INPUT)
46 .addOptional(YangStmtMapping.OUTPUT)
47 .addOptional(YangStmtMapping.REFERENCE)
48 .addOptional(YangStmtMapping.STATUS)
49 .addAny(YangStmtMapping.TYPEDEF)
52 protected ActionStatementImpl(final StmtContext<QName,ActionStatement, ?> context) {
56 public static class Definition
57 extends AbstractStatementSupport<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> {
59 private static final Set<StatementDefinition> ILLEGAL_PARENTS = ImmutableSet.of(YangStmtMapping.NOTIFICATION,
60 YangStmtMapping.RPC, YangStmtMapping.ACTION);
63 super(YangStmtMapping.ACTION);
67 public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
68 return Utils.qNameFromArgument(ctx, value);
72 public void onStatementAdded(
73 final StmtContext.Mutable<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> stmt) {
74 stmt.getParentContext().addToNs(ChildSchemaNodes.class, stmt.getStatementArgument(), stmt);
78 public ActionStatement createDeclared(
79 final StmtContext<QName, ActionStatement, ?> ctx) {
80 return new ActionStatementImpl(ctx);
84 public EffectiveStatement<QName, ActionStatement> createEffective(
85 final StmtContext<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> ctx) {
86 SourceException.throwIf(StmtContextUtils.hasAncestorOfType(ctx, ILLEGAL_PARENTS),
87 ctx.getStatementSourceReference(), "Action %s is defined within a notification, rpc or another action",
88 ctx.getStatementArgument());
89 SourceException.throwIf(!StmtContextUtils.hasAncestorOfTypeWithChildOfType(ctx, YangStmtMapping.LIST,
90 YangStmtMapping.KEY), ctx.getStatementSourceReference(),
91 "Action %s is defined within a list that has no key statement", ctx.getStatementArgument());
92 SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.CASE),
93 ctx.getStatementSourceReference(), "Action %s is defined within a case statement",
94 ctx.getStatementArgument());
95 SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.MODULE),
96 ctx.getStatementSourceReference(), "Action %s is defined at the top level of a module",
97 ctx.getStatementArgument());
98 return new ActionEffectiveStatementImpl(ctx);
102 protected SubstatementValidator getSubstatementValidator() {
103 return SUBSTATEMENT_VALIDATOR;
108 public QName getName() {
114 public Collection<? extends TypedefStatement> getTypedefs() {
115 return allDeclared(TypedefStatement.class);
120 public Collection<? extends GroupingStatement> getGroupings() {
121 return allDeclared(GroupingStatement.class);
126 public StatusStatement getStatus() {
127 return firstDeclared(StatusStatement.class);
132 public DescriptionStatement getDescription() {
133 return firstDeclared(DescriptionStatement.class);
138 public ReferenceStatement getReference() {
139 return firstDeclared(ReferenceStatement.class);
143 public InputStatement getInput() {
144 return firstDeclared(InputStatement.class);
148 public OutputStatement getOutput() {
149 return firstDeclared(OutputStatement.class);
154 public Collection<? extends IfFeatureStatement> getIfFeatures() {
155 return allDeclared(IfFeatureStatement.class);