218426022c82014b5e515261d16990ef587eb0b6
[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.model.ri.stmt.DeclaredStatements;
18 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24
25 abstract class AbstractNotificationStatementSupport
26         extends AbstractSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
27     AbstractNotificationStatementSupport() {
28         super(YangStmtMapping.NOTIFICATION, uninstantiatedPolicy());
29     }
30
31     @Override
32     protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
33             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
34         return DeclaredStatements.createNotification(ctx.getArgument(), substatements);
35     }
36
37     @Override
38     protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
39         return DeclaredStatements.createNotification(ctx.getArgument());
40     }
41
42     @Override
43     protected final NotificationEffectiveStatement createEffective(final Current<QName, NotificationStatement> stmt,
44             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
45         try {
46             return new NotificationEffectiveStatementImpl(stmt.declared(), substatements, stmt.effectivePath(),
47                 EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements));
48         } catch (SubstatementIndexingException e) {
49             throw new SourceException(e.getMessage(), stmt, e);
50         }
51     }
52
53     @Override
54     public final NotificationEffectiveStatement copyEffective(final Current<QName, NotificationStatement> stmt,
55             final NotificationEffectiveStatement original) {
56         return new NotificationEffectiveStatementImpl((NotificationEffectiveStatementImpl) original,
57             stmt.effectivePath(),
58             EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()));
59     }
60 }