BasicFilter.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.monitor.sdk.condition.Context;
  22. import org.openspcoop2.monitor.sdk.condition.StatisticsContext;
  23. import org.openspcoop2.monitor.sdk.exceptions.SearchException;
  24. import org.openspcoop2.monitor.sdk.plugins.ISearchArguments;
  25. import org.openspcoop2.monitor.sdk.plugins.ISearchProcessing;
  26. import org.openspcoop2.monitor.sdk.plugins.IStatisticProcessing;

  27. import org.openspcoop2.utils.LoggerWrapperFactory;
  28. import org.slf4j.Logger;

  29. /**
  30.  * BasicFilter
  31.  *
  32.  * @author Poli Andrea (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class BasicFilter implements IDynamicFilter{
  37.    
  38.     private static Logger log = LoggerWrapperFactory.getLogger(BasicFilter.class);
  39.    
  40.     private String tipoPlugin;
  41.     private String tipo;
  42.     private String className;
  43.    
  44.     protected BasicFilter(String tipoPlugin, String tipo, String className) {
  45.         this.tipoPlugin = tipoPlugin;
  46.         this.tipo = tipo;
  47.         this.className = className;
  48.     }
  49.    
  50.     @Override
  51.     public org.openspcoop2.monitor.sdk.condition.IFilter createConditionFilter(Context context) throws SearchException {
  52.         try{
  53.             IDynamicLoader bl = DynamicFactory.getInstance().newDynamicLoader(this.tipoPlugin, this.tipo, this.className, BasicFilter.log);
  54.            
  55.             Object obj = bl.newInstance();
  56.            
  57.             if(obj instanceof ISearchProcessing){
  58.                 return ((ISearchProcessing) obj).createSearchFilter(context);
  59.             }else if(obj instanceof IStatisticProcessing && context instanceof StatisticsContext    ){
  60.                     return ((IStatisticProcessing) obj).createSearchFilter((StatisticsContext)context);
  61.             }else{
  62.                 String iface = ISearchArguments.class.getName();
  63.                 throw new Exception("La classe ["+this.className+"] non implementa l'interfaccia ["+iface+"]");
  64.             }
  65.         }catch(ClassNotFoundException cnfe){
  66.             throw new SearchException("Impossibile caricare il plugin. La classe indicata ["+this.className+"] non esiste.");
  67.         }catch (Exception e) {
  68.             BasicFilter.log.error(e.getMessage(),e);
  69.             throw new SearchException("Si e' verificato un errore: "+e.getMessage());
  70.         }
  71.     }

  72. }