b9f86e85f43709327a6aaa62dced498d5508839d
[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.stmt.BaseSchemaTreeStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
20
21 abstract class AbstractNotificationStatementSupport
22         extends BaseSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
23     AbstractNotificationStatementSupport() {
24         super(YangStmtMapping.NOTIFICATION);
25     }
26
27     @Override
28     public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
29         return StmtContextUtils.parseIdentifier(ctx, value);
30     }
31
32     @Override
33     protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
34             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
35         return new RegularNotificationStatement(ctx.coerceStatementArgument(), substatements);
36     }
37
38     @Override
39     protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
40         return new EmptyNotificationStatement(ctx.coerceStatementArgument());
41     }
42
43     @Override
44     protected final NotificationEffectiveStatement createEffective(
45             final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
46             final NotificationStatement declared,
47             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
48         checkEffective(ctx);
49
50         return new NotificationEffectiveStatementImpl(declared, historyAndStatusFlags(ctx, substatements), ctx,
51             substatements);
52     }
53
54     @Override
55     protected final NotificationEffectiveStatement createEmptyEffective(
56             final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
57             final NotificationStatement declared) {
58         return createEffective(ctx, declared, ImmutableList.of());
59     }
60
61     abstract void checkEffective(StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx);
62 }