SavingWorkObject.java

  1. package com.gh.mygreen.xlsmapper;

  2. import java.util.ArrayList;
  3. import java.util.List;

  4. import org.apache.poi.ss.usermodel.Cell;

  5. import com.gh.mygreen.xlsmapper.cellconverter.TypeBindException;
  6. import com.gh.mygreen.xlsmapper.util.CellPosition;
  7. import com.gh.mygreen.xlsmapper.validation.SheetBindingErrors;
  8. import com.gh.mygreen.xlsmapper.xml.AnnotationReader;

  9. /**
  10.  * 書き込み処理中で持ち回すオブジェクトを保持するクラス。
  11.  *
  12.  */
  13. public class SavingWorkObject {
  14.    
  15.     private AnnotationReader annoReader;
  16.    
  17.     private final List<NeedProcess> needPostProcesses = new ArrayList<>();
  18.    
  19.     private SheetBindingErrors<?> errors;
  20.    
  21.     public AnnotationReader getAnnoReader() {
  22.         return annoReader;
  23.     }
  24.    
  25.     public void setAnnoReader(AnnotationReader annoReader) {
  26.         this.annoReader = annoReader;
  27.     }
  28.    
  29.     public void addNeedPostProcess(NeedProcess needProcess) {
  30.         this.needPostProcesses.add(needProcess);
  31.     }
  32.    
  33.     public List<NeedProcess> getNeedPostProcesses() {
  34.         return needPostProcesses;
  35.     }
  36.    
  37.     public SheetBindingErrors<?> getErrors() {
  38.         return errors;
  39.     }
  40.    
  41.     public void setErrors(SheetBindingErrors<?> errors) {
  42.         this.errors = errors;
  43.     }
  44.    
  45.     /**
  46.      * 型変換エラーを追加します。
  47.      * @param bindException 型変換エラー
  48.      * @param cell マッピング元となったセル
  49.      * @param fieldName マッピング先のフィールド名
  50.      * @param label ラベル。省略する場合は、nullを指定します。
  51.      */
  52.     public void addTypeBindError(final TypeBindException bindException, final Cell cell, final String fieldName, final String label) {
  53.         addTypeBindError(bindException, CellPosition.of(cell), fieldName, label);
  54.     }
  55.    
  56.     /**
  57.      * 型変換エラーを追加します。
  58.      * @param bindException 型変換エラー
  59.      * @param address マッピング元となったセルのアドレス
  60.      * @param fieldName マッピング先のフィールド名
  61.      * @param label ラベル。省略する場合は、nullを指定します。
  62.      */
  63.     public void addTypeBindError(final TypeBindException bindException, final CellPosition address, final String fieldName, final String label) {
  64.        
  65.         this.errors.createFieldConversionError(fieldName, bindException.getBindClass(), bindException.getTargetValue())
  66.             .variables(bindException.getMessageVars())
  67.             .variables("validatedValue", bindException.getTargetValue())
  68.             .address(address)
  69.             .label(label)
  70.             .buildAndAddError();
  71.        
  72.     }
  73.    
  74.    
  75. }