Bug 7051 - moving of SubstatementValidator into spi.meta package
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / PositionStatementImpl.java
index 9496c69b751b2ee27afd946eb9202c3afb709bf0..213d31738763d9fba77080308f764c4e78d5e3f8 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -7,53 +7,60 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
-
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
 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.spi.meta.SubstatementValidator;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
 
-public class PositionStatementImpl extends AbstractDeclaredStatement<String>
-        implements PositionStatement {
+public class PositionStatementImpl extends AbstractDeclaredStatement<Long> implements PositionStatement {
+    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
+        YangStmtMapping.POSITION).build();
 
-    protected PositionStatementImpl(
-            StmtContext<String, PositionStatement, ?> context) {
+    protected PositionStatementImpl(final StmtContext<Long, PositionStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition
-            extends
-            AbstractStatementSupport<String, PositionStatement, EffectiveStatement<String, PositionStatement>> {
+    public static class Definition extends AbstractStatementSupport<Long, PositionStatement,
+            EffectiveStatement<Long, PositionStatement>> {
 
         public Definition() {
-            super(Rfc6020Mapping.POSITION);
+            super(YangStmtMapping.POSITION);
         }
 
         @Override
-        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
-            return value;
+        public Long parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+            try {
+                return Long.parseLong(value);
+            } catch (NumberFormatException e) {
+                throw new SourceException(String.format("Bit position value %s is not valid integer", value),
+                        ctx.getStatementSourceReference(), e);
+            }
         }
 
         @Override
-        public PositionStatement createDeclared(
-                StmtContext<String, PositionStatement, ?> ctx) {
+        public PositionStatement createDeclared(final StmtContext<Long, PositionStatement, ?> ctx) {
             return new PositionStatementImpl(ctx);
         }
 
         @Override
-        public EffectiveStatement<String, PositionStatement> createEffective(
-                StmtContext<String, PositionStatement, EffectiveStatement<String, PositionStatement>> ctx) {
+        public EffectiveStatement<Long, PositionStatement> createEffective(
+                final StmtContext<Long, PositionStatement, EffectiveStatement<Long, PositionStatement>> ctx) {
             return new PositionEffectiveStatementImpl(ctx);
         }
 
+        @Override
+        protected SubstatementValidator getSubstatementValidator() {
+            return SUBSTATEMENT_VALIDATOR;
+        }
     }
 
     @Override
-    public String getValue() {
+    public long getValue() {
         return argument();
     }
-
 }