Merge branch 'master' of ../controller
[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     private static final ValueStatementSupport INSTANCE = new ValueStatementSupport();
23
24     private ValueStatementSupport() {
25         super(YangStmtMapping.VALUE);
26     }
27
28     public static ValueStatementSupport getInstance() {
29         return INSTANCE;
30     }
31
32     @Override
33     public Integer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
34         try {
35             return Integer.valueOf(value);
36         } catch (NumberFormatException e) {
37             throw new SourceException(ctx.getStatementSourceReference(), e,
38                 "%s is not valid value statement integer argument in a range of -2147483648..2147483647", value);
39         }
40     }
41
42     @Override
43     public ValueStatement createDeclared(final StmtContext<Integer, ValueStatement, ?> ctx) {
44         return new ValueStatementImpl(ctx);
45     }
46
47     @Override
48     public EffectiveStatement<Integer, ValueStatement> createEffective(
49             final StmtContext<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> ctx) {
50         return new ValueEffectiveStatementImpl(ctx);
51     }
52
53     @Override
54     protected SubstatementValidator getSubstatementValidator() {
55         return SUBSTATEMENT_VALIDATOR;
56     }
57 }