LoaderRegistroPluginsService.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.pdd.config.loader.cli;

  21. import java.sql.Connection;
  22. import java.util.Properties;

  23. import javax.naming.Context;

  24. import org.openspcoop2.core.commons.CoreException;
  25. import org.openspcoop2.core.config.RegistroPlugins;
  26. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  27. import org.openspcoop2.core.config.driver.db.DriverConfigurazioneDB;
  28. import org.openspcoop2.generic_project.exception.NotFoundException;
  29. import org.openspcoop2.generic_project.utils.ServiceManagerProperties;
  30. import org.openspcoop2.monitor.engine.dynamic.IRegistroPluginsReader;
  31. import org.slf4j.Logger;

  32. /**
  33. * LoaderRegistroPluginsService
  34. *
  35. * @author Poli Andrea (apoli@link.it)
  36. * @author $Author$
  37. * @version $Rev$, $Date$
  38. */
  39. public class LoaderRegistroPluginsService implements IRegistroPluginsReader {

  40.     private static final String ERROR_PREFIX = "Errore durante la creazione del Service: ";
  41.    
  42.     private DriverConfigurazioneDB driverConfigDB = null;
  43.        
  44.     public LoaderRegistroPluginsService(Logger log, LoaderDatabaseProperties databaseProperties){
  45.         try{
  46.             this.initEngine(null, databaseProperties, null, log);
  47.            
  48.         }catch(Exception e){
  49.             String msgError = ERROR_PREFIX + e.getMessage();
  50.             log.error(msgError,e);
  51.         }
  52.     }
  53.     public LoaderRegistroPluginsService(Connection con, boolean autoCommit, LoaderDatabaseProperties databaseProperties, Logger log){
  54.         try{
  55.             if(autoCommit) {
  56.                 // nop
  57.             }
  58.             this.initEngine(con, databaseProperties, null, log);
  59.         }catch(Exception e){
  60.             log.error(ERROR_PREFIX + e.getMessage(),e);
  61.         }
  62.     }
  63.     public LoaderRegistroPluginsService(Connection con, boolean autoCommit, ServiceManagerProperties serviceManagerProperties, Logger log){
  64.         try{
  65.             if(autoCommit) {
  66.                 // nop
  67.             }
  68.             this.initEngine(con, null, serviceManagerProperties, log);
  69.         }catch(Exception e){
  70.             log.error(ERROR_PREFIX + e.getMessage(),e);
  71.         }
  72.     }
  73.     private void initEngine(Connection con, LoaderDatabaseProperties databaseProperties, ServiceManagerProperties serviceManagerProperties, Logger log) {
  74.         try{
  75.             String tipoDatabase = null;
  76.             if(serviceManagerProperties!=null) {
  77.                 tipoDatabase = serviceManagerProperties.getDatabaseType();
  78.             }
  79.             else {
  80.                 tipoDatabase = databaseProperties.getTipoDatabase();
  81.             }
  82.            
  83.             if(con!=null) {
  84.                 this.driverConfigDB = new DriverConfigurazioneDB(con, log, tipoDatabase);
  85.             }
  86.             else {
  87.                
  88.                 Properties datasourceJNDIContext = new Properties();
  89.                 datasourceJNDIContext.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
  90.                 datasourceJNDIContext.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
  91.                
  92.                 this.driverConfigDB = new DriverConfigurazioneDB(Loader.DS_JNDI_NAME,datasourceJNDIContext, log, tipoDatabase);
  93.             }

  94.         }catch(Exception e){
  95.             log.error(ERROR_PREFIX + e.getMessage(),e);
  96.         }
  97.     }
  98.    
  99.     @Override
  100.     public RegistroPlugins getRegistroPlugins() throws NotFoundException, CoreException {
  101.         try {
  102.             return this.driverConfigDB.getRegistroPlugins();
  103.         }catch(DriverConfigurazioneNotFound notFound) {
  104.             throw new NotFoundException(notFound.getMessage(), notFound);
  105.         }catch(Exception e) {
  106.             throw new CoreException(e.getMessage(),e);
  107.         }
  108.     }


  109. }