public static boolean parseSetValue()

in kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptions.java [43:87]


    public static boolean parseSetValue(KOptionInfo kopt, String strValue) {
        KOptionType kt = kopt.getType();
        if (kt == KOptionType.NOV) {
            return true; // no need of a value
        }
        if (strValue == null || strValue.isEmpty()) {
            return false;
        }

        if (kt == KOptionType.FILE) {
            // May check file sanity
            kopt.setValue(new File(strValue));
        } else if (kt == KOptionType.DIR) {
            File dir = new File(strValue);
            if (!dir.exists()) {
                throw new IllegalArgumentException("Invalid dir:" + strValue);
            }
            kopt.setValue(dir);
        } else if (kt == KOptionType.INT) {
            try {
                Integer num = Integer.valueOf(strValue);
                kopt.setValue(num);
            } catch (NumberFormatException nfe) {
                throw new IllegalArgumentException("Invalid integer:" + strValue);
            }
        } else if (kt == KOptionType.STR) {
            kopt.setValue(strValue);
        } else if (kt == KOptionType.DATE) {
            DateFormat df = new SimpleDateFormat("dd/MM/yy:HH:mm:ss", Locale.US);
            Date date = null;
            try {
                date = df.parse(strValue);
                kopt.setValue(date);
            } catch (ParseException e) {
                throw new IllegalArgumentException("Fail to parse the date: " + strValue);
            }
        } else if (kt == KOptionType.DURATION) {
            kopt.setValue(parseDuration(strValue));
        } else if (kt == KOptionType.BOOL) {
            kopt.setValue(Boolean.valueOf(strValue));
        } else {
            throw new IllegalArgumentException("Not recognised option:" + strValue);
        }
        return true;
    }