RESOLVED - BATCH-779: RFC: make FieldSetMapper and LineAggregator extend ItemProcessor
reverted to original method names
This commit is contained in:
@@ -189,7 +189,7 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
|
||||
StringBuilder lines = new StringBuilder();
|
||||
int lineCount = 0;
|
||||
for (T item : items) {
|
||||
lines.append(lineAggregator.process(item) + lineSeparator);
|
||||
lines.append(lineAggregator.aggregate(item) + lineSeparator);
|
||||
lineCount++;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -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 #process(FieldSet)}. Typically a
|
||||
* that will be passed into {@link #map(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 #process(FieldSet)}.<br/>
|
||||
* for every call to {@link #map(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#process(FieldSet)
|
||||
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#map(FieldSet)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T process(FieldSet fs) {
|
||||
public T map(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.process(tokenizer.process(line));
|
||||
return fieldSetMapper.map(tokenizer.tokenize(line));
|
||||
}
|
||||
|
||||
public void setLineTokenizer(LineTokenizer tokenizer) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.batch.item.file.mapping;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface that is used to map data obtained from a {@link FieldSet} into an
|
||||
* object.
|
||||
@@ -27,5 +28,10 @@ package org.springframework.batch.item.file.mapping;
|
||||
*/
|
||||
public interface FieldSetMapper<T> {
|
||||
|
||||
T process(FieldSet fieldSet);
|
||||
/**
|
||||
* Method used to map data obtained from a {@link FieldSet} into an object.
|
||||
*
|
||||
* @param fieldSet the {@link FieldSet} to map
|
||||
*/
|
||||
T map(FieldSet fieldSet);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PassThroughFieldSetMapper implements FieldSetMapper<FieldSet> {
|
||||
* org.springframework.batch.io.file.FieldSetMapper#mapLine(org.springframework
|
||||
* .batch.io.file.FieldSet)
|
||||
*/
|
||||
public FieldSet process(FieldSet fs) {
|
||||
public FieldSet map(FieldSet fs) {
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public abstract class AbstractLineTokenizer implements LineTokenizer {
|
||||
*
|
||||
* @return the resulting tokens
|
||||
*/
|
||||
public FieldSet process(String line) {
|
||||
public FieldSet tokenize(String line) {
|
||||
|
||||
if(line == null){
|
||||
line = "";
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DelimitedLineAggregator<T> implements LineAggregator<T[]> {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
|
||||
*/
|
||||
public String process(T[] item) {
|
||||
public String aggregate(T[] item) {
|
||||
return StringUtils.arrayToDelimitedString(item, delimiter);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ public class FormatterLineAggregator<T> implements LineAggregator<T> {
|
||||
* @param item data to be aggregated
|
||||
* @return aggregated string
|
||||
*/
|
||||
public String process(T item) {
|
||||
public String aggregate(T item) {
|
||||
|
||||
Assert.notNull(item);
|
||||
Assert.notNull(format);
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.batch.item.file.transform;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface used to create string representing object.
|
||||
*
|
||||
@@ -26,5 +23,11 @@ package org.springframework.batch.item.file.transform;
|
||||
*/
|
||||
public interface LineAggregator<T> {
|
||||
|
||||
String process(T item);
|
||||
/**
|
||||
* Create a string from the value provided.
|
||||
*
|
||||
* @param item values to be converted
|
||||
* @return string
|
||||
*/
|
||||
String aggregate(T item);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.batch.item.file.transform;
|
||||
|
||||
import org.springframework.batch.item.file.mapping.FieldSet;
|
||||
|
||||
|
||||
/**
|
||||
* Interface that is used by framework to split string obtained typically from a
|
||||
* file into tokens.
|
||||
@@ -28,5 +27,13 @@ import org.springframework.batch.item.file.mapping.FieldSet;
|
||||
*/
|
||||
public interface LineTokenizer {
|
||||
|
||||
FieldSet process(String line);
|
||||
/**
|
||||
* Yields the tokens resulting from the splitting of the supplied
|
||||
* <code>line</code>.
|
||||
*
|
||||
* @param line the line to be tokenized (can be <code>null</code>)
|
||||
*
|
||||
* @return the resulting tokens
|
||||
*/
|
||||
FieldSet tokenize(String line);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ public class PassThroughLineAggregator<T> implements LineAggregator<T> {
|
||||
/**
|
||||
* Simply convert to a String with toString().
|
||||
*
|
||||
* @see org.springframework.batch.item.file.transform.LineAggregator#process(java.lang.Object)
|
||||
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
|
||||
*/
|
||||
public String process(T item) {
|
||||
public String aggregate(T item) {
|
||||
return item.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PrefixMatchingCompositeLineTokenizer implements LineTokenizer {
|
||||
this.tokenizers = new LinkedHashMap<String, LineTokenizer>(tokenizers);
|
||||
}
|
||||
|
||||
public FieldSet process(String line) {
|
||||
public FieldSet tokenize(String line) {
|
||||
|
||||
if (line == null) {
|
||||
return new DefaultFieldSet(new String[0]);
|
||||
@@ -61,7 +61,7 @@ public class PrefixMatchingCompositeLineTokenizer implements LineTokenizer {
|
||||
throw new IllegalStateException("Could not match record to tokenizer for line=[" + line + "]");
|
||||
}
|
||||
|
||||
return tokenizer.process(line);
|
||||
return tokenizer.tokenize(line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ public class RecursiveCollectionLineAggregator<T> implements LineAggregator<Coll
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
|
||||
*/
|
||||
public String process(Collection<T> items) {
|
||||
public String aggregate(Collection<T> items) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (T value : items) {
|
||||
builder.append(delegate.process(value) + LINE_SEPARATOR);
|
||||
builder.append(delegate.aggregate(value) + LINE_SEPARATOR);
|
||||
}
|
||||
return builder.delete(builder.length()-LINE_SEPARATOR.length(),builder.length()).toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user