RESOLVED: BATCH-1175 Genricise Validator
This commit is contained in:
@@ -30,14 +30,14 @@ import org.springframework.validation.Errors;
|
||||
* @author Tomas Slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class SpringValidator implements Validator, InitializingBean {
|
||||
public class SpringValidator<T> implements Validator<T>, InitializingBean {
|
||||
|
||||
private org.springframework.validation.Validator validator;
|
||||
|
||||
/**
|
||||
* @see Validator#validate(Object)
|
||||
*/
|
||||
public void validate(Object item) throws ValidationException {
|
||||
public void validate(T item) throws ValidationException {
|
||||
|
||||
if (!validator.supports(item.getClass())) {
|
||||
throw new ValidationException("Validation failed for " + item + ": " + item.getClass().getName()
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ValidatingItemProcessor<T> implements ItemProcessor<T, T> {
|
||||
|
||||
private Validator validator;
|
||||
private Validator<? super T> validator;
|
||||
|
||||
public ValidatingItemProcessor(Validator validator){
|
||||
public ValidatingItemProcessor(Validator<? super T> validator){
|
||||
Assert.notNull(validator, "Validator must not be null.");
|
||||
this.validator = validator;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class ValidatingItemProcessor<T> implements ItemProcessor<T, T> {
|
||||
*
|
||||
* @param validator
|
||||
*/
|
||||
public void setValidator(Validator validator) {
|
||||
public void setValidator(Validator<? super T> validator) {
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ package org.springframework.batch.item.validator;
|
||||
* @author tomas.slanina
|
||||
*
|
||||
*/
|
||||
public interface Validator {
|
||||
public interface Validator<T> {
|
||||
/**
|
||||
* Method used to validate if the value is valid.
|
||||
*
|
||||
* @param value object to be validated
|
||||
* @throws ValidationException if value is not valid.
|
||||
*/
|
||||
void validate(Object value) throws ValidationException;
|
||||
void validate(T value) throws ValidationException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user