BasicComponentFactory.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.basic;

  21. import org.openspcoop2.protocol.sdk.IComponentFactory;
  22. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  23. import org.openspcoop2.protocol.sdk.ProtocolException;
  24. import org.slf4j.Logger;

  25. /**
  26.  * BasicComponentFactory
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class BasicComponentFactory implements IComponentFactory {

  33.     private static Logger checkLogger = null;
  34.     private static boolean checkIsClosed = true;
  35.     private static boolean checkAutocommit = true;
  36.     public static boolean isCheckIsClosed() {
  37.         return checkIsClosed;
  38.     }
  39.     public static void setCheckIsClosed(boolean checkIsClosed) {
  40.         BasicComponentFactory.checkIsClosed = checkIsClosed;
  41.     }
  42.     public static boolean isCheckAutocommit() {
  43.         return checkAutocommit;
  44.     }
  45.     public static void setCheckAutocommit(boolean checkAutocommit) {
  46.         BasicComponentFactory.checkAutocommit = checkAutocommit;
  47.     }
  48.     public static Logger getCheckLogger() {
  49.         return checkLogger;
  50.     }
  51.     public static void setCheckLogger(Logger checkLogger) {
  52.         BasicComponentFactory.checkLogger = checkLogger;
  53.     }

  54.     protected Logger log;
  55.     protected IProtocolFactory<?> protocolFactory;
  56.    
  57.     public BasicComponentFactory(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  58.         try{
  59.             this.protocolFactory = protocolFactory;
  60.             this.log = this.protocolFactory.getLogger();
  61.         }catch(Exception e){
  62.             throw new ProtocolException(e.getMessage(),e);
  63.         }
  64.     }
  65.    
  66.     public Logger getLog() {
  67.         return this.log;
  68.     }
  69.     public void logError(String msg) {
  70.         if(this.log!=null) {
  71.             this.log.error(msg);
  72.         }
  73.     }
  74.     public void logError(String msg, Exception e) {
  75.         if(this.log!=null) {
  76.             this.log.error(msg, e);
  77.         }
  78.     }
  79.     public void logInfo(String msg) {
  80.         if(this.log!=null) {
  81.             this.log.info(msg);
  82.         }
  83.     }
  84.     public void logDebug(String msg) {
  85.         if(this.log!=null) {
  86.             this.log.debug(msg);
  87.         }
  88.     }
  89.    
  90.     @Override
  91.     public IProtocolFactory<?> getProtocolFactory() {
  92.         return this.protocolFactory;
  93.     }
  94.    
  95. }