protected Object parse()

in hugegraph-common/src/main/java/org/apache/hugegraph/config/TypedOption.java [125:158]


    protected Object parse(String value, Class<?> dataType) {
        if (dataType.equals(String.class)) {
            return value;
        } else if (dataType.equals(Class.class)) {
            try {
                if (value.startsWith("class")) {
                    value = value.substring("class".length()).trim();
                }
                return Class.forName(value);
            } catch (ClassNotFoundException e) {
                throw new ConfigException(
                          "Failed to parse Class from String '%s'", e, value);
            }
        } else if (List.class.isAssignableFrom(dataType)) {
            E.checkState(this.forList(),
                         "List option can't be registered with class %s",
                         this.getClass().getSimpleName());
        }

        // Use PropertyConverter method `toXXX` convert value
        String methodTo = "to" + dataType.getSimpleName();
        try {
            Method method = PropertyConverter.class.getMethod(
                            methodTo, Object.class);
            return method.invoke(null, value);
        } catch (ReflectiveOperationException e) {
            LOG.error("Invalid type of value '{}' for option '{}'",
                      value, this.name, e);
            throw new ConfigException(
                      "Invalid type of value '%s' for option '%s', " +
                      "expect '%s' type",
                      value, this.name, dataType.getSimpleName());
        }
    }