Add BaseQNameStatementSupport.historyAndStatusFlags()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / AbstractNotificationStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, 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.yang.parser.rfc7950.stmt.notification;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseQNameStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
22
23 abstract class AbstractNotificationStatementSupport
24         extends BaseQNameStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
25     AbstractNotificationStatementSupport() {
26         super(YangStmtMapping.NOTIFICATION);
27     }
28
29     @Override
30     public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
31         return StmtContextUtils.parseIdentifier(ctx, value);
32     }
33
34     @Override
35     public final void onStatementAdded(
36             final Mutable<QName, NotificationStatement, NotificationEffectiveStatement> stmt) {
37         stmt.coerceParentContext().addToNs(ChildSchemaNodeNamespace.class, stmt.coerceStatementArgument(), stmt);
38     }
39
40     @Override
41     protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
42             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
43         return new RegularNotificationStatement(ctx.coerceStatementArgument(), substatements);
44     }
45
46     @Override
47     protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
48         return new EmptyNotificationStatement(ctx.coerceStatementArgument());
49     }
50
51     @Override
52     protected final NotificationEffectiveStatement createEffective(
53             final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
54             final NotificationStatement declared,
55             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
56         checkEffective(ctx);
57
58         return new NotificationEffectiveStatementImpl(declared, historyAndStatusFlags(ctx, substatements), ctx,
59             substatements);
60     }
61
62     @Override
63     protected final NotificationEffectiveStatement createEmptyEffective(
64             final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
65             final NotificationStatement declared) {
66         return createEffective(ctx, declared, ImmutableList.of());
67     }
68
69     abstract void checkEffective(StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx);
70 }