Off the top of my head: you could use an item transformer and a custom exception with a skip policy.
Code:
public abstract class FilteringItemTransformer implements ItemTransformer {
protected abstract boolean accept(Object item);
public Object transform(Object item) {
if( ! accept( item ) ) {
throw new ItemFilterException( item );
}
return item;
}
}
public class ItemFilterException extends RuntimeException {
/**
* Generated
*/
public static final Long serialVersionUID = -35153205L;
private Object item;
public ItemFilterException(Object item) {
this.item = item;
}
}
Then all you need is to configure your step with an ItemTransformerItemWriter using that transformer and your desired writer as its delegate.
Then just configure ItemFilterException as a skippable exception...
An alternate solution would be to change the ItemTransformerItemWriter (or create an alternate version) to not continue to the "write" phase if the returned transformed value is null - then the above-mentioned transformer looks like this:
Code:
public abstract class FilteringItemTransformer implements ItemTransformer {
protected abstract boolean accept(Object item);
public Object transform(Object item) {
if( ! accept( item ) ) {
return null;
}
return item;
}
}
This way a separate exception / skippable policy is not required.
Created a JIRA issue --
http://jira.springframework.org/browse/BATCH-581