de57f4c946353ffadeff709684b153929d3dcc18
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / ValueStatementImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.rfc6020;
9
10 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
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.AbstractDeclaredStatement;
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.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
17
18 public class ValueStatementImpl extends AbstractDeclaredStatement<Integer> implements ValueStatement {
19
20     protected ValueStatementImpl(StmtContext<Integer, ValueStatement, ?> context) {
21         super(context);
22     }
23
24     public static class Definition extends
25             AbstractStatementSupport<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> {
26
27         public Definition() {
28             super(Rfc6020Mapping.VALUE);
29         }
30
31         @Override
32         public Integer parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
33             int valueNum;
34
35             try {
36                 valueNum = Integer.parseInt(value);
37             } catch (NumberFormatException e) {
38                 throw new IllegalArgumentException(
39                         String.format(
40                                 "%s is not valid value statement integer argument in a range of -2147483648..2147483647",
41                                 value), e);
42             }
43
44             return valueNum;
45         }
46
47         @Override
48         public ValueStatement createDeclared(StmtContext<Integer, ValueStatement, ?> ctx) {
49             return new ValueStatementImpl(ctx);
50         }
51
52         @Override
53         public EffectiveStatement<Integer, ValueStatement> createEffective(
54                 StmtContext<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> ctx) {
55             return new ValueEffectiveStatementImpl(ctx);
56         }
57
58     }
59
60     @Override
61     public Integer getValue() {
62         return argument();
63     }
64
65 }