All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sourcegroove.batch.item.file.excel.ExcelRowMapper Maven / Gradle / Ivy

There is a newer version: 1.3.21
Show newest version
package com.github.sourcegroove.batch.item.file.excel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;

import java.util.List;

public class ExcelRowMapper {
    protected final Log log = LogFactory.getLog(getClass());

    private ExcelRowTokenizer rowTokenizer;
    private FieldSetMapper fieldSetMapper;

    public void setRowTokenizer(ExcelRowTokenizer rowTokenizer) {
        this.rowTokenizer = rowTokenizer;
    }
    public void setFieldSetMapper(FieldSetMapper fieldSetMapper) {
        this.fieldSetMapper = fieldSetMapper;
    }

    public T mapRow(List row, int rowNumber)  {
        log.trace("Mapping row " + rowNumber + " with " + row.size() + " values");
        FieldSet fieldSet = this.rowTokenizer.tokenize(row, rowNumber);
        try {
            return this.fieldSetMapper.mapFieldSet(fieldSet);
        } catch (BindException e) {
            throw new RuntimeException("Error mapping fieldset at row " + rowNumber, e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy