RESOLVED: BATCH-1175 Genricise Validator

This commit is contained in:
dsyer
2009-03-24 17:18:42 +00:00
parent 56de18f884
commit 11b8acc989
4 changed files with 15 additions and 10 deletions

View File

@@ -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()

View File

@@ -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;
}

View File

@@ -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;
}