Add AbstractQName.bindTo(QNameModule)
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / config / ConfigStatementSupport.java
index a09e22dd586987dd270d699b1c198e111d7c6714..143196f029c56f0224596da103cd213fead5973a 100644 (file)
@@ -7,22 +7,25 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.config;
 
+import com.google.common.collect.ImmutableList;
 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.ConfigEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseBooleanStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 
-public final class ConfigStatementSupport extends
-    AbstractStatementSupport<Boolean, ConfigStatement, EffectiveStatement<Boolean, ConfigStatement>> {
+public final class ConfigStatementSupport
+        extends BaseBooleanStatementSupport<ConfigStatement, ConfigEffectiveStatement> {
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
         YangStmtMapping.CONFIG).build();
     private static final ConfigStatementSupport INSTANCE = new ConfigStatementSupport();
 
     private ConfigStatementSupport() {
-        super(YangStmtMapping.CONFIG);
+        super(YangStmtMapping.CONFIG, new EmptyConfigEffectiveStatement(new EmptyConfigStatement(Boolean.FALSE)),
+            new EmptyConfigEffectiveStatement(new EmptyConfigStatement(Boolean.TRUE)));
     }
 
     public static ConfigStatementSupport getInstance() {
@@ -30,41 +33,25 @@ public final class ConfigStatementSupport extends
     }
 
     @Override
-    public Boolean parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        return ArgumentUtils.parseBoolean(ctx, value);
-    }
-
-    @Override
-    public ConfigStatement createDeclared(final StmtContext<Boolean, ConfigStatement, ?> ctx) {
-        final ConfigStatement ret = new ConfigStatementImpl(ctx);
-
-        if (EmptyConfigStatement.FALSE.equals(ret)) {
-            return EmptyConfigStatement.FALSE;
-        } else if (EmptyConfigStatement.TRUE.equals(ret)) {
-            return EmptyConfigStatement.TRUE;
-        } else {
-            return ret;
-        }
+    protected SubstatementValidator getSubstatementValidator() {
+        return SUBSTATEMENT_VALIDATOR;
     }
 
     @Override
-    public EffectiveStatement<Boolean, ConfigStatement> createEffective(
-            final StmtContext<Boolean, ConfigStatement, EffectiveStatement<Boolean, ConfigStatement>> ctx) {
-        final EffectiveStatement<Boolean, ConfigStatement> ret = new ConfigEffectiveStatementImpl(ctx);
-        final ConfigStatement declared = ret.getDeclared();
-        if (declared instanceof EmptyConfigStatement && ret.effectiveSubstatements().isEmpty()) {
-            return ((EmptyConfigStatement)declared).toEffective();
-        }
-        return ret;
+    protected ConfigStatement createDeclared(final StmtContext<Boolean, ConfigStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularConfigStatement(ctx.coerceStatementArgument(), substatements);
     }
 
     @Override
-    public String internArgument(final String rawArgument) {
-        return ArgumentUtils.internBoolean(rawArgument);
+    protected ConfigEffectiveStatement createEffective(
+            final StmtContext<Boolean, ConfigStatement, ConfigEffectiveStatement> ctx,
+            final ConfigStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return new RegularConfigEffectiveStatement(declared, substatements);
     }
 
     @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return SUBSTATEMENT_VALIDATOR;
+    protected EmptyConfigEffectiveStatement createEmptyEffective(final ConfigStatement declared) {
+        return new EmptyConfigEffectiveStatement(declared);
     }
 }
\ No newline at end of file