SeveritaConverter.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.eventi.utils;

  21. import org.openspcoop2.core.eventi.constants.TipoSeverita;
  22. import org.openspcoop2.utils.UtilsException;

  23. /**
  24.  * SeveritaConverter
  25.  *
  26.  * @author Andrea Poli (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class SeveritaConverter {
  31.    
  32.     private SeveritaConverter() {}

  33.     private static final int FATAL = 0;
  34.     private static final int ERROR = 1;
  35.     private static final int WARN = 2;
  36.     private static final int INFO = 3;
  37.     private static final int DEBUG = 4;
  38.    
  39.     public static TipoSeverita toSeverita(int intValue) throws UtilsException{
  40.         if(intValue==FATAL){
  41.             return TipoSeverita.FATAL;
  42.         }
  43.         else if(intValue==ERROR){
  44.             return TipoSeverita.ERROR;
  45.         }
  46.         else if(intValue==WARN){
  47.             return TipoSeverita.WARN;
  48.         }
  49.         else if(intValue==INFO){
  50.             return TipoSeverita.INFO;
  51.         }
  52.         else if(intValue==DEBUG){
  53.             return TipoSeverita.DEBUG;
  54.         }
  55.         else{
  56.             throw new UtilsException("Value ["+intValue+"] unknown");
  57.         }
  58.     }
  59.    
  60.     public static int toIntValue(TipoSeverita severita) throws UtilsException{
  61.         switch (severita) {
  62.         case FATAL:
  63.             return FATAL;
  64.         case ERROR:
  65.             return ERROR;
  66.         case WARN:
  67.             return WARN;
  68.         case INFO:
  69.             return INFO;
  70.         case DEBUG:
  71.             return DEBUG;
  72.         }
  73.         throw new UtilsException("Enumeration ["+severita+"] non gestita");
  74.     }
  75.    
  76. }