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 / value / ValueStatementSupport.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.value;
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.ValueStatement;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17
18 public final class ValueStatementSupport extends
19         AbstractStatementSupport<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> {
20     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
21         YangStmtMapping.VALUE).build();
22
23     public ValueStatementSupport() {
24         super(YangStmtMapping.VALUE);
25     }
26
27     @Override
28     public Integer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
29         try {
30             return Integer.valueOf(value);
31         } catch (NumberFormatException e) {
32             throw new SourceException(ctx.getStatementSourceReference(), e,
33                 "%s is not valid value statement integer argument in a range of -2147483648..2147483647", value);
34         }
35     }
36
37     @Override
38     public ValueStatement createDeclared(final StmtContext<Integer, ValueStatement, ?> ctx) {
39         return new ValueStatementImpl(ctx);
40     }
41
42     @Override
43     public EffectiveStatement<Integer, ValueStatement> createEffective(
44             final StmtContext<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> ctx) {
45         return new ValueEffectiveStatementImpl(ctx);
46     }
47
48     @Override
49     protected SubstatementValidator getSubstatementValidator() {
50         return SUBSTATEMENT_VALIDATOR;
51     }
52 }