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 Object
implements ItemProcessor<T,T>, org.springframework.beans.factory.InitializingBean
Simple implementation of
ItemProcessor
that validates input and returns it
without modifications. Should the given Validator
throw a
ValidationException
this processor will re-throw it to indicate the item should
be skipped, unless setFilter(boolean)
is set to true
, in which
case null
will be returned to indicate the item should be filtered.- Author:
- Robert Kasanicky
-
Constructor Summary
ConstructorDescriptionDefault constructorValidatingItemProcessor
(Validator<? super T> validator) Creates a ValidatingItemProcessor based on the given Validator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Validate the item and return it unmodifiedvoid
setFilter
(boolean filter) Should the processor filter invalid records instead of skipping them?void
setValidator
(Validator<? super T> validator) Set the validator used to validate each item.
-
Constructor Details
-
ValidatingItemProcessor
public ValidatingItemProcessor()Default constructor -
ValidatingItemProcessor
Creates a ValidatingItemProcessor based on the given Validator.- Parameters:
validator
- theValidator
instance to be used.
-
-
Method Details
-
setValidator
Set the validator used to validate each item.- Parameters:
validator
- theValidator
instance 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 (null
is returned). Otherwise, aValidationException
will be thrown.
-
process
Validate the item and return it unmodified- Specified by:
process
in interfaceItemProcessor<T,
T> - Parameters:
item
- to be processed, nevernull
.- Returns:
- the input item
- Throws:
ValidationException
- if validation fails
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-