2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
10 import static com.google.common.base.Verify.verify;
12 import com.google.common.collect.ImmutableList;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
15 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
21 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
22 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
23 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
24 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
25 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.QNameWithFlagsEffectiveStatementState;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
33 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
35 abstract class AbstractNotificationStatementSupport
36 extends AbstractSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
37 AbstractNotificationStatementSupport(final YangParserConfiguration config, final SubstatementValidator validator) {
38 super(YangStmtMapping.NOTIFICATION, uninstantiatedPolicy(), config, validator);
42 protected final NotificationStatement createDeclared(final BoundStmtCtx<QName> ctx,
43 final ImmutableList<DeclaredStatement<?>> substatements) {
44 return DeclaredStatements.createNotification(ctx.getArgument(), substatements);
48 protected final NotificationStatement attachDeclarationReference(final NotificationStatement stmt,
49 final DeclarationReference reference) {
50 return DeclaredStatementDecorators.decorateNotification(stmt, reference);
54 protected final NotificationEffectiveStatement createEffective(final Current<QName, NotificationStatement> stmt,
55 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
57 return EffectiveStatements.createNotification(stmt.declared(), stmt.getArgument(),
58 EffectiveStmtUtils.historyAndStatusFlags(stmt.history(), substatements), substatements);
59 } catch (SubstatementIndexingException e) {
60 throw new SourceException(e.getMessage(), stmt, e);
65 // FIXME: propagate original?
66 public final NotificationEffectiveStatement copyEffective(final Current<QName, NotificationStatement> stmt,
67 final NotificationEffectiveStatement original) {
68 return EffectiveStatements.copyNotification(original, stmt.getArgument(),
69 EffectiveStmtUtils.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()));
73 public final EffectiveStatementState extractEffectiveState(final NotificationEffectiveStatement stmt) {
74 verify(stmt instanceof NotificationDefinition, "Unexpected statement %s", stmt);
75 final var schema = (NotificationDefinition) stmt;
76 return new QNameWithFlagsEffectiveStatementState(stmt.argument(),
77 EffectiveStmtUtils.historyAndStatusFlags(schema));