package hirondelle.web4j.config;
import hirondelle.web4j.model.ConvertParamError;
import hirondelle.web4j.model.Decimal;
import hirondelle.web4j.model.ModelCtorException;
import hirondelle.web4j.request.RequestParameter;
import hirondelle.web4j.security.SafeText;
import java.math.BigDecimal;
import java.util.Locale;
import java.util.TimeZone;
public final class ConvertParamErrorImpl implements ConvertParamError {
public ModelCtorException get(Class<?> aTargetClass, String aUserInputValue, RequestParameter aRequestParameter){
String errorMessagePattern = getPatternAsFixedString(aTargetClass);
ModelCtorException result = new ModelCtorException();
if( SafeText.class == aTargetClass) {
Object[] params = { aRequestParameter };
result.add(errorMessagePattern, params);
}
else {
Object[] params = { aRequestParameter, aUserInputValue };
result.add(errorMessagePattern, params);
}
return result;
}
private String getPatternAsFixedString(Class<?> aTargetClass){
String result = null;
if ( BigDecimal.class == aTargetClass || Decimal.class == aTargetClass ) {
result = "_1_ is not in the expected format/range : '_2_'";
}
else if ( Integer.class == aTargetClass ) {
result = "_1_ is not an integer : '_2_'";
}
else if ( hirondelle.web4j.model.DateTime.class == aTargetClass ) {
result = "_1_ is not in the expected date format 'YYYYMMDD' : '_2_'";
}
else if ( SafeText.class == aTargetClass ) {
result = "_1_ contains unpermitted character(s)"; }
else if ( TimeZone.class == aTargetClass ) {
result = "_1_ is not a valid Time Zone identifier: '_2_'";
}
else if ( Locale.class == aTargetClass ) {
result = "_1_ is not a valid Locale identifier: '_2_'";
}
else {
throw new AssertionError("Unexpected case for target base class: " + aTargetClass);
}
return result;
}
}