Do not expose StmtContext to StatementFactory
[yangtools.git] / parser / rfc8639-parser-support / src / main / java / org / opendaylight / yangtools / rfc8639 / parser / SubscriptionStateNotificationStatementSupport.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.rfc8639.parser;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.rfc8639.model.api.SubscribedNotificationsStatements;
12 import org.opendaylight.yangtools.rfc8639.model.api.SubscriptionStateNotificationEffectiveStatement;
13 import org.opendaylight.yangtools.rfc8639.model.api.SubscriptionStateNotificationStatement;
14 import org.opendaylight.yangtools.yang.common.Empty;
15 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
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.parser.api.YangParserConfiguration;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractEmptyStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26
27 public final class SubscriptionStateNotificationStatementSupport
28         extends AbstractEmptyStatementSupport<SubscriptionStateNotificationStatement,
29             SubscriptionStateNotificationEffectiveStatement> {
30     private static final SubstatementValidator VALIDATOR =
31         SubstatementValidator.builder(SubscribedNotificationsStatements.SUBSCRIPTION_STATE_NOTIFICATION).build();
32
33     public SubscriptionStateNotificationStatementSupport(final YangParserConfiguration config) {
34         super(SubscribedNotificationsStatements.SUBSCRIPTION_STATE_NOTIFICATION, StatementPolicy.exactReplica(),
35             config, VALIDATOR);
36     }
37
38     @Override
39     public void onStatementAdded(final Mutable<Empty, SubscriptionStateNotificationStatement,
40             SubscriptionStateNotificationEffectiveStatement> stmt) {
41         SourceException.throwIf(YangStmtMapping.NOTIFICATION != stmt.coerceParentContext().publicDefinition(), stmt,
42             "Only notifications may be marked with subscription-state-notification");
43     }
44
45     @Override
46     protected SubscriptionStateNotificationStatement createDeclared(final BoundStmtCtx<Empty> ctx,
47             final ImmutableList<DeclaredStatement<?>> substatements) {
48         return new SubscriptionStateNotificationStatementImpl(substatements);
49     }
50
51     @Override
52     protected SubscriptionStateNotificationStatement attachDeclarationReference(
53             final SubscriptionStateNotificationStatement stmt, final DeclarationReference reference) {
54         return new RefSubscriptionStateNotificationStatement(stmt, reference);
55     }
56
57     @Override
58     protected SubscriptionStateNotificationEffectiveStatement createEffective(
59             final Current<Empty, SubscriptionStateNotificationStatement> stmt,
60             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
61         return new SubscriptionStateNotificationEffectiveStatementImpl(stmt.declared(), substatements);
62     }
63 }