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