/** * Convert a String to a Boolean. * null --> true * "" --> true * case insensitive "true" --> true * case insensitive "false" --> false * anything else --> throw Exception * * @param paramName the name of the param * @param s the String to convert * @return Boolean */ private static Boolean convertStringToBoolean(String paramName, String s) { if (!ok(s)) return Boolean.TRUE; if (s.equalsIgnoreCase(Boolean.TRUE.toString())) return Boolean.TRUE; if (s.equalsIgnoreCase(Boolean.FALSE.toString())) return Boolean.FALSE; String msg = localStrings.getLocalString("UnacceptableBooleanValue", "Invalid parameter: {0}. This boolean option must be set " + "(case insensitive) to true or false. " + "Its value was set to {1}", paramName, s); throw new UnacceptableValueException(msg); }
/** * Convert a String to a Boolean. * null --> true * "" --> true * case insensitive "true" --> true * case insensitive "false" --> false * anything else --> throw Exception * * @param paramName the name of the param * @param s the String to convert * @return Boolean */ private static Boolean convertStringToBoolean(String paramName, String s) { if (!ok(s)) return Boolean.TRUE; if (s.equalsIgnoreCase(Boolean.TRUE.toString())) return Boolean.TRUE; if (s.equalsIgnoreCase(Boolean.FALSE.toString())) return Boolean.FALSE; String msg = localStrings.getLocalString("UnacceptableBooleanValue", "Invalid parameter: {0}. This boolean option must be set " + "(case insensitive) to true or false. " + "Its value was set to {1}", paramName, s); throw new UnacceptableValueException(msg); }
/** * Convert a String to a Boolean. * null --> true * "" --> true * case insensitive "true" --> true * case insensitive "false" --> false * anything else --> throw Exception * * @param paramName the name of the param * @param s the String to convert * @return Boolean */ private static Boolean convertStringToBoolean(String paramName, String s) { if (!ok(s)) return Boolean.TRUE; if (s.equalsIgnoreCase(Boolean.TRUE.toString())) return Boolean.TRUE; if (s.equalsIgnoreCase(Boolean.FALSE.toString())) return Boolean.FALSE; String msg = localStrings.getLocalString("UnacceptableBooleanValue", "Invalid parameter: {0}. This boolean option must be set " + "(case insensitive) to true or false. " + "Its value was set to {1}", paramName, s); throw new UnacceptableValueException(msg); }
/** * Check if the value string is one of the strings in the list of * acceptable values in the @Param annotation on the target. * * @param target the target field * @param paramValueStr the parameter value */ private static void checkAgainstAcceptableValues(AnnotatedElement target, String paramValueStr) { Param param = target.getAnnotation(Param.class); String acceptable = param.acceptableValues(); String paramName = CommandModel.getParamName(param, target); if (ok(acceptable) && ok(paramValueStr)) { String[] ss = acceptable.split(","); for (String s : ss) { if (paramValueStr.equals(s.trim())) return; // matched, value is good } // didn't match any, error throw new UnacceptableValueException( localStrings.getLocalString("UnacceptableValue", "Invalid parameter: {0}. Its value is {1} " + "but it isn''t one of these acceptable values: {2}", paramName, paramValueStr, acceptable)); } }
/** * Check if the value string is one of the strings in the list od * acceptable values in the @Param annotation on the target. * * @param target the target field * @param paramValueStr the parameter value */ private static void checkAgainstAcceptableValues(AnnotatedElement target, String paramValueStr) { Param param = target.getAnnotation(Param.class); String acceptable = param.acceptableValues(); String paramName = CommandModel.getParamName(param, target); if (ok(acceptable) && ok(paramValueStr)) { String[] ss = acceptable.split(","); for (String s : ss) { if (paramValueStr.equals(s.trim())) return; // matched, value is good } // didn't match any, error throw new UnacceptableValueException( localStrings.getLocalString("UnacceptableValue", "Invalid parameter: {0}. Its value is {1} " + "but it isn''t one of these acceptable values: {2}", paramName, paramValueStr, acceptable)); } }
/** * Check if the value string is one of the strings in the list of * acceptable values in the @Param annotation on the target. * * @param target the target field * @param paramValueStr the parameter value */ private static void checkAgainstAcceptableValues(AnnotatedElement target, String paramValueStr) { Param param = target.getAnnotation(Param.class); String acceptable = param.acceptableValues(); String paramName = CommandModel.getParamName(param, target); if (ok(acceptable) && ok(paramValueStr)) { String[] ss = acceptable.split(","); for (String s : ss) { if (paramValueStr.equals(s.trim())) return; // matched, value is good } // didn't match any, error throw new UnacceptableValueException( localStrings.getLocalString("UnacceptableValue", "Invalid parameter: {0}. Its value is {1} " + "but it isn''t one of these acceptable values: {2}", paramName, paramValueStr, acceptable)); } }