ParameterType.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.constants;

  21. import java.io.Serializable;
  22. import java.util.List;

  23. import org.openspcoop2.generic_project.beans.IEnumeration;
  24. import org.openspcoop2.generic_project.exception.NotFoundException;

  25. /**
  26.  * ParameterType
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public enum ParameterType implements IEnumeration , Serializable , Cloneable {

  33.    
  34.     INPUT_TEXT ("INPUT_TEXT"),
  35.    
  36.     OUTPUT_TEXT ("OUTPUT_TEXT"),
  37.    
  38.     INPUT_SECRET ("INPUT_SECRET"),
  39.    
  40.     TEXT_AREA ("TEXT_AREA"),
  41.    
  42.     SELECT_LIST ("SELECT_LIST"),
  43.    
  44.     RADIO_BUTTON ("RADIO_BUTTON"),
  45.    
  46.     CHECK_BOX ("CHECK_BOX"),
  47.    
  48.     CALENDAR ("CALENDAR");
  49.    
  50.    
  51.     /** Value */
  52.     private String value;
  53.     @Override
  54.     public String getValue()
  55.     {
  56.         return this.value;
  57.     }


  58.     /** Official Constructor */
  59.     ParameterType(String value)
  60.     {
  61.         this.value = value;
  62.     }


  63.    
  64.     @Override
  65.     public String toString(){
  66.         return this.value;
  67.     }
  68.     public boolean equals(String object){
  69.         if(object==null)
  70.             return false;
  71.         return object.equals(this.getValue());  
  72.     }
  73.    
  74.        
  75.    
  76.     /** compatibility with the generated bean (reflection) */
  77.     public boolean equals(Object object,List<String> fieldsNotCheck){
  78.         if( !(object instanceof ParameterType) ){
  79.             throw new RuntimeException("Wrong type: "+object.getClass().getName());
  80.         }
  81.         return this.equals(((ParameterType)object));
  82.     }
  83.     public String toString(boolean reportHTML){
  84.         return toString();
  85.     }
  86.     public String toString(boolean reportHTML,List<String> fieldsNotIncluded){
  87.         return toString();
  88.     }
  89.     public String diff(Object object,StringBuilder bf,boolean reportHTML){
  90.         return bf.toString();
  91.     }
  92.     public String diff(Object object,StringBuilder bf,boolean reportHTML,List<String> fieldsNotIncluded){
  93.         return bf.toString();
  94.     }
  95.    
  96.    
  97.     /** Utilities */
  98.    
  99.     public static String[] toArray(){
  100.         String[] res = new String[values().length];
  101.         int i=0;
  102.         for (ParameterType tmp : values()) {
  103.             res[i]=tmp.getValue();
  104.             i++;
  105.         }
  106.         return res;
  107.     }  
  108.     public static String[] toStringArray(){
  109.         String[] res = new String[values().length];
  110.         int i=0;
  111.         for (ParameterType tmp : values()) {
  112.             res[i]=tmp.toString();
  113.             i++;
  114.         }
  115.         return res;
  116.     }
  117.     public static String[] toEnumNameArray(){
  118.         String[] res = new String[values().length];
  119.         int i=0;
  120.         for (ParameterType tmp : values()) {
  121.             res[i]=tmp.name();
  122.             i++;
  123.         }
  124.         return res;
  125.     }
  126.    
  127.     public static boolean contains(String value){
  128.         return toEnumConstant(value)!=null;
  129.     }
  130.    
  131.     public static ParameterType toEnumConstant(String value){
  132.         try{
  133.             return toEnumConstant(value,false);
  134.         }catch(NotFoundException notFound){
  135.             return null;
  136.         }
  137.     }
  138.     public static ParameterType toEnumConstant(String value, boolean throwNotFoundException) throws NotFoundException{
  139.         ParameterType res = null;
  140.         for (ParameterType tmp : values()) {
  141.             if(tmp.getValue().equals(value)){
  142.                 res = tmp;
  143.                 break;
  144.             }
  145.         }
  146.         if(throwNotFoundException){
  147.             throw new NotFoundException("Enum with value ["+value+"] not found");
  148.         }
  149.         return res;
  150.     }
  151.    
  152.     public static IEnumeration toEnumConstantFromString(String value){
  153.         try{
  154.             return toEnumConstantFromString(value,false);
  155.         }catch(NotFoundException notFound){
  156.             return null;
  157.         }
  158.     }
  159.     public static IEnumeration toEnumConstantFromString(String value, boolean throwNotFoundException) throws NotFoundException{
  160.         ParameterType res = null;
  161.         for (ParameterType tmp : values()) {
  162.             if(tmp.toString().equals(value)){
  163.                 res = tmp;
  164.                 break;
  165.             }
  166.         }
  167.         if(throwNotFoundException){
  168.             throw new NotFoundException("Enum with value ["+value+"] not found");
  169.         }
  170.         return res;
  171.     }
  172. }