Class ValidatingItemProcessor<T>
- java.lang.Object
- org.springframework.batch.item.validator.ValidatingItemProcessor<T>
- All Implemented Interfaces:
ItemProcessor<T,T>,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
BeanValidatingItemProcessor
public class ValidatingItemProcessor<T> extends java.lang.Object implements ItemProcessor<T,T>, org.springframework.beans.factory.InitializingBean
Simple implementation ofItemProcessorthat validates input and returns it without modifications. Should the givenValidatorthrow aValidationExceptionthis processor will re-throw it to indicate the item should be skipped, unlesssetFilter(boolean)is set totrue, in which casenullwill be returned to indicate the item should be filtered.- Author:
- Robert Kasanicky
Constructor Summary
Constructors Constructor Description ValidatingItemProcessor()Default constructorValidatingItemProcessor(Validator<? super T> validator)Creates a ValidatingItemProcessor based on the given Validator.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Tprocess(T item)Validate the item and return it unmodifiedvoidsetFilter(boolean filter)Should the processor filter invalid records instead of skipping them?voidsetValidator(Validator<? super T> validator)Set the validator used to validate each item.
Method Detail
setValidator
public void setValidator(Validator<? super T> validator)
Set the validator used to validate each item.- Parameters:
validator- theValidatorinstance to be used.
setFilter
public void setFilter(boolean filter)
Should the processor filter invalid records instead of skipping them?- Parameters:
filter- if set totrue, items that fail validation are filtered (nullis returned). Otherwise, aValidationExceptionwill be thrown.
process
public T process(T item) throws ValidationException
Validate the item and return it unmodified- Specified by:
processin interfaceItemProcessor<T,T>- Parameters:
item- to be processed- Returns:
- the input item
- Throws:
ValidationException- if validation fails
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception