TipoBehaviour.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.config.constants;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.List;

  24. import org.openspcoop2.generic_project.beans.IEnumeration;
  25. import org.openspcoop2.generic_project.exception.NotFoundException;

  26. /**    
  27.  * BehaviourType
  28.  *
  29.  * @author Poli Andrea (poli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public enum TipoBehaviour implements IEnumeration , Serializable , Cloneable {

  34.     CONSEGNA_LOAD_BALANCE (CostantiConfigurazione.CONSEGNA_LOAD_BALANCE ,"Load Balance"), // per tutti
  35.     CONSEGNA_MULTIPLA (CostantiConfigurazione.CONSEGNA_MULTIPLA , "Consegna Multipla"), //ex "Più Destinatari"), // per oneway-soap
  36.     CONSEGNA_CONDIZIONALE (CostantiConfigurazione.CONSEGNA_CONDIZIONALE ,"Consegna Condizionale"), // per tutti
  37.     CONSEGNA_CON_NOTIFICHE (CostantiConfigurazione.CONSEGNA_CON_NOTIFICHE ,"Consegna con Notifiche"), // per !oneway-soap e rest
  38.     CUSTOM (CostantiConfigurazione.CONSEGNA_CUSTOM ,"Personalizzata");


  39.     /** Value */
  40.     private String value;
  41.     @Override
  42.     public String getValue()
  43.     {
  44.         return this.value;
  45.     }

  46.     /** Label */
  47.     private String label;
  48.     public String getLabel()
  49.     {
  50.         return this.label;
  51.     }


  52.     /** Official Constructor */
  53.     TipoBehaviour(String value, String label)
  54.     {
  55.         this.value = value;
  56.         this.label = label;
  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.     /** compatibility with the generated bean (reflection) */
  68.     public boolean equals(Object object,List<String> fieldsNotCheck){
  69.         if( !(object instanceof TipoBehaviour) ){
  70.             throw new RuntimeException("Wrong type: "+object.getClass().getName());
  71.         }
  72.         return this.equals(((TipoBehaviour)object));
  73.     }
  74.     public String toString(boolean reportHTML){
  75.         return toString();
  76.     }
  77.     public String toString(boolean reportHTML,List<String> fieldsNotIncluded){
  78.         return toString();
  79.     }
  80.     public String diff(Object object,StringBuilder bf,boolean reportHTML){
  81.         return bf.toString();
  82.     }
  83.     public String diff(Object object,StringBuilder bf,boolean reportHTML,List<String> fieldsNotIncluded){
  84.         return bf.toString();
  85.     }


  86.     /** Utilities */

  87.     public static List<TipoBehaviour> getEnums(boolean consegnaMultiplaEnabled, boolean soapOneway){
  88.         List<TipoBehaviour> l = new ArrayList<TipoBehaviour>();
  89.         l.add(TipoBehaviour.CONSEGNA_LOAD_BALANCE);
  90.         l.add(TipoBehaviour.CONSEGNA_CONDIZIONALE);
  91.         if(consegnaMultiplaEnabled) {
  92.             l.add(TipoBehaviour.CONSEGNA_CON_NOTIFICHE);
  93.             if(soapOneway) {
  94.                 l.add(TipoBehaviour.CONSEGNA_MULTIPLA);
  95.             }
  96.             // posso usarla anche su soap oneway
  97.             //else {
  98.             // quindi spostata sopra la consegna multipla per coerenza di spiegazione
  99.             //l.add(TipoBehaviour.CONSEGNA_CON_NOTIFICHE);
  100.             //}
  101.         }
  102.         l.add(TipoBehaviour.CUSTOM);
  103.         return l;
  104.     }
  105.     public static List<String> getLabels(boolean consegnaMultiplaEnabled, boolean soapOneway){
  106.         List<TipoBehaviour> l = getEnums(consegnaMultiplaEnabled, soapOneway);
  107.         List<String> newL = new ArrayList<>();
  108.         for (TipoBehaviour behaviourType : l) {
  109.             newL.add(behaviourType.getLabel());
  110.         }
  111.         return newL;
  112.     }
  113.     public static List<String> getValues(boolean consegnaMultiplaEnabled, boolean soapOneway){
  114.         List<TipoBehaviour> l = getEnums(consegnaMultiplaEnabled, soapOneway);
  115.         List<String> newL = new ArrayList<>();
  116.         for (TipoBehaviour behaviourType : l) {
  117.             newL.add(behaviourType.getValue());
  118.         }
  119.         return newL;
  120.     }

  121.     public static String[] toArray(){
  122.         String[] res = new String[values().length];
  123.         int i=0;
  124.         for (TipoBehaviour tmp : values()) {
  125.             res[i]=tmp.getValue();
  126.             i++;
  127.         }
  128.         return res;
  129.     }  
  130.     public static String[] toStringArray(){
  131.         String[] res = new String[values().length];
  132.         int i=0;
  133.         for (TipoBehaviour tmp : values()) {
  134.             res[i]=tmp.toString();
  135.             i++;
  136.         }
  137.         return res;
  138.     }
  139.     public static String[] toEnumNameArray(){
  140.         String[] res = new String[values().length];
  141.         int i=0;
  142.         for (TipoBehaviour tmp : values()) {
  143.             res[i]=tmp.name();
  144.             i++;
  145.         }
  146.         return res;
  147.     }

  148.     public static boolean contains(String value){
  149.         return toEnumConstant(value)!=null;
  150.     }

  151.     public static TipoBehaviour toEnumConstant(String value){
  152.         try{
  153.             return toEnumConstant(value,false);
  154.         }catch(NotFoundException notFound){
  155.             return null;
  156.         }
  157.     }
  158.     public static TipoBehaviour toEnumConstant(String value, boolean throwNotFoundException) throws NotFoundException{
  159.         TipoBehaviour res = null;
  160.         for (TipoBehaviour tmp : values()) {
  161.             if(tmp.getValue().equals(value)){
  162.                 res = tmp;
  163.                 break;
  164.             }
  165.         }
  166.         if(res==null && value!=null && !"".equals(value)) {
  167.             return TipoBehaviour.CUSTOM;
  168.         }
  169.         if(res==null && throwNotFoundException){
  170.             throw new NotFoundException("Enum with value ["+value+"] not found");
  171.         }
  172.         return res;
  173.     }

  174.     public static IEnumeration toEnumConstantFromString(String value){
  175.         try{
  176.             return toEnumConstantFromString(value,false);
  177.         }catch(NotFoundException notFound){
  178.             return null;
  179.         }
  180.     }
  181.     public static IEnumeration toEnumConstantFromString(String value, boolean throwNotFoundException) throws NotFoundException{
  182.         TipoBehaviour res = null;
  183.         for (TipoBehaviour tmp : values()) {
  184.             if(tmp.toString().equals(value)){
  185.                 res = tmp;
  186.                 break;
  187.             }
  188.         }
  189.         if(res==null && value!=null && !"".equals(value)) {
  190.             return TipoBehaviour.CUSTOM;
  191.         }
  192.         if(res==null && throwNotFoundException){
  193.             throw new NotFoundException("Enum with value ["+value+"] not found");
  194.         }
  195.         return res;
  196.     }
  197. }