HttpMethod.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.registry.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 HttpMethod 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 = "HttpMethod")
  33. @javax.xml.bind.annotation.XmlEnum(String.class)
  34. public enum HttpMethod implements IEnumeration , Serializable , Cloneable {

  35.     @javax.xml.bind.annotation.XmlEnumValue("GET")
  36.     GET ("GET"),
  37.     @javax.xml.bind.annotation.XmlEnumValue("POST")
  38.     POST ("POST"),
  39.     @javax.xml.bind.annotation.XmlEnumValue("PUT")
  40.     PUT ("PUT"),
  41.     @javax.xml.bind.annotation.XmlEnumValue("DELETE")
  42.     DELETE ("DELETE"),
  43.     @javax.xml.bind.annotation.XmlEnumValue("OPTIONS")
  44.     OPTIONS ("OPTIONS"),
  45.     @javax.xml.bind.annotation.XmlEnumValue("HEAD")
  46.     HEAD ("HEAD"),
  47.     @javax.xml.bind.annotation.XmlEnumValue("TRACE")
  48.     TRACE ("TRACE"),
  49.     @javax.xml.bind.annotation.XmlEnumValue("PATCH")
  50.     PATCH ("PATCH"),
  51.     @javax.xml.bind.annotation.XmlEnumValue("LINK")
  52.     LINK ("LINK"),
  53.     @javax.xml.bind.annotation.XmlEnumValue("UNLINK")
  54.     UNLINK ("UNLINK");
  55.    
  56.    
  57.     /** Value */
  58.     private String value;
  59.     @Override
  60.     public String getValue()
  61.     {
  62.         return this.value;
  63.     }


  64.     /** Official Constructor */
  65.     HttpMethod(String value)
  66.     {
  67.         this.value = value;
  68.     }


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