Allow derived context to be reused
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / AbstractNotificationStatementSupport.java
index e11a152a60dcd37a0030369abe85a46cd5019869..51ab5b62c26834860cf6fd0a0ea8e7ef59750cdf 100644 (file)
@@ -7,35 +7,53 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
 
+import com.google.common.collect.ImmutableList;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseSchemaTreeStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 abstract class AbstractNotificationStatementSupport
-        extends AbstractQNameStatementSupport<NotificationStatement, EffectiveStatement<QName, NotificationStatement>> {
+        extends BaseSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
     AbstractNotificationStatementSupport() {
-        super(YangStmtMapping.NOTIFICATION);
+        super(YangStmtMapping.NOTIFICATION, uninstantiatedPolicy());
     }
 
     @Override
-    public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        return StmtContextUtils.parseIdentifier(ctx, value);
+    protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularNotificationStatement(ctx.getArgument(), substatements);
     }
 
     @Override
-    public final void onStatementAdded(
-            final Mutable<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> stmt) {
-        stmt.coerceParentContext().addToNs(ChildSchemaNodeNamespace.class, stmt.coerceStatementArgument(), stmt);
+    protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
+        return new EmptyNotificationStatement(ctx.getArgument());
     }
 
     @Override
-    public final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
-        return new NotificationStatementImpl(ctx);
+    protected final NotificationEffectiveStatement createEffective(final Current<QName, NotificationStatement> stmt,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        try {
+            return new NotificationEffectiveStatementImpl(stmt.declared(), substatements,
+                EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt.wrapSchemaPath());
+        } catch (SubstatementIndexingException e) {
+            throw new SourceException(e.getMessage(), stmt, e);
+        }
+    }
+
+    @Override
+    public final NotificationEffectiveStatement copyEffective(final Current<QName, NotificationStatement> stmt,
+            final NotificationEffectiveStatement original) {
+        return new NotificationEffectiveStatementImpl((NotificationEffectiveStatementImpl) original,
+            EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
+            stmt.wrapSchemaPath());
     }
 }
\ No newline at end of file