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