string issue fix for few yang construct like config, mandatory + allowing yang constructs as identifers and string

Change-Id: I8dd01dc60d280a843b0a485681caa6bfcac013c2
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index 41b2418..07c8105 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -21,6 +21,8 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.regex.Pattern;
+
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.utils.YangConstructType;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 
@@ -29,7 +31,11 @@
  */
 public final class ListenerUtil {
     private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
+    private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+";
     private static final String PLUS = "+";
+    private static final String ONE = "1";
+    private static final String TRUE_KEYWORD = "true";
+    private static final String FALSE_KEYWORD = "false";
     private static final int IDENTIFIER_LENGTH = 64;
 
     /**
@@ -109,4 +115,73 @@
 
         return true;
     }
+
+    /**
+     * Validates YANG version.
+     *
+     * @param ctx version context object of the grammar rule
+     * @return valid version
+     */
+    public static byte getValidVersion(GeneratedYangParser.YangVersionStatementContext ctx) {
+
+        String value = removeQuotesAndHandleConcat(ctx.version().getText());
+        if (!value.equals(ONE)) {
+            ParserException parserException = new ParserException("YANG file error: Input version not supported");
+            parserException.setLine(ctx.getStart().getLine());
+            parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+            throw parserException;
+        }
+
+        return Byte.valueOf(value);
+    }
+
+    /**
+     * Validates non negative integer value.
+     *
+     * @param integerValue integer to be validated
+     * @param yangConstruct yang construct for creating error message
+     * @param ctx context object of the grammar rule
+     * @return valid non negative integer value
+     */
+    public static int getValidNonNegativeIntegerValue(String integerValue, YangConstructType yangConstruct,
+                                           ParserRuleContext ctx) {
+
+        String value = removeQuotesAndHandleConcat(integerValue);
+        if (!value.matches(NON_NEGATIVE_INTEGER_PATTERN)) {
+            ParserException parserException = new ParserException("YANG file error : " +
+                    YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
+                    "valid.");
+            parserException.setLine(ctx.getStart().getLine());
+            parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+            throw parserException;
+        }
+
+        return Integer.parseInt(value);
+    }
+
+    /**
+     * Validates boolean value.
+     *
+     * @param booleanValue value to be validated
+     * @param yangConstruct yang construct for creating error message
+     * @param ctx context object of the grammar rule
+     * @return boolean value either true or false
+     */
+    public static boolean getValidBooleanValue(String booleanValue, YangConstructType yangConstruct,
+                                                ParserRuleContext ctx) {
+
+        String value = removeQuotesAndHandleConcat(booleanValue);
+        if (value.equals(TRUE_KEYWORD)) {
+            return true;
+        } else if (value.equals(FALSE_KEYWORD)) {
+            return false;
+        } else {
+            ParserException parserException = new ParserException("YANG file error : " +
+                    YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
+                    "valid.");
+            parserException.setLine(ctx.getStart().getLine());
+            parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+            throw parserException;
+        }
+    }
 }
\ No newline at end of file