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

  35.     @javax.xml.bind.annotation.XmlEnumValue("subscriberType")
  36.     SUBSCRIBER_TYPE ("subscriberType"),
  37.     @javax.xml.bind.annotation.XmlEnumValue("subscriberName")
  38.     SUBSCRIBER_NAME ("subscriberName"),
  39.     @javax.xml.bind.annotation.XmlEnumValue("providerType")
  40.     PROVIDER_TYPE ("providerType"),
  41.     @javax.xml.bind.annotation.XmlEnumValue("providerName")
  42.     PROVIDER_NAME ("providerName"),
  43.     @javax.xml.bind.annotation.XmlEnumValue("serviceType")
  44.     SERVICE_TYPE ("serviceType"),
  45.     @javax.xml.bind.annotation.XmlEnumValue("serviceName")
  46.     SERVICE_NAME ("serviceName"),
  47.     @javax.xml.bind.annotation.XmlEnumValue("serviceVersion")
  48.     SERVICE_VERSION ("serviceVersion"),
  49.     @javax.xml.bind.annotation.XmlEnumValue("name")
  50.     NAME ("name"),
  51.     @javax.xml.bind.annotation.XmlEnumValue("ruleName")
  52.     RULE_NAME ("ruleName");
  53.    
  54.    
  55.     /** Value */
  56.     private String value;
  57.     @Override
  58.     public String getValue()
  59.     {
  60.         return this.value;
  61.     }


  62.     /** Official Constructor */
  63.     ActorType(String value)
  64.     {
  65.         this.value = value;
  66.     }


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