TipoSelettore.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.core.behaviour.conditional;

  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.  * TipoSelettore
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public enum TipoSelettore implements IEnumeration , Serializable , Cloneable {

  33.     HEADER_BASED ("HeaderBased"),
  34.     URLBASED ("URLBased"),
  35.     FORM_BASED ("FormBased"),
  36.     SOAPACTION_BASED ("SOAPActionBased"),
  37.     CONTENT_BASED ("ContentBased"),
  38.     INDIRIZZO_IP ("ClientIP"),
  39.     INDIRIZZO_IP_FORWARDED ("XForwardedFor"),
  40.     TEMPLATE ("Template"),
  41.     VELOCITY_TEMPLATE ("VelocityTemplate"),
  42.     FREEMARKER_TEMPLATE ("FreemarkerTemplate");
  43.    
  44.    
  45.     /** Value */
  46.     private String value;
  47.     @Override
  48.     public String getValue()
  49.     {
  50.         return this.value;
  51.     }


  52.     /** Official Constructor */
  53.     TipoSelettore(String value)
  54.     {
  55.         this.value = value;
  56.     }

  57.    
  58.     public boolean isTemplate() {
  59.         return TEMPLATE.equals(this) || VELOCITY_TEMPLATE.equals(this) || FREEMARKER_TEMPLATE.equals(this);
  60.     }
  61.    
  62.     public boolean hasParameter() {
  63.         return HEADER_BASED.equals(this) || URLBASED.equals(this) || FORM_BASED.equals(this) || CONTENT_BASED.equals(this) || this.isTemplate();
  64.     }

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