RESOLVED - issue BATCH-779: RFC: make FieldSetMapper and LineAggregator extend ItemProcessor
http://jira.springframework.org/browse/BATCH-779 Updated FieldSetMapper interface method to mapFieldSet from simply map, in order to be more consistent with other *Mapper implementations.
This commit is contained in:
@@ -102,7 +102,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
|
||||
/**
|
||||
* The bean name (id) for an object that can be populated from the field set
|
||||
* that will be passed into {@link #map(FieldSet)}. Typically a
|
||||
* that will be passed into {@link #mapFieldSet(FieldSet)}. Typically a
|
||||
* prototype scoped bean so that a new instance is returned for each field
|
||||
* set mapped.
|
||||
*
|
||||
@@ -118,7 +118,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
/**
|
||||
* Public setter for the type of bean to create instead of using a prototype
|
||||
* bean. An object of this type will be created from its default constructor
|
||||
* for every call to {@link #map(FieldSet)}.<br/>
|
||||
* for every call to {@link #mapFieldSet(FieldSet)}.<br/>
|
||||
*
|
||||
* Either this property or the prototype bean name must be specified, but
|
||||
* not both.
|
||||
@@ -153,10 +153,10 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
* the {@link DataBinder} from {@link #createBinder(Object)} has errors
|
||||
* after binding).
|
||||
*
|
||||
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#map(FieldSet)
|
||||
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(FieldSet)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T map(FieldSet fs) {
|
||||
public T mapFieldSet(FieldSet fs) {
|
||||
T copy = getBean();
|
||||
DataBinder binder = createBinder(copy);
|
||||
binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties())));
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DefaultLineMapper<T> implements LineMapper<T> {
|
||||
private FieldSetMapper<T> fieldSetMapper;
|
||||
|
||||
public T mapLine(String line, int lineNumber) throws Exception {
|
||||
return fieldSetMapper.map(tokenizer.tokenize(line));
|
||||
return fieldSetMapper.mapFieldSet(tokenizer.tokenize(line));
|
||||
}
|
||||
|
||||
public void setLineTokenizer(LineTokenizer tokenizer) {
|
||||
|
||||
@@ -33,5 +33,5 @@ public interface FieldSetMapper<T> {
|
||||
*
|
||||
* @param fieldSet the {@link FieldSet} to map
|
||||
*/
|
||||
T map(FieldSet fieldSet);
|
||||
T mapFieldSet(FieldSet fieldSet);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PassThroughFieldSetMapper implements FieldSetMapper<FieldSet> {
|
||||
* org.springframework.batch.item.file.FieldSetMapper#mapLine(org.springframework
|
||||
* .batch.io.file.FieldSet)
|
||||
*/
|
||||
public FieldSet map(FieldSet fs) {
|
||||
public FieldSet mapFieldSet(FieldSet fs) {
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
|
||||
new String[] { "varString", "varBoolean", "varChar" });
|
||||
TestObject result = mapper.map(fieldSet);
|
||||
TestObject result = mapper.mapFieldSet(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
assertEquals(true, result.isVarBoolean());
|
||||
assertEquals('C', result.getVarChar());
|
||||
@@ -78,7 +78,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
|
||||
new String[] { "varString", "varBoolean", "varChar" });
|
||||
TestObject result = mapper.map(fieldSet);
|
||||
TestObject result = mapper.mapFieldSet(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
assertEquals(true, result.isVarBoolean());
|
||||
assertEquals('C', result.getVarChar());
|
||||
@@ -93,7 +93,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
|
||||
new String[] { "VarString", "VAR_BOOLEAN", "VAR_CHAR" });
|
||||
TestObject result = mapper.map(fieldSet);
|
||||
TestObject result = mapper.mapFieldSet(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
assertEquals(true, result.isVarBoolean());
|
||||
assertEquals('C', result.getVarChar());
|
||||
@@ -107,7 +107,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
|
||||
new String[] { "varString", "varBoolean", "varChar" });
|
||||
TestObject result = mapper.map(fieldSet);
|
||||
TestObject result = mapper.mapFieldSet(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
assertEquals(true, result.isVarBoolean());
|
||||
assertEquals('C', result.getVarChar());
|
||||
@@ -130,7 +130,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
new String[] { "This is some dummy string", "1", "Another dummy", "2" }, new String[] { "valueA",
|
||||
"valueB", "testObjectB.valueA", "testObjectB.testObjectC.value" });
|
||||
|
||||
TestNestedA result = mapper.map(fieldSet);
|
||||
TestNestedA result = mapper.mapFieldSet(fieldSet);
|
||||
|
||||
assertEquals("This is some dummy string", result.getValueA());
|
||||
assertEquals(1, result.getValueB());
|
||||
@@ -150,7 +150,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "1" }, new String[] {
|
||||
"VALUE_A", "VALUE_B" });
|
||||
|
||||
TestNestedA result = (TestNestedA) mapper.map(fieldSet);
|
||||
TestNestedA result = (TestNestedA) mapper.mapFieldSet(fieldSet);
|
||||
|
||||
assertEquals("This is some dummy string", result.getValueA());
|
||||
assertEquals(1, result.getValueB());
|
||||
@@ -167,7 +167,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1" }, new String[] { "foo" });
|
||||
|
||||
TestNestedC result = mapper.map(fieldSet);
|
||||
TestNestedC result = mapper.mapFieldSet(fieldSet);
|
||||
|
||||
// "foo" is similar enough to "value" that it matches - but only because
|
||||
// nothing else does...
|
||||
@@ -189,7 +189,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy", "2" }, new String[] {
|
||||
"TestObjectB.ValueA", "TestObjectB.TestObjectC.Value" });
|
||||
|
||||
TestNestedA result = mapper.map(fieldSet);
|
||||
TestNestedA result = mapper.mapFieldSet(fieldSet);
|
||||
|
||||
assertEquals("Another dummy", result.getTestObjectB().getValueA());
|
||||
assertEquals(2, result.getTestObjectB().getTestObjectC().getValue());
|
||||
@@ -209,7 +209,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy" }, new String[] { "TestObjectB.foo" });
|
||||
|
||||
try {
|
||||
mapper.map(fieldSet);
|
||||
mapper.mapFieldSet(fieldSet);
|
||||
fail("Expected NotWritablePropertyException");
|
||||
}
|
||||
catch (NotWritablePropertyException e) {
|
||||
@@ -231,7 +231,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "2" }, new String[] { "TestObjectA.garbage" });
|
||||
|
||||
try {
|
||||
mapper.map(fieldSet);
|
||||
mapper.mapFieldSet(fieldSet);
|
||||
fail("Expected NotWritablePropertyException");
|
||||
}
|
||||
catch (NotWritablePropertyException e) {
|
||||
@@ -271,7 +271,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1", "2", "3" }, new String[] { "NestedC[0].Value",
|
||||
"NestedC[1].Value", "NestedC[2].Value" });
|
||||
|
||||
mapper.map(fieldSet);
|
||||
mapper.mapFieldSet(fieldSet);
|
||||
|
||||
assertEquals(1, ((TestNestedC) nestedList.getNestedC().get(0)).getValue());
|
||||
assertEquals(2, ((TestNestedC) nestedList.getNestedC().get(1)).getValue());
|
||||
@@ -285,7 +285,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
mapper.setTargetType(TestObject.class);
|
||||
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
|
||||
TestObject bean = (TestObject) mapper.map(fieldSet);
|
||||
TestObject bean = (TestObject) mapper.mapFieldSet(fieldSet);
|
||||
// since Spring 2.5.5 this is OK (before that BATCH-261)
|
||||
assertEquals(9, bean.getVarLong());
|
||||
}
|
||||
@@ -299,7 +299,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
|
||||
.getNumberInstance(), true)));
|
||||
TestObject bean = (TestObject) mapper.map(fieldSet);
|
||||
TestObject bean = (TestObject) mapper.mapFieldSet(fieldSet);
|
||||
|
||||
assertEquals(9, bean.getVarLong());
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
|
||||
.getNumberInstance(), true)));
|
||||
TestObject bean = (TestObject) mapper.map(fieldSet);
|
||||
TestObject bean = (TestObject) mapper.mapFieldSet(fieldSet);
|
||||
|
||||
assertEquals(9, bean.getVarLong());
|
||||
assertEquals(78, bean.getVarInt());
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DefaultLineMapperTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
FieldSetMapper<String> fsMapper = createStrictMock(FieldSetMapper.class);
|
||||
expect(fsMapper.map(fs)).andReturn(item);
|
||||
expect(fsMapper.mapFieldSet(fs)).andReturn(item);
|
||||
replay(fsMapper);
|
||||
|
||||
tested.setLineTokenizer(tokenizer);
|
||||
|
||||
@@ -27,11 +27,11 @@ public class PassThroughFieldSetMapperTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#map(org.springframework.batch.item.file.mapping.FieldSet)}.
|
||||
* {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapFieldSet(org.springframework.batch.item.file.mapping.FieldSet)}.
|
||||
*/
|
||||
public void testMapLine() {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" });
|
||||
assertEquals(fieldSet, mapper.map(fieldSet));
|
||||
assertEquals(fieldSet, mapper.mapFieldSet(fieldSet));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public abstract class AbstractTradeBatchTests extends TestCase {
|
||||
}
|
||||
|
||||
protected static class TradeMapper implements FieldSetMapper<Trade> {
|
||||
public Trade map(FieldSet fs) {
|
||||
public Trade mapFieldSet(FieldSet fs) {
|
||||
return new Trade(fs);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user