AbstractDateDatoRicostruzione.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.logger.record;

  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;

  23. import org.openspcoop2.core.commons.CoreException;

  24. /**    
  25.  * AbstractDateDatoRicostruzione
  26.  *
  27.  * @author Poli Andrea (poli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public abstract class AbstractDateDatoRicostruzione extends AbstractDatoRicostruzione<Date> {

  32.     protected AbstractDateDatoRicostruzione(InfoDato info, Date dato) throws CoreException {
  33.         super(info, dato);
  34.     }

  35.     protected AbstractDateDatoRicostruzione(String dato, InfoDato info) throws CoreException {
  36.         super(dato, info);
  37.     }
  38.    
  39.     abstract SimpleDateFormat getDateFormat();
  40.    
  41.     @Override
  42.     public String convertToString() {
  43.         if(this.dato==null){
  44.             return CostantiDati.NON_PRESENTE;
  45.         }
  46.         return this.getDateFormat().format(this.dato);
  47.     }
  48.    
  49.     @Override
  50.     protected Date convertToObject(String dato) throws CoreException {
  51.         if(dato==null){
  52.             throw new CoreException("Dato non fornito");
  53.         }
  54.         if(CostantiDati.NON_PRESENTE.equals(dato)){
  55.             return null;
  56.         }
  57.         Date d = null;
  58.         try {
  59.             d = this.getDateFormat().parse(dato);
  60.         }catch(Exception e) {
  61.             throw new CoreException("Dato non interpretabile tramite il pattern ["+this.getDateFormat()+"]: "+e.getMessage(),e);
  62.         }
  63.         if(d==null){
  64.             throw new CoreException("Dato non interpretabile tramite il pattern ["+this.getDateFormat()+"]");
  65.         }
  66.         return d;
  67.     }

  68. }