MessageListener.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.utils.wadl;

  21. import org.slf4j.Logger;

  22. /**
  23.  * Message Listener che riceve gli eventi durante la lettura di un wadl
  24.  *
  25.  * @author Andrea Poli (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  *
  29.  */

  30. public class MessageListener implements org.jvnet.ws.wadl.util.MessageListener {

  31.     private Logger log;
  32.     private boolean logInfoLevel;
  33.     private boolean logWarningLevel;
  34.     public MessageListener(Logger log){
  35.         this(log, true, true);
  36.     }
  37.     public MessageListener(Logger log,boolean logInfoLevel,boolean logWarningLevel){
  38.         this.log = log;
  39.         this.logInfoLevel = logInfoLevel;
  40.         this.logWarningLevel = logWarningLevel;
  41.     }
  42.    
  43.     @Override
  44.     public void error(String message, Throwable t) {
  45.         if(this.log!=null){
  46.             this.log.error("[WADL] "+message, t);
  47.         }else{
  48.             System.err.println("[WADL] "+message);
  49.             t.printStackTrace(System.err);
  50.         }
  51.     }

  52.     @Override
  53.     public void info(String message) {
  54.         if(this.logInfoLevel){
  55.             if(this.log!=null){
  56.                 this.log.info("[WADL] "+message);
  57.             }
  58.             else{
  59.                 System.out.println("[WADL] "+message);
  60.             }
  61.         }
  62.     }

  63.     @Override
  64.     public void warning(String message, Throwable t) {
  65.         if(this.logWarningLevel){
  66.             if(this.log!=null){
  67.                 this.log.warn("[WADL] "+message, t);
  68.             }else{
  69.                 System.out.println("[WADL] "+message);
  70.                 t.printStackTrace(System.out);
  71.             }
  72.         }
  73.     }

  74. }