TypeBindException.java

  1. package com.gh.mygreen.xlsmapper.cellconverter;

  2. import java.util.LinkedHashMap;
  3. import java.util.Map;

  4. import com.gh.mygreen.xlsmapper.XlsMapperException;
  5. import com.gh.mygreen.xlsmapper.util.ArgUtils;




  6. /**
  7.  * ExcelのCellとJavaオブジェクト間の型変換に失敗した際にスローされる例外。
  8.  *
  9.  * @author T.TSUCHIE
  10.  *
  11.  */
  12. public class TypeBindException extends XlsMapperException {
  13.    
  14.     /** serialVersionUID */
  15.     private static final long serialVersionUID = -5571437827158347334L;
  16.    
  17.     /** バインド先の クラスタイプ*/
  18.     private Class<?> bindClass;
  19.    
  20.     /** バインド対象の値 */
  21.     private final Object targetValue;
  22.    
  23.     /** validation時のメッセージの変数に使用する */
  24.     private final Map<String, Object> messageVars = new LinkedHashMap<>();
  25.    
  26.     public TypeBindException(final Exception e, final String message, final Class<?> bindClass, final Object targetValue) {
  27.         super(message, e);
  28.         this.bindClass = bindClass;
  29.         this.targetValue = targetValue;
  30.     }
  31.    
  32.     public TypeBindException(final String message, final Class<?> bindClass, final Object targetValue) {
  33.         super(message);
  34.         this.bindClass = bindClass;
  35.         this.targetValue = targetValue;
  36.     }
  37.    
  38.     public void setBindClass(Class<?> bindClass) {
  39.         this.bindClass = bindClass;
  40.     }
  41.    
  42.     public Class<?> getBindClass() {
  43.         return bindClass;
  44.     }
  45.    
  46.     public Object getTargetValue() {
  47.         return targetValue;
  48.     }
  49.    
  50.     public Map<String, Object> getMessageVars() {
  51.         return messageVars;
  52.     }
  53.    
  54.     public TypeBindException addMessageVar(final String key, Object value) {
  55.         ArgUtils.notEmpty(key, "key");
  56.         getMessageVars().put(key, value);
  57.         return this;
  58.     }
  59.    
  60.     public TypeBindException addAllMessageVars(final Map<String, Object> messageVars) {
  61.         ArgUtils.notNull(messageVars, "messageVars");
  62.         getMessageVars().putAll(messageVars);
  63.         return this;
  64.     }
  65.    
  66. }