Parameter.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.util.ArrayList;
  22. import java.util.List;

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

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

  33.     private String id;
  34.     private List<String> refreshParamIds;
  35.     private ParameterRendering<T> rendering;
  36.     private ParameterType type;
  37.     private T value;
  38.    
  39.     protected Parameter(String id, ParameterType type){
  40.         this.id = id;
  41.         this.type = type;
  42.         this.refreshParamIds = new ArrayList<>();
  43.         this.rendering = new ParameterRendering<T>();
  44.     }
  45.     protected Parameter(Parameter<T> p){
  46.         this.id = p.id;
  47.         this.type = p.type;
  48.         this.refreshParamIds = p.refreshParamIds;
  49.         this.rendering = p.rendering;
  50.     }
  51.    
  52.     public ParameterType getType() {
  53.         return this.type;
  54.     }
  55.     public String getId() {
  56.         return this.id;
  57.     }
  58.     public void setId(String id) {
  59.         this.id = id;
  60.     }
  61.     public List<String> getRefreshParamIds() {
  62.         return this.refreshParamIds;
  63.     }
  64.     public void setRefreshParamIds(List<String> refreshParamIds) {
  65.         this.refreshParamIds = refreshParamIds;
  66.     }
  67.     public ParameterRendering<T> getRendering() {
  68.         return this.rendering;
  69.     }
  70.     public void setRendering(ParameterRendering<T> rendering) {
  71.         this.rendering = rendering;
  72.     }
  73.     @SuppressWarnings("unchecked")
  74.     public T getValue() {
  75.         if(this.value!=null){
  76.             // Per le stringhe effettuo il trim
  77.             if(this.value instanceof String){
  78.                 String s = (String) this.value;
  79.                 return (T) s.trim();
  80.             }
  81.         }
  82.         return this.value;
  83.     }
  84.     public void setValue(T value) {
  85.         this.value = value;
  86.     }
  87.     public void resetValue(){
  88.         this.value = null;
  89.     }
  90.     public abstract void setValueAsString(String value) throws ParameterException;
  91.     public abstract String getValueAsString() throws ParameterException;
  92.    
  93. }