DescriptionItemType.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.protocol.information_missing.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 DescriptionItemType xsd (tipo:string)
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. @javax.xml.bind.annotation.XmlType(name = "DescriptionItemType")
  33. @javax.xml.bind.annotation.XmlEnum(String.class)
  34. public enum DescriptionItemType implements IEnumeration , Serializable , Cloneable {

  35.     @javax.xml.bind.annotation.XmlEnumValue("title")
  36.     TITLE ("title"),
  37.     @javax.xml.bind.annotation.XmlEnumValue("subtitle")
  38.     SUBTITLE ("subtitle"),
  39.     @javax.xml.bind.annotation.XmlEnumValue("note")
  40.     NOTE ("note"),
  41.     @javax.xml.bind.annotation.XmlEnumValue("text")
  42.     TEXT ("text");
  43.    
  44.    
  45.     /** Value */
  46.     private String value;
  47.     @Override
  48.     public String getValue()
  49.     {
  50.         return this.value;
  51.     }


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


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