Move implementation of OnStatementAdded to single class
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / AbstractNotificationStatementSupport.java
index 0c563e34949955022088dd756b38c20f16b34076..b9f86e85f43709327a6aaa62dced498d5508839d 100644 (file)
@@ -7,18 +7,19 @@
  */
 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.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 
 abstract class AbstractNotificationStatementSupport
-        extends AbstractQNameStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
+        extends BaseSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
     AbstractNotificationStatementSupport() {
         super(YangStmtMapping.NOTIFICATION);
     }
@@ -29,13 +30,33 @@ abstract class AbstractNotificationStatementSupport
     }
 
     @Override
-    public final void onStatementAdded(
-            final Mutable<QName, NotificationStatement, NotificationEffectiveStatement> stmt) {
-        stmt.coerceParentContext().addToNs(ChildSchemaNodeNamespace.class, stmt.coerceStatementArgument(), stmt);
+    protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularNotificationStatement(ctx.coerceStatementArgument(), substatements);
     }
 
     @Override
-    public final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
-        return new NotificationStatementImpl(ctx);
+    protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
+        return new EmptyNotificationStatement(ctx.coerceStatementArgument());
     }
+
+    @Override
+    protected final NotificationEffectiveStatement createEffective(
+            final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
+            final NotificationStatement declared,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        checkEffective(ctx);
+
+        return new NotificationEffectiveStatementImpl(declared, historyAndStatusFlags(ctx, substatements), ctx,
+            substatements);
+    }
+
+    @Override
+    protected final NotificationEffectiveStatement createEmptyEffective(
+            final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
+            final NotificationStatement declared) {
+        return createEffective(ctx, declared, ImmutableList.of());
+    }
+
+    abstract void checkEffective(StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx);
 }
\ No newline at end of file