ManagerUtils.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.protocol.utils;

  21. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  22. import org.openspcoop2.protocol.sdk.ProtocolException;

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

  31.     public static String getDefaultProtocol() throws ProtocolException{
  32.         try{
  33.             Class<?> cProtocolFactoryManager = Class.forName("org.openspcoop2.protocol.engine.ProtocolFactoryManager");
  34.             Object protocolFactoryManager = cProtocolFactoryManager.getMethod("getInstance").invoke(null);
  35.            
  36.             IProtocolFactory<?> pf = (IProtocolFactory<?>) cProtocolFactoryManager.getMethod("getDefaultProtocolFactory").invoke(protocolFactoryManager);
  37.            
  38.             return pf.getProtocol();
  39.                        
  40.         }catch(Exception e){
  41.             throw new ProtocolException(e.getMessage(),e);
  42.         }
  43.     }
  44.    
  45.     public static String getProtocolByOrganizationType(String type) throws ProtocolException{
  46.         try{
  47.             Class<?> cProtocolFactoryManager = Class.forName("org.openspcoop2.protocol.engine.ProtocolFactoryManager");
  48.             Object protocolFactoryManager = cProtocolFactoryManager.getMethod("getInstance").invoke(null);
  49.            
  50.             String protocollo = (String) cProtocolFactoryManager.getMethod("getProtocolByOrganizationType",String.class).invoke(protocolFactoryManager,type);
  51.            
  52.             return protocollo;
  53.                        
  54.         }catch(Exception e){
  55.             throw new ProtocolException(e.getMessage(),e);
  56.         }
  57.     }
  58.    
  59.     public static String getDefaultOrganizationType(String protocollo) throws ProtocolException{
  60.         try{
  61.             Class<?> cProtocolFactoryManager = Class.forName("org.openspcoop2.protocol.engine.ProtocolFactoryManager");
  62.             Object protocolFactoryManager = cProtocolFactoryManager.getMethod("getInstance").invoke(null);
  63.            
  64.             IProtocolFactory<?> pf = (IProtocolFactory<?>) cProtocolFactoryManager.getMethod("getProtocolFactoryByName",String.class).invoke(protocolFactoryManager,protocollo);
  65.            
  66.             return pf.createProtocolConfiguration().getTipoSoggettoDefault();
  67.                        
  68.         }catch(Exception e){
  69.             throw new ProtocolException(e.getMessage(),e);
  70.         }
  71.     }
  72.    
  73.     public static String getDefaultServiceType(String protocollo) throws ProtocolException{
  74.         try{
  75.             Class<?> cProtocolFactoryManager = Class.forName("org.openspcoop2.protocol.engine.ProtocolFactoryManager");
  76.             Object protocolFactoryManager = cProtocolFactoryManager.getMethod("getInstance").invoke(null);
  77.            
  78.             IProtocolFactory<?> pf = (IProtocolFactory<?>) cProtocolFactoryManager.getMethod("getProtocolFactoryByName",String.class).invoke(protocolFactoryManager,protocollo);
  79.            
  80.             return pf.createProtocolConfiguration().getTipoServizioDefault(pf.createProtocolConfiguration().getDefaultServiceBindingConfiguration(null).getDefaultBinding());
  81.                        
  82.         }catch(Exception e){
  83.             throw new ProtocolException(e.getMessage(),e);
  84.         }
  85.     }
  86.    
  87. }