AlarmFactory.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.alarm;

  21. import java.lang.reflect.Method;

  22. import org.openspcoop2.core.commons.dao.DAOFactory;
  23. import org.openspcoop2.monitor.sdk.exceptions.AlarmException;
  24. import org.openspcoop2.utils.LoggerWrapperFactory;
  25. import org.openspcoop2.utils.Utilities;
  26. import org.slf4j.Logger;


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

  35.     public static IAlarm getAlarm(String idAllarme) throws AlarmException {
  36.         return getAlarm(LoggerWrapperFactory.getLogger(AlarmFactory.class), idAllarme);
  37.     }
  38.     public static IAlarm getAlarm(Logger log, String idAllarme) throws AlarmException {
  39.         try {
  40.             Class<?> c = Class.forName("org.openspcoop2.monitor.engine.alarm.AlarmManager");
  41.            
  42.             Class<?>[] paramTypes = new Class[3];
  43.             paramTypes[0] = String.class;
  44.             paramTypes[1] = Logger.class;
  45.             paramTypes[2] = DAOFactory.class;
  46.            
  47.             DAOFactory daoFactory = DAOFactory.getInstance(log);
  48.            
  49.             Object[] params = new Object[3];
  50.             params[0] = idAllarme;
  51.             params[1] = log;
  52.             params[2] = daoFactory;
  53.                        
  54.             Method m = c.getMethod("getAlarm", paramTypes);
  55.             return (IAlarm) m.invoke(Utilities.newInstance(c), params);
  56.         } catch (Exception e) {
  57.             throw new AlarmException (e.getMessage(),e);
  58.         }
  59.     }
  60.    
  61. }