Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / ValueStatementImpl.java
index 558f4c079622ff232503768eda1289595a6df00b..de57f4c946353ffadeff709684b153929d3dcc18 100644 (file)
@@ -7,51 +7,58 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
-
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
 
-public class ValueStatementImpl extends AbstractDeclaredStatement<String>
-        implements ValueStatement {
+public class ValueStatementImpl extends AbstractDeclaredStatement<Integer> implements ValueStatement {
 
-    protected ValueStatementImpl(StmtContext<String, ValueStatement, ?> context) {
+    protected ValueStatementImpl(StmtContext<Integer, ValueStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition
-            extends
-            AbstractStatementSupport<String, ValueStatement, EffectiveStatement<String, ValueStatement>> {
+    public static class Definition extends
+            AbstractStatementSupport<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.VALUE);
         }
 
         @Override
-        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
-            return value;
+        public Integer parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+            int valueNum;
+
+            try {
+                valueNum = Integer.parseInt(value);
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException(
+                        String.format(
+                                "%s is not valid value statement integer argument in a range of -2147483648..2147483647",
+                                value), e);
+            }
+
+            return valueNum;
         }
 
         @Override
-        public ValueStatement createDeclared(
-                StmtContext<String, ValueStatement, ?> ctx) {
+        public ValueStatement createDeclared(StmtContext<Integer, ValueStatement, ?> ctx) {
             return new ValueStatementImpl(ctx);
         }
 
         @Override
-        public EffectiveStatement<String, ValueStatement> createEffective(
-                StmtContext<String, ValueStatement, EffectiveStatement<String, ValueStatement>> ctx) {
+        public EffectiveStatement<Integer, ValueStatement> createEffective(
+                StmtContext<Integer, ValueStatement, EffectiveStatement<Integer, ValueStatement>> ctx) {
             return new ValueEffectiveStatementImpl(ctx);
         }
 
     }
 
     @Override
-    public String getValue() {
+    public Integer getValue() {
         return argument();
     }