Current ParameterHelper has complex typeToString() and stringToType() functions.
The proposed patch for simplifying this behaviour:
Index: main/kernel/src/org/ametys/runtime/util/parameter/ParameterHelper.java =================================================================== --- main/kernel/src/org/ametys/runtime/util/parameter/ParameterHelper.java (revision 504) +++ main/kernel/src/org/ametys/runtime/util/parameter/ParameterHelper.java (working copy) @@ -42,29 +42,9 @@ /** binary values */ BINARY } - /** Constants to type values as string : boolean */ - public static final String TYPE_BOOLEAN_LABEL = "boolean"; - - /** Constants to type values as string : string */ - public static final String TYPE_STRING_LABEL = "string"; - - /** Constants to type values as string : password */ - public static final String TYPE_PASSWORD_LABEL = "password"; - - /** Constants to type values as string : long */ - public static final String TYPE_LONG_LABEL = "long"; - - /** Constants to type values as string : double */ - public static final String TYPE_DOUBLE_LABEL = "double"; - - /** Constants to type values as string : date */ - public static final String TYPE_DATE_LABEL = "date"; /** Constants to set date format */ public static final String TYPE_DATE_TYPE = "yyyy-MM-dd'T'HH:mm"; - - /** Constants to type values as string : binary */ - public static final String TYPE_BINARY_LABEL = "binary"; // Logger for traces private static Logger _logger = LoggerFactory.getLoggerFor(ParameterHelper.class); @@ -83,38 +63,7 @@ */ public static String typeToString(TYPE type) { - if (type == TYPE.BOOLEAN) - { - return TYPE_BOOLEAN_LABEL; - } - else if (type == TYPE.DATE) - { - return TYPE_DATE_LABEL; - } - else if (type == TYPE.DOUBLE) - { - return TYPE_DOUBLE_LABEL; - } - else if (type == TYPE.LONG) - { - return TYPE_LONG_LABEL; - } - else if (type == TYPE.STRING) - { - return TYPE_STRING_LABEL; - } - else if (type == TYPE.PASSWORD) - { - return TYPE_PASSWORD_LABEL; - } - else if (type == TYPE.BINARY) - { - return TYPE_BINARY_LABEL; - } - else - { - throw new IllegalArgumentException("The value '" + type + "' is unknown for a config parameter type"); - } + return type.name().toLowerCase(); } /** @@ -126,35 +75,11 @@ */ public static TYPE stringToType(String type) { - if (TYPE_BOOLEAN_LABEL.equalsIgnoreCase(type)) - { - return TYPE.BOOLEAN; - } - else if (TYPE_STRING_LABEL.equalsIgnoreCase(type)) - { - return TYPE.STRING; - } - else if (TYPE_PASSWORD_LABEL.equalsIgnoreCase(type)) - { - return TYPE.PASSWORD; - } - else if (TYPE_LONG_LABEL.equalsIgnoreCase(type)) - { - return TYPE.LONG; - } - else if (TYPE_DOUBLE_LABEL.equalsIgnoreCase(type)) - { - return TYPE.DOUBLE; - } - else if (TYPE_DATE_LABEL.equalsIgnoreCase(type)) - { - return TYPE.DATE; - } - else if (TYPE_BINARY_LABEL.equalsIgnoreCase(type)) + try { - return TYPE.BINARY; + return TYPE.valueOf(type.toUpperCase()); } - else + catch (IllegalArgumentException e) { throw new IllegalArgumentException("The type '" + type + "' is unknown for config parameters"); } @@ -205,10 +130,6 @@ { return null; } - else - { - return null; - } } catch (Exception nfe) { @@ -220,8 +141,8 @@ { _logger.debug("Failed to cast empty string to type '" + typeToString(type) + "'. Null object will be used.", nfe); } - return null; } + return null; }