FactoryDriverCreator.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.core.commons;

  21. import java.io.InputStream;
  22. import java.util.Properties;

  23. /**
  24.  * Questa classe imple
  25.  *
  26.  * @author Stefano Corallo (corallo@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public abstract class FactoryDriverCreator {

  31.     private String fileProperties;
  32.    
  33.     public String getFilePropertiesName() {
  34.         return this.fileProperties;
  35.     }

  36.     public void setFilePropertiesName(String fileProperties) {
  37.         this.fileProperties = fileProperties;
  38.     }

  39.     public FactoryDriverCreator(String fileProperties)
  40.     {
  41.     this.fileProperties = fileProperties;
  42.     }
  43.    
  44.     /**
  45.      * Ritorna l'istanza del driver
  46.      * @return Driver
  47.      * @throws Exception
  48.      */
  49.     public abstract IDriverWS getDriver() throws Exception;
  50.    
  51.     /**
  52.      * Legge le proprieta da un file properties
  53.      * @param fileProperties
  54.      * @return Properties
  55.      * @throws Exception
  56.      */
  57.     public Properties readProperties(String fileProperties) throws Exception
  58.     {
  59.     Properties prop = new Properties();
  60.     InputStream inProp = getClass().getClassLoader().getResourceAsStream(fileProperties);
  61.    
  62.     try {
  63.         prop.load(inProp);
  64.        
  65.         return new Properties(prop);
  66.        
  67.     } catch(Exception e) {
  68.        
  69.         throw new Exception(e);
  70.        
  71.     } finally {
  72.         try {
  73.         inProp.close();
  74.         } catch (Exception e) {}
  75.     }
  76.     }
  77. }