FilterFactory.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.sdk.condition;

  21. import java.lang.reflect.Constructor;

  22. import org.openspcoop2.utils.TipiDatabase;

  23. import org.openspcoop2.monitor.sdk.constants.StatisticType;
  24. import org.openspcoop2.monitor.sdk.exceptions.FilterFactoryException;
  25. import org.openspcoop2.monitor.sdk.statistic.IStatistic;

  26. /**
  27.  * FilterFactory
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class FilterFactory {
  34.    
  35.     public static IStatisticFilter newFilterStatisticRepository(TipiDatabase tipiDatabase,StatisticType statisticType) throws FilterFactoryException {
  36.         try {
  37.             Class<?> c = Class.forName("org.openspcoop2.monitor.engine.condition.FilterStatisticRepositoryImpl");
  38.             Constructor<?> constructor = c.getConstructor(TipiDatabase.class,StatisticType.class);
  39.             return (IStatisticFilter) constructor.newInstance(tipiDatabase,statisticType);
  40.         } catch (Exception e) {
  41.             throw new FilterFactoryException (e);
  42.         }
  43.     }
  44.     public static IStatisticFilter newFilterStatisticRepository(StatisticsContext searchContext) throws FilterFactoryException {
  45.         try {
  46.             TipiDatabase tipiDatabase = searchContext.getDatabaseType();
  47.             if(tipiDatabase==null)
  48.                 throw new Exception("Field 'TipoDatabase' undefinded in SearchContext");
  49.             StatisticType statisticType = searchContext.getStatisticType();
  50.             if(statisticType==null)
  51.                 throw new Exception("Field 'StatisticType' undefinded in SearchContext");
  52.             return newFilterStatisticRepository(tipiDatabase,statisticType);
  53.         } catch (Exception e) {
  54.             throw new FilterFactoryException (e);
  55.         }
  56.     }
  57.    
  58.    
  59.     public static IFilter newFilterTransactionRepository(TipiDatabase tipiDatabase) throws FilterFactoryException {
  60.         try {
  61.             Class<?> c = Class.forName("org.openspcoop2.monitor.engine.condition.FilterTransactionRepositoryImpl");
  62.             Constructor<?> constructor = c.getConstructor(TipiDatabase.class);
  63.             return (IFilter) constructor.newInstance(tipiDatabase);
  64.         } catch (Exception e) {
  65.             throw new FilterFactoryException (e);
  66.         }
  67.     }
  68.     public static IFilter newFilterTransactionRepository(Context searchContext) throws FilterFactoryException {
  69.         try {
  70.             TipiDatabase tipiDatabase = searchContext.getDatabaseType();
  71.             if(tipiDatabase==null)
  72.                 throw new Exception("Field 'TipoDatabase' undefinded in SearchContext");
  73.             return newFilterTransactionRepository(tipiDatabase);
  74.         } catch (Exception e) {
  75.             throw new FilterFactoryException (e);
  76.         }
  77.     }
  78.     public static IFilter newFilterTransactionRepository(IStatistic context) throws FilterFactoryException {
  79.         try {
  80.             TipiDatabase tipiDatabase = context.getDatabaseType();
  81.             if(tipiDatabase==null)
  82.                 throw new Exception("Field 'TipoDatabase' undefinded in IStatistic");
  83.             return newFilterTransactionRepository(tipiDatabase);
  84.         } catch (Exception e) {
  85.             throw new FilterFactoryException (e);
  86.         }
  87.     }

  88. }