DriverRegistroServiziWSInitUtilities.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.registry.driver.utils;

  21. import java.lang.reflect.Constructor;
  22. import java.lang.reflect.Method;

  23. import org.openspcoop2.core.registry.driver.BeanUtilities;
  24. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  25. import org.slf4j.Logger;

  26. /**
  27.  * DriverRegistroServiziWSInitUtilities
  28.  *
  29.  * @author Andrea Poli (poli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class DriverRegistroServiziWSInitUtilities {

  34.     public static BeanUtilities newInstance(String url,String username,String password,Logger log) throws DriverRegistroServiziException{
  35.         try{
  36.             // Serve per poter compilare tutto il progetto senza gli stub per non creare dipendenza circolare
  37.             Class<?> cDriver = Class.forName("org.openspcoop2.core.registry.driver.ws.DriverRegistroServiziWS");
  38.             Constructor<?> constructor = null;
  39.             if(username!=null){
  40.                 constructor = cDriver.getConstructor(String.class,String.class,String.class,Logger.class);
  41.             }else{
  42.                 constructor = cDriver.getConstructor(String.class,Logger.class);
  43.             }
  44.             BeanUtilities driver = null;
  45.             if(username!=null){
  46.                 driver = (BeanUtilities) constructor.newInstance(url,username,password,log);
  47.             }else{
  48.                 driver = (BeanUtilities) constructor.newInstance(url,log);
  49.             }
  50.             Method mIsCreate = driver.getClass().getMethod("isCreate");
  51.             boolean isCreate = (Boolean) mIsCreate.invoke(driver);
  52.             if(isCreate)
  53.                 log.info("Inizializzato Registro dei Servizi WS");
  54.             else
  55.                 throw new Exception("RegistroServizi WS non inizializzato");
  56.             return driver;
  57.         }catch(Exception e){
  58.             throw new DriverRegistroServiziException(e.getMessage(),e);
  59.         }
  60.     }
  61.    
  62. }