DynamicFactory.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.monitor.engine.dynamic;

  21. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  22. import org.openspcoop2.monitor.sdk.exceptions.SearchException;
  23. import org.slf4j.Logger;

  24. /**
  25.  * DynamicFactory
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class DynamicFactory {

  32.     private static DynamicFactory basicLoaderFactory;
  33.     private static synchronized void initialize() {
  34.         if(basicLoaderFactory==null){
  35.             basicLoaderFactory = new DynamicFactory();
  36.         }
  37.     }
  38.     public static DynamicFactory getInstance() {
  39.         if(basicLoaderFactory==null){
  40.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  41.             synchronized (DynamicFactory.class) {
  42.                 initialize();
  43.             }
  44.         }
  45.         return basicLoaderFactory;
  46.     }
  47.    
  48.    
  49.     private PluginLoader pluginLoader = null;
  50.     private DynamicFactory() {
  51.         this.pluginLoader = PluginLoader.getInstance();
  52.     }
  53.    
  54.     public IDynamicLoader newDynamicLoader(TipoPlugin tipoPlugin, String tipo, String className,Logger log) throws SearchException{
  55.         return newDynamicLoader(tipoPlugin.getValue(), tipo, className, log);
  56.     }
  57.     public IDynamicLoader newDynamicLoader(String tipoPlugin, String tipo, String className,Logger log) throws SearchException{
  58.        
  59.         try {
  60.             return new BasicLoader(tipoPlugin, tipo, className, this.pluginLoader.getDynamicClass(className, tipoPlugin, tipo), log);
  61.         }catch(Exception e) {
  62.             throw new SearchException(e.getMessage(),e);
  63.         }
  64.        
  65.     }
  66.    
  67.     public IDynamicFilter newDynamicFilter(TipoPlugin tipoPlugin, String tipo, String className,Logger log) {
  68.         return newDynamicFilter(tipoPlugin.getValue(), tipo, className, log);
  69.     }
  70.     public IDynamicFilter newDynamicFilter(String tipoPlugin, String tipo, String className,Logger log) {
  71.         if(log!=null) {
  72.             // unused
  73.         }
  74.         return new BasicFilter(tipoPlugin, tipo, className);
  75.     }
  76.    
  77.     public IDynamicValidator newDynamicValidator(TipoPlugin tipoPlugin, String tipo, String className,Logger log) {
  78.         return newDynamicValidator(tipoPlugin.getValue(), tipo, className, log);
  79.     }
  80.     public IDynamicValidator newDynamicValidator(String tipoPlugin, String tipo, String className,Logger log) {
  81.         if(log!=null) {
  82.             // unused
  83.         }
  84.         return new BasicValidator(tipoPlugin, tipo, className);
  85.     }
  86. }