CalendarParameter.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.monitor.sdk.parameters;

  21. import java.lang.reflect.Method;
  22. import java.util.Date;

  23. import org.openspcoop2.monitor.sdk.constants.ParameterType;
  24. import org.openspcoop2.monitor.sdk.exceptions.ParameterException;

  25. /**
  26.  * CalendarParameter
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class CalendarParameter extends Parameter<Date> {

  33.     public CalendarParameter(String id) {
  34.         super(id, ParameterType.CALENDAR);
  35.     }

  36.     @Override
  37.     public void setValueAsString(String value) throws ParameterException{
  38.         if(value!=null){
  39.             try{
  40.                 Class<?> c = Class.forName("org.openspcoop2.monitor.engine.utils.ContentFormatter");
  41.                 Method m = c.getMethod("toDate", String.class);
  42.                 Date d = (Date) m.invoke(null, value);
  43.                 this.setValue(d);
  44.             }
  45.             catch(Exception e){
  46.                 throw new ParameterException("Value ["+value+"] uncorrected: "+e.getMessage(),e);
  47.             }
  48.         }
  49.     }
  50.    
  51.     @Override
  52.     public String getValueAsString() throws ParameterException{
  53.         if(this.getValue()!=null){
  54.             try{
  55.                 Class<?> c = Class.forName("org.openspcoop2.monitor.engine.utils.ContentFormatter");
  56.                 Method m = c.getMethod("toString", Date.class);
  57.                 String s = (String) m.invoke(null, this.getValue());
  58.                 return s;
  59.             }
  60.             catch(Exception e){
  61.                 throw new ParameterException("Error occurs: "+e.getMessage(),e);
  62.             }
  63.         }
  64.         return null;
  65.     }
  66. }