View Javadoc
1   package org.csveed.bean;
2   
3   import java.util.Set;
4   
5   import org.csveed.api.Header;
6   import org.csveed.api.Row;
7   import org.csveed.common.Column;
8   import org.csveed.report.CsvException;
9   import org.csveed.report.RowError;
10  import org.slf4j.Logger;
11  import org.slf4j.LoggerFactory;
12  
13  public class ColumnNameMapper<T> extends AbstractMapper<T> {
14  
15      private static final Logger logger = LoggerFactory.getLogger(ColumnNameMapper.class);
16  
17      @Override
18      protected Set<Column> keys() {
19          return beanInstructions.getProperties().columnNameKeys();
20      }
21  
22      @Override
23      public BeanProperty getBeanProperty(Column column) {
24          return beanInstructions.getProperties().fromName(column);
25      }
26  
27      @Override
28      protected void checkKey(Header header, Column key) {
29          try {
30              header.getIndex(key.getColumnName());
31          } catch (CsvException e) {
32              logger.trace("", e);
33              throw new CsvException(new RowError(
34                      "The header row does not contain column \"" + key + "\". Originally mapped to property \"" +
35                              getBeanProperty(key).getPropertyName() + "\"",
36                      header.reportOnEndOfLine(), 0
37                      ));
38          }
39      }
40  
41      @Override
42      protected Column getColumn(Row row) {
43          return new Column().setHeader(row.getHeader());
44      }
45  
46  }