LivelloRilevanza.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.sdk.constants;

  21. import org.apache.commons.lang.NotImplementedException;

  22. /**
  23.  * Enumarazione sul livello di rilevanza di una eccezione
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public enum LivelloRilevanza {
  30.     DEBUG("DEBUG"),
  31.     INFO("INFO"),
  32.     WARN("WARN"),
  33.     ERROR("ERROR"),
  34.     FATAL("FATAL"),
  35.     UNKNOWN("Sconosciuto");

  36.     private final String livello;

  37.     LivelloRilevanza(String livello){
  38.         this.livello = livello;
  39.     }
  40.    
  41.     @Override
  42.     public String toString() {
  43.         throw new NotImplementedException("Use ProtocolFactory.createTraduttore().toString(livelloRilevanza) or getEngineValue()");
  44.     }
  45.    
  46.     public boolean equals(String l){
  47.         if(l==null){
  48.             return false;
  49.         }
  50.         return this.livello.equals(l);
  51.     }
  52.    
  53.     public String getEngineValue(){
  54.         return this.livello;
  55.     }
  56.    
  57.     public static boolean isEccezioneLivelloGrave(LivelloRilevanza livello){
  58.         switch (livello) {
  59.         case ERROR:
  60.         case FATAL:
  61.             return true;
  62.         default:
  63.             return false;
  64.         }
  65.     }
  66.    
  67.     public static LivelloRilevanza toLivelloRilevanza(String metaValue){
  68.         if(DEBUG.livello.equals(metaValue))
  69.             return DEBUG;
  70.         if(INFO.livello.equals(metaValue))
  71.             return INFO;
  72.         if(WARN.livello.equals(metaValue))
  73.             return WARN;
  74.         if(ERROR.livello.equals(metaValue))
  75.             return ERROR;
  76.         if(FATAL.livello.equals(metaValue))
  77.             return FATAL;
  78.         return UNKNOWN;
  79.     }

  80. }