BATCH-1906: add support to access an item's line number

This commit is contained in:
jpraet
2013-03-03 19:04:12 +01:00
committed by Michael Minella
parent cb27354e75
commit 6e7b290727
4 changed files with 202 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
package org.springframework.batch.item;
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
/**
* Marker interface indicating that an item should have the item count set on it. Typically used within
* an {@link AbstractItemCountingItemStreamItemReader}.
*
* @author Jimmy Praet
*/
public interface ItemCountAware {
void setItemCount(int count);
}

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.item.support;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemCountAware;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ParseException;
@@ -79,7 +80,11 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
return null;
}
currentItemCount++;
return doRead();
T item = doRead();
if(item instanceof ItemCountAware) {
((ItemCountAware) item).setItemCount(currentItemCount);
}
return item;
}
protected int getCurrentItemCount() {