Centralize substatement validators
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / AbstractNotificationStatementSupport.java
index 44b34afce0fe5472e2dac95702a50d2a69a5994b..e0d9c201fb4d8b19cea5e5d2566fc8da3491d5e6 100644 (file)
@@ -10,39 +10,57 @@ 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.DeclarationReference;
 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.stmt.BaseSchemaTreeStatementSupport;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
+import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
+import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins;
+import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
+import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
 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.SubstatementValidator;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 abstract class AbstractNotificationStatementSupport
-        extends BaseSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
-    AbstractNotificationStatementSupport() {
-        super(YangStmtMapping.NOTIFICATION);
+        extends AbstractSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
+    AbstractNotificationStatementSupport(final YangParserConfiguration config, final SubstatementValidator validator) {
+        super(YangStmtMapping.NOTIFICATION, uninstantiatedPolicy(), config, validator);
     }
 
     @Override
     protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new RegularNotificationStatement(ctx.coerceStatementArgument(), substatements);
+        return DeclaredStatements.createNotification(ctx.getArgument(), substatements);
     }
 
     @Override
-    protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
-        return new EmptyNotificationStatement(ctx.coerceStatementArgument());
+    protected final NotificationStatement attachDeclarationReference(final NotificationStatement stmt,
+            final DeclarationReference reference) {
+        return DeclaredStatementDecorators.decorateNotification(stmt, reference);
     }
 
     @Override
     protected final NotificationEffectiveStatement createEffective(final Current<QName, NotificationStatement> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        checkEffective(stmt);
-
-        return new NotificationEffectiveStatementImpl(stmt.declared(), substatements, stmt.sourceReference(),
-                historyAndStatusFlags(stmt.history(), substatements), stmt.getSchemaPath());
+        try {
+            return EffectiveStatements.createNotification(stmt.declared(), stmt.effectivePath(),
+                EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), substatements);
+        } catch (SubstatementIndexingException e) {
+            throw new SourceException(e.getMessage(), stmt, e);
+        }
     }
 
-    abstract void checkEffective(Current<QName, NotificationStatement> stmt);
-}
\ No newline at end of file
+    @Override
+    // FIXME: propagate original?
+    public final NotificationEffectiveStatement copyEffective(final Current<QName, NotificationStatement> stmt,
+            final NotificationEffectiveStatement original) {
+        return EffectiveStatements.copyNotification(original, stmt.effectivePath(),
+            EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()));
+    }
+}