Move 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.stmt.BaseSchemaTreeStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23
24 abstract class AbstractNotificationStatementSupport
25         extends BaseSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
26     AbstractNotificationStatementSupport() {
27         super(YangStmtMapping.NOTIFICATION, CopyPolicy.DECLARED_COPY);
28     }
29
30     @Override
31     protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
32             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
33         return new RegularNotificationStatement(ctx.getArgument(), substatements);
34     }
35
36     @Override
37     protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
38         return new EmptyNotificationStatement(ctx.getArgument());
39     }
40
41     @Override
42     protected final NotificationEffectiveStatement createEffective(final Current<QName, NotificationStatement> stmt,
43             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
44         try {
45             return new NotificationEffectiveStatementImpl(stmt.declared(), substatements,
46                 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt.wrapSchemaPath());
47         } catch (SubstatementIndexingException e) {
48             throw new SourceException(e.getMessage(), stmt, e);
49         }
50     }
51 }