Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / config / ConfigStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.config;
9
10 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
11 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
13 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
17
18 public class ConfigStatementSupport extends
19     AbstractStatementSupport<Boolean, ConfigStatement, EffectiveStatement<Boolean, ConfigStatement>> {
20     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
21         YangStmtMapping.CONFIG).build();
22
23     public ConfigStatementSupport() {
24         super(YangStmtMapping.CONFIG);
25     }
26
27     @Override
28     public Boolean parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
29         return ArgumentUtils.parseBoolean(ctx, value);
30     }
31
32     @Override
33     public ConfigStatement createDeclared(final StmtContext<Boolean, ConfigStatement, ?> ctx) {
34         final ConfigStatement ret = new ConfigStatementImpl(ctx);
35
36         if (EmptyConfigStatement.FALSE.equals(ret)) {
37             return EmptyConfigStatement.FALSE;
38         } else if (EmptyConfigStatement.TRUE.equals(ret)) {
39             return EmptyConfigStatement.TRUE;
40         } else {
41             return ret;
42         }
43     }
44
45     @Override
46     public EffectiveStatement<Boolean, ConfigStatement> createEffective(
47             final StmtContext<Boolean, ConfigStatement, EffectiveStatement<Boolean, ConfigStatement>> ctx) {
48         final EffectiveStatement<Boolean, ConfigStatement> ret = new ConfigEffectiveStatementImpl(ctx);
49         final ConfigStatement declared = ret.getDeclared();
50         if (declared instanceof EmptyConfigStatement && ret.effectiveSubstatements().isEmpty()) {
51             return ((EmptyConfigStatement)declared).toEffective();
52         }
53         return ret;
54     }
55
56     @Override
57     public String internArgument(final String rawArgument) {
58         return ArgumentUtils.internBoolean(rawArgument);
59     }
60
61     @Override
62     protected SubstatementValidator getSubstatementValidator() {
63         return SUBSTATEMENT_VALIDATOR;
64     }
65 }