GestoreRegistroServiziRemoto.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.web.ctrlstat.registro;

  21. import java.util.Properties;

  22. import org.slf4j.Logger;
  23. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  24. import org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet;
  25. import org.openspcoop2.core.registry.driver.db.DriverRegistroServiziDB;
  26. import org.openspcoop2.core.registry.driver.uddi.DriverRegistroServiziUDDI;
  27. import org.openspcoop2.core.registry.driver.web.DriverRegistroServiziWEB;
  28. import org.openspcoop2.core.registry.driver.ws.DriverRegistroServiziWS;
  29. import org.openspcoop2.core.registry.driver.xml.DriverRegistroServiziXML;
  30. import org.openspcoop2.web.ctrlstat.config.RegistroServiziRemotoProperties;


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

  40.    
  41.     public static IDriverRegistroServiziGet getDriverRegistroServizi(Logger log) throws Exception{
  42.         if(gestore==null){
  43.             init(log);
  44.         }
  45.         return gestore.driverRegistroServizi;
  46.     }
  47.     public static String getTipoRegistroServizi(Logger log) throws Exception{
  48.         if(gestore==null){
  49.             init(log);
  50.         }
  51.         return gestore.tipoRegistro;
  52.     }
  53.    
  54.     private static GestoreRegistroServiziRemoto gestore = null;
  55.     private static synchronized void init(Logger log) throws Exception{
  56.         if(gestore==null){
  57.             gestore = new GestoreRegistroServiziRemoto(log);
  58.         }
  59.     }
  60.    
  61.    
  62.    
  63.     private String tipoRegistro;
  64.     private IDriverRegistroServiziGet driverRegistroServizi = null;
  65.    
  66.     public GestoreRegistroServiziRemoto(Logger log) throws Exception{
  67.        
  68.         RegistroServiziRemotoProperties registroServiziRemotoProperties = RegistroServiziRemotoProperties.getInstance();
  69.        
  70.        
  71.         /* CONFIGURAZIONE GENERALE */
  72.         this.tipoRegistro = registroServiziRemotoProperties.getTipoRegistroServiziRemoto();
  73.        
  74.        
  75.         /* REGISTRO XML */
  76.         if(CostantiConfigurazione.REGISTRO_XML.equals(this.tipoRegistro)){
  77.            
  78.             String location = registroServiziRemotoProperties.getRegistroServiziXML_Location();
  79.            
  80.            
  81.             this.driverRegistroServizi = new DriverRegistroServiziXML(location, log);
  82.             if(((DriverRegistroServiziXML)this.driverRegistroServizi).create==false){
  83.                 throw new Exception("[RegistroServiziRemoto] DriverRegistroServiziXML non correttamente inizializzato");
  84.             }
  85.         }
  86.        
  87.         /* REGISTRO WS */
  88.         else if(CostantiConfigurazione.REGISTRO_WS.equals(this.tipoRegistro)){
  89.            
  90.             String location = registroServiziRemotoProperties.getRegistroServiziWS_Location();
  91.            
  92.             String username = registroServiziRemotoProperties.getRegistroServiziWS_Username();
  93.             if(username!=null){
  94.                 username = username.trim();
  95.             }
  96.             String password = registroServiziRemotoProperties.getRegistroServiziWS_Password();
  97.             if(password!=null){
  98.                 password = password.trim();
  99.             }
  100.            
  101.             if(username!=null && password!=null){
  102.                 this.driverRegistroServizi = new DriverRegistroServiziWS(location,username,password, log);
  103.             }else{
  104.                 this.driverRegistroServizi = new DriverRegistroServiziWS(location, log);
  105.             }
  106.             if(((DriverRegistroServiziWS)this.driverRegistroServizi).create==false){
  107.                 throw new Exception("[RegistroServiziRemoto] DriverRegistroServiziWS non correttamente inizializzato");
  108.             }
  109.         }
  110.        
  111.         /* REGISTRO DB */
  112.         else if(CostantiConfigurazione.REGISTRO_DB.equals(this.tipoRegistro)){
  113.            
  114.             String tipoDatabase = registroServiziRemotoProperties.getRegistroServiziDB_TipoDatabase();
  115.            
  116.             String datasource = registroServiziRemotoProperties.getRegistroServiziDB_DataSource();
  117.        
  118.             Properties ctxProperties = registroServiziRemotoProperties.getRegistroServiziDB_DataSourceContext();
  119.            
  120.             this.driverRegistroServizi = new DriverRegistroServiziDB(datasource,ctxProperties, log,tipoDatabase);
  121.             if(((DriverRegistroServiziDB)this.driverRegistroServizi).create==false){
  122.                 throw new Exception("[RegistroServiziRemoto] DriverRegistroServiziDB non correttamente inizializzato");
  123.             }
  124.            
  125.         }
  126.        
  127.         /* REGISTRO UDDI */
  128.         else if(CostantiConfigurazione.REGISTRO_UDDI.equals(this.tipoRegistro)){
  129.            
  130.             String location = registroServiziRemotoProperties.getRegistroServiziUDDI_InquiryURL();
  131.            
  132.             String username = registroServiziRemotoProperties.getRegistroServiziUDDI_Username();
  133.             if(username!=null){
  134.                 username = username.trim();
  135.             }
  136.             String password = registroServiziRemotoProperties.getRegistroServiziUDDI_Password();
  137.             if(password!=null){
  138.                 password = password.trim();
  139.             }
  140.            
  141.             if(username!=null && password!=null){
  142.                 this.driverRegistroServizi = new DriverRegistroServiziUDDI(location,username,password, log);
  143.             }else{
  144.                 this.driverRegistroServizi = new DriverRegistroServiziUDDI(location, log);
  145.             }
  146.             if(((DriverRegistroServiziUDDI)this.driverRegistroServizi).create==false){
  147.                 throw new Exception("[RegistroServiziRemoto] DriverRegistroServiziUDDI non correttamente inizializzato");
  148.             }
  149.    
  150.         }
  151.        
  152.         /* REGISTRO WEB */
  153.         else if(CostantiConfigurazione.REGISTRO_WEB.equals(this.tipoRegistro)){
  154.            
  155.             String location = registroServiziRemotoProperties.getRegistroServiziWEB_URLPrefix();
  156.            
  157.             this.driverRegistroServizi = new DriverRegistroServiziWEB(location, log);
  158.             if(((DriverRegistroServiziWEB)this.driverRegistroServizi).create==false){
  159.                 throw new Exception("[RegistroServiziRemoto] DriverRegistroServiziWEB non correttamente inizializzato");
  160.             }
  161.            
  162.            
  163.         }
  164.        
  165.         else{
  166.             throw new Exception("Tipo di registro non gestito: "+this.tipoRegistro);
  167.         }
  168.        
  169.         log.info("Accesso al registro dei servizi remoto di tipo ["+this.tipoRegistro+"] correttamente effettuato.");
  170.            
  171.        
  172.     }
  173.    
  174. }