XMLProperties.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.generic_project.dao.xml;

  21. import org.openspcoop2.generic_project.beans.IProjectInfo;
  22. import org.openspcoop2.generic_project.exception.ServiceException;
  23. import org.openspcoop2.generic_project.utils.LoaderProperties;
  24. import org.openspcoop2.generic_project.utils.Utilities;
  25. import org.openspcoop2.utils.resources.ClassLoaderUtilities;

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

  34.     public XMLProperties(IProjectInfo project) throws ServiceException {
  35.         super(Utilities.normalizedProjectName(project.getProjectName())+".dao.xml.properties");
  36.     }

  37.     public static XMLProperties getInstance(IProjectInfo project) throws ServiceException {
  38.         return new XMLProperties(project);
  39.     }
  40.    
  41.     @SuppressWarnings("unchecked")
  42.     public <CRUD> Class<CRUD> getServiceCRUDClass(String object) throws ServiceException{
  43.         try{
  44.             String p = this.properties.getProperty("service.crud."+object);
  45.             if(p!=null){
  46.                 p = p.trim();
  47.             }else{
  48.                 throw new ServiceException("Property 'service.crud."+object+"' not found in the file properties "+this.filePropertiesName);
  49.             }
  50.             Class<?> serviceClass = Class.forName(p);
  51.             return (Class<CRUD>) serviceClass;
  52.         }catch(Exception e){
  53.             throw new ServiceException("Loading service CRUD class failed: "+e.getMessage(),e);
  54.         }
  55.     }
  56.     @SuppressWarnings("unchecked")
  57.     public <CRUD> CRUD getServiceCRUD(String object) throws ServiceException{
  58.         try{
  59.             return (CRUD) ClassLoaderUtilities.newInstance(getServiceCRUDClass(object));
  60.         }catch(Exception e){
  61.             throw new ServiceException("Loading service CRUD class failed: "+e.getMessage(),e);
  62.         }
  63.     }
  64.    
  65.     @SuppressWarnings("unchecked")
  66.     public <SEARCH> Class<SEARCH> getServiceSearchClass(String object) throws ServiceException{
  67.         try{
  68.             String p = this.properties.getProperty("service.search."+object);
  69.             if(p!=null){
  70.                 p = p.trim();
  71.             }else{
  72.                 throw new ServiceException("Property 'service.search."+object+"' not found in the file properties "+this.filePropertiesName);
  73.             }
  74.             Class<?> serviceClass = Class.forName(p);
  75.             return (Class<SEARCH>) serviceClass;
  76.         }catch(Exception e){
  77.             throw new ServiceException("Loading service Search class failed: "+e.getMessage(),e);
  78.         }
  79.     }
  80.     @SuppressWarnings("unchecked")
  81.     public <SEARCH> SEARCH getServiceSearch(String object) throws ServiceException{
  82.         try{
  83.             return (SEARCH) ClassLoaderUtilities.newInstance(getServiceSearchClass(object));
  84.         }catch(Exception e){
  85.             throw new ServiceException("Loading service Search class failed: "+e.getMessage(),e);
  86.         }
  87.     }
  88. }