RegistroServiziRemotoProperties.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.config;


  21. import java.util.Properties;

  22. import org.slf4j.Logger;
  23. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  24. import org.openspcoop2.pdd.config.OpenSPCoop2ConfigurationException;
  25. import org.openspcoop2.utils.LoggerWrapperFactory;
  26. import org.openspcoop2.utils.UtilsException;


  27. /**
  28. * ConsoleProperties
  29. *
  30. * @author Andrea Poli (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33. */


  34. public class RegistroServiziRemotoProperties {  

  35.     /** Logger utilizzato per errori eventuali. */
  36.     private Logger log = null;



  37.     /* ********  F I E L D S  P R I V A T I  ******** */

  38.     /** Reader delle proprieta' impostate nel file 'console.registroServiziRemoto.properties' */
  39.     private RegistroServiziRemotoInstanceProperties reader;

  40.     /** Copia Statica */
  41.     private static RegistroServiziRemotoProperties registroServiziRemotoProperties = null;


  42.     /* ********  C O S T R U T T O R E  ******** */

  43.     /**
  44.      * Viene chiamato in causa per istanziare il properties reader
  45.      *
  46.      *
  47.      */
  48.     private RegistroServiziRemotoProperties(String confDir, String confPropertyName, String confLocalPathPrefix,Logger log) throws Exception {

  49.         if(log!=null)
  50.             this.log = log;
  51.         else
  52.             this.log = LoggerWrapperFactory.getLogger(RegistroServiziRemotoProperties.class);
  53.        
  54.         /* ---- Lettura del cammino del file di configurazione ---- */
  55.         Properties propertiesReader = new Properties();
  56.         java.io.InputStream properties = null;
  57.         try{  
  58.             properties = RegistroServiziRemotoProperties.class.getResourceAsStream("/console.registroServiziRemoto.properties");
  59.             if(properties==null){
  60.                 throw new Exception("File '/console.registroServiziRemoto.properties' not found");
  61.             }
  62.             propertiesReader.load(properties);
  63.         }catch(Exception e) {
  64.             this.log.error("Riscontrato errore durante la lettura del file 'console.registroServiziRemoto.properties': \n\n"+e.getMessage());
  65.             throw new Exception("ConsoleProperties initialize error: "+e.getMessage());
  66.         }finally{
  67.             try{
  68.                 if(properties!=null)
  69.                     properties.close();
  70.             }catch(Exception er){
  71.                 // close
  72.             }
  73.         }

  74.         this.reader = new RegistroServiziRemotoInstanceProperties(propertiesReader, this.log, confDir,confPropertyName,confLocalPathPrefix);
  75.     }


  76.     /**
  77.      * Il Metodo si occupa di inizializzare il propertiesReader
  78.      *
  79.      *
  80.      */
  81.     public static boolean initialize(String confDir, String confPropertyName, String confLocalPathPrefix,Logger log){

  82.         try {
  83.             RegistroServiziRemotoProperties.registroServiziRemotoProperties = new RegistroServiziRemotoProperties(confDir,confPropertyName,confLocalPathPrefix,log);    
  84.             return true;
  85.         }
  86.         catch(Exception e) {
  87.             log.error("Inizializzazione fallita: "+e.getMessage(),e);
  88.             return false;
  89.         }
  90.     }
  91.    
  92.     /**
  93.      * Ritorna l'istanza di questa classe
  94.      *
  95.      * @return Istanza di ClassNameProperties
  96.      *
  97.      */
  98.     public static RegistroServiziRemotoProperties getInstance() throws OpenSPCoop2ConfigurationException{
  99.         if(RegistroServiziRemotoProperties.registroServiziRemotoProperties==null){
  100.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  101.             synchronized (RegistroServiziRemotoProperties.class) {
  102.                 throw new OpenSPCoop2ConfigurationException("DatasourceProperties non inizializzato");
  103.             }
  104.         }
  105.         return RegistroServiziRemotoProperties.registroServiziRemotoProperties;
  106.     }
  107.    
  108.     public static void updateLocalImplementation(Properties prop){
  109.         RegistroServiziRemotoProperties.registroServiziRemotoProperties.reader.setLocalObjectImplementation(prop);
  110.     }








  111.     /* ********  M E T O D I  ******** */

  112.     private String readProperty(boolean required,String property) throws UtilsException{
  113.         String tmp = this.reader.getValueConvertEnvProperties(property);
  114.         if(tmp==null){
  115.             if(required){
  116.                 throw new UtilsException("Property ["+property+"] not found");
  117.             }
  118.             else{
  119.                 return null;
  120.             }
  121.         }else{
  122.             return tmp.trim();
  123.         }
  124.     }

  125.    
  126.    
  127.     public String getTipoRegistroServiziRemoto() throws UtilsException{
  128.         return this.readProperty(true, "registroServizi.tipo");
  129.     }

  130.    
  131.     /* ----- RegistroServiziXML -------- */
  132.    
  133.     public String getRegistroServiziXML_Location() throws UtilsException{
  134.         return this.readProperty(CostantiConfigurazione.REGISTRO_XML.equals(this.getTipoRegistroServiziRemoto()), "registroServizi.xml.location");
  135.     }
  136.    
  137.    
  138.    
  139.     /* ----- RegistroServiziWS -------- */
  140.    
  141.     public String getRegistroServiziWS_Location() throws UtilsException{
  142.         return this.readProperty(CostantiConfigurazione.REGISTRO_WS.equals(this.getTipoRegistroServiziRemoto()), "registroServizi.ws.location");
  143.     }
  144.    
  145.     public String getRegistroServiziWS_Username() throws UtilsException{
  146.         return this.readProperty(false, "registroServizi.ws.username");
  147.     }
  148.    
  149.     public String getRegistroServiziWS_Password() throws UtilsException{
  150.         return this.readProperty(false, "registroServizi.ws.password");
  151.     }
  152.    
  153.    
  154.    
  155.     /* ----- RegistroServiziDB -------- */
  156.    
  157.     public String getRegistroServiziDB_DataSource() throws UtilsException{
  158.         return this.readProperty(CostantiConfigurazione.REGISTRO_DB.equals(this.getTipoRegistroServiziRemoto()), "registroServizi.db.dataSource");
  159.     }
  160.    
  161.     public Properties getRegistroServiziDB_DataSourceContext() throws UtilsException{
  162.         return this.reader.readPropertiesConvertEnvProperties("registroServizi.db.context.");
  163.     }
  164.    
  165.     public String getRegistroServiziDB_TipoDatabase() throws UtilsException{
  166.         return this.readProperty(CostantiConfigurazione.REGISTRO_DB.equals(this.getTipoRegistroServiziRemoto()), "registroServizi.db.tipo");
  167.     }
  168.    
  169.    
  170.     /* ----- RegistroServiziUDDI -------- */
  171.    
  172.     public String getRegistroServiziUDDI_InquiryURL() throws UtilsException{
  173.         return this.readProperty(CostantiConfigurazione.REGISTRO_UDDI.equals(this.getTipoRegistroServiziRemoto()), "registroServizi.uddi.inquiryUrl");
  174.     }
  175.    
  176.     public String getRegistroServiziUDDI_Username() throws UtilsException{
  177.         return this.readProperty(false, "registroServizi.uddi.username");
  178.     }
  179.    
  180.     public String getRegistroServiziUDDI_Password() throws UtilsException{
  181.         return this.readProperty(false, "registroServizi.uddi.password");
  182.     }
  183.    
  184.    
  185.     /* ----- RegistroServiziWEB -------- */
  186.    
  187.     public String getRegistroServiziWEB_URLPrefix() throws UtilsException{
  188.         return this.readProperty(CostantiConfigurazione.REGISTRO_UDDI.equals(this.getTipoRegistroServiziRemoto()), "registroServizi.web.urlPrefix");
  189.     }

  190. }