mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-2923 adds better support for generics
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1428071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+14
-8
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.validator.validators;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.validator.ValidationException;
|
||||
|
||||
|
||||
@@ -26,6 +27,12 @@ import com.opensymphony.xwork2.validator.ValidationException;
|
||||
*/
|
||||
public abstract class AbstractRangeValidator<T extends Comparable> extends FieldValidatorSupport {
|
||||
|
||||
private final Class<T> type;
|
||||
|
||||
protected AbstractRangeValidator(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void validate(Object object) throws ValidationException {
|
||||
Object obj = getFieldValue(getFieldName(), object);
|
||||
Comparable<T> value = (Comparable<T>) obj;
|
||||
@@ -49,16 +56,15 @@ public abstract class AbstractRangeValidator<T extends Comparable> extends Field
|
||||
}
|
||||
}
|
||||
|
||||
protected T parse(String expression) {
|
||||
if (expression == null) {
|
||||
return null;
|
||||
}
|
||||
return (T) TextParseUtil.translateVariables('$', expression, stack, type);
|
||||
}
|
||||
|
||||
protected abstract T getMaxComparatorValue();
|
||||
|
||||
protected abstract T getMinComparatorValue();
|
||||
|
||||
protected String safeConditionalParse(String expression) {
|
||||
Object value = conditionalParse(expression);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user