TipoPorta.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.core.statistiche.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.  * Enumeration dell'elemento tipo-porta xsd (tipo:string)
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. @javax.xml.bind.annotation.XmlType(name = "tipo-porta")
  34. @javax.xml.bind.annotation.XmlEnum(String.class)
  35. public enum TipoPorta implements IEnumeration , Serializable , Cloneable {

  36.     @javax.xml.bind.annotation.XmlEnumValue("delegata")
  37.     DELEGATA ("delegata"),
  38.     @javax.xml.bind.annotation.XmlEnumValue("applicativa")
  39.     APPLICATIVA ("applicativa"),
  40.     @javax.xml.bind.annotation.XmlEnumValue("router")
  41.     ROUTER ("router"),
  42.     @javax.xml.bind.annotation.XmlEnumValue("integration_manager")
  43.     INTEGRATION_MANAGER ("integration_manager");
  44.    
  45.    
  46.     /** Value */
  47.     private String value;
  48.     @Override
  49.     public String getValue()
  50.     {
  51.         return this.value;
  52.     }


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


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