ConfigurazionePdD.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.pdd.config;

  21. import java.io.File;
  22. import java.lang.reflect.Method;
  23. import java.sql.Connection;
  24. import java.util.ArrayList;
  25. import java.util.Iterator;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Properties;

  29. import org.openspcoop2.core.allarmi.Allarme;
  30. import org.openspcoop2.core.allarmi.utils.FiltroRicercaAllarmi;
  31. import org.openspcoop2.core.byok.IDriverBYOKConfig;
  32. import org.openspcoop2.core.config.AccessoConfigurazione;
  33. import org.openspcoop2.core.config.AccessoConfigurazionePdD;
  34. import org.openspcoop2.core.config.AccessoDatiAttributeAuthority;
  35. import org.openspcoop2.core.config.AccessoDatiAutenticazione;
  36. import org.openspcoop2.core.config.AccessoDatiAutorizzazione;
  37. import org.openspcoop2.core.config.AccessoDatiGestioneToken;
  38. import org.openspcoop2.core.config.AccessoDatiKeystore;
  39. import org.openspcoop2.core.config.AccessoDatiRichieste;
  40. import org.openspcoop2.core.config.AccessoRegistro;
  41. import org.openspcoop2.core.config.Configurazione;
  42. import org.openspcoop2.core.config.Credenziali;
  43. import org.openspcoop2.core.config.GenericProperties;
  44. import org.openspcoop2.core.config.GestioneErrore;
  45. import org.openspcoop2.core.config.PortaApplicativa;
  46. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativo;
  47. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativoConnettore;
  48. import org.openspcoop2.core.config.PortaDelegata;
  49. import org.openspcoop2.core.config.PortaDelegataServizioApplicativo;
  50. import org.openspcoop2.core.config.ProprietaOggetto;
  51. import org.openspcoop2.core.config.RoutingTable;
  52. import org.openspcoop2.core.config.ServizioApplicativo;
  53. import org.openspcoop2.core.config.Soggetto;
  54. import org.openspcoop2.core.config.StatoServiziPdd;
  55. import org.openspcoop2.core.config.SystemProperties;
  56. import org.openspcoop2.core.config.TrasformazioneRegolaRichiesta;
  57. import org.openspcoop2.core.config.TrasformazioneRegolaRisposta;
  58. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  59. import org.openspcoop2.core.config.constants.CredenzialeTipo;
  60. import org.openspcoop2.core.config.constants.PluginCostanti;
  61. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  62. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  63. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  64. import org.openspcoop2.core.config.driver.FiltroRicercaPorteApplicative;
  65. import org.openspcoop2.core.config.driver.FiltroRicercaPorteDelegate;
  66. import org.openspcoop2.core.config.driver.FiltroRicercaServiziApplicativi;
  67. import org.openspcoop2.core.config.driver.FiltroRicercaSoggetti;
  68. import org.openspcoop2.core.config.driver.IDriverConfigurazioneGet;
  69. import org.openspcoop2.core.config.driver.db.DriverConfigurazioneDB;
  70. import org.openspcoop2.core.config.driver.xml.DriverConfigurazioneXML;
  71. import org.openspcoop2.core.constants.TipoPdD;
  72. import org.openspcoop2.core.controllo_traffico.AttivazionePolicy;
  73. import org.openspcoop2.core.controllo_traffico.ConfigurazioneGenerale;
  74. import org.openspcoop2.core.controllo_traffico.ConfigurazionePolicy;
  75. import org.openspcoop2.core.controllo_traffico.ElencoIdPolicy;
  76. import org.openspcoop2.core.controllo_traffico.ElencoIdPolicyAttive;
  77. import org.openspcoop2.core.controllo_traffico.IdActivePolicy;
  78. import org.openspcoop2.core.controllo_traffico.IdPolicy;
  79. import org.openspcoop2.core.controllo_traffico.beans.UniqueIdentifierUtilities;
  80. import org.openspcoop2.core.controllo_traffico.constants.TipoRisorsaPolicyAttiva;
  81. import org.openspcoop2.core.id.IDConnettore;
  82. import org.openspcoop2.core.id.IDGenericProperties;
  83. import org.openspcoop2.core.id.IDPortaApplicativa;
  84. import org.openspcoop2.core.id.IDPortaDelegata;
  85. import org.openspcoop2.core.id.IDServizio;
  86. import org.openspcoop2.core.id.IDServizioApplicativo;
  87. import org.openspcoop2.core.id.IDSoggetto;
  88. import org.openspcoop2.core.mapping.DBMappingUtils;
  89. import org.openspcoop2.core.mapping.MappingErogazionePortaApplicativa;
  90. import org.openspcoop2.core.mapping.MappingFruizionePortaDelegata;
  91. import org.openspcoop2.core.plugins.IdPlugin;
  92. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  93. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  94. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  95. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  96. import org.openspcoop2.monitor.engine.dynamic.IRegistroPluginsReader;
  97. import org.openspcoop2.monitor.sdk.alarm.AlarmStatus;
  98. import org.openspcoop2.monitor.sdk.alarm.IAlarm;
  99. import org.openspcoop2.pdd.core.CostantiPdD;
  100. import org.openspcoop2.pdd.core.byok.DriverBYOK;
  101. import org.openspcoop2.pdd.core.byok.DriverBYOKUtilities;
  102. import org.openspcoop2.pdd.core.controllo_traffico.policy.config.PolicyConfiguration;
  103. import org.openspcoop2.pdd.core.dynamic.Template;
  104. import org.openspcoop2.pdd.core.dynamic.TemplateSource;
  105. import org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione;
  106. import org.openspcoop2.protocol.engine.ConfigurazioneFiltroServiziApplicativi;
  107. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  108. import org.openspcoop2.protocol.engine.constants.Costanti;
  109. import org.openspcoop2.protocol.registry.RegistroServiziManager;
  110. import org.openspcoop2.protocol.registry.RegistroServiziReader;
  111. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  112. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  113. import org.openspcoop2.utils.LoggerWrapperFactory;
  114. import org.openspcoop2.utils.NameValue;
  115. import org.openspcoop2.utils.SemaphoreLock;
  116. import org.openspcoop2.utils.UtilsException;
  117. import org.openspcoop2.utils.cache.Cache;
  118. import org.openspcoop2.utils.cache.CacheAlgorithm;
  119. import org.openspcoop2.utils.cache.CacheResponse;
  120. import org.openspcoop2.utils.cache.CacheType;
  121. import org.openspcoop2.utils.certificate.ArchiveLoader;
  122. import org.openspcoop2.utils.certificate.ArchiveType;
  123. import org.openspcoop2.utils.certificate.CertificateInfo;
  124. import org.openspcoop2.utils.crypt.CryptConfig;
  125. import org.openspcoop2.utils.date.DateManager;
  126. import org.openspcoop2.utils.resources.FileSystemUtilities;
  127. import org.slf4j.Logger;



  128. /**
  129.  * Classe utilizzata per effettuare query a registri di servizio di openspcoop.
  130.  * E' possibile indicare piu' di una sorgente e/o una cache
  131.  *
  132.  *
  133.  * @author Poli Andrea (apoli@link.it)
  134.  * @author $Author$
  135.  * @version $Rev$, $Date$
  136.  */

  137. public class ConfigurazionePdD  {
  138.    
  139.     /** Fonti su cui effettuare le query:
  140.      * - CACHE
  141.      * - configurazione
  142.      */
  143.     private Cache cache = null;
  144.     public Cache getCache() {
  145.         return this.cache;
  146.     }

  147.     private IDriverConfigurazioneGet driverConfigurazionePdD;

  148.     private boolean useConnectionPdD = false;
  149.     private String tipoDatabase = null;

  150.     /** Logger utilizzato per debug. */
  151.     private Logger logger = null;
  152.     private void logDebug(String msg) {
  153.         this.logDebug(msg, null);
  154.     }
  155.     private void logDebug(String msg, Throwable e) {
  156.         if(this.logger!=null) {
  157.             if(e!=null) {
  158.                 this.logger.debug(msg, e);
  159.             }
  160.             else {
  161.                 this.logger.debug(msg);
  162.             }
  163.         }
  164.     }
  165.     private void logInfo(String msg) {
  166.         this.logInfo(msg, null);
  167.     }
  168.     private void logInfo(String msg, Throwable e) {
  169.         if(this.logger!=null) {
  170.             if(e!=null) {
  171.                 this.logger.info(msg, e);
  172.             }
  173.             else {
  174.                 this.logger.info(msg);
  175.             }
  176.         }
  177.     }
  178.     private void logWarn(String msg) {
  179.         this.logWarn(msg, null);
  180.     }
  181.     private void logWarn(String msg, Throwable e) {
  182.         if(this.logger!=null) {
  183.             if(e!=null) {
  184.                 this.logger.warn(msg, e);
  185.             }
  186.             else {
  187.                 this.logger.warn(msg);
  188.             }
  189.         }
  190.     }
  191.     private void logError(String msg) {
  192.         this.logError(msg, null);
  193.     }
  194.     private void logError(String msg, Throwable e) {
  195.         if(this.logger!=null) {
  196.             if(e!=null) {
  197.                 this.logger.error(msg, e);
  198.             }
  199.             else {
  200.                 this.logger.error(msg);
  201.             }
  202.         }
  203.     }

  204.     private static String notFoundClassName = DriverConfigurazioneNotFound.class.getName()+"";
  205.     private static String excClassName = DriverConfigurazioneException.class.getName()+"";

  206.     /** Variabili statiche contenenti le configurazioni
  207.      *  - ConfigurazioneGenerale
  208.      *  - GestioneErrore
  209.      *  - RoutingTable
  210.      *  - AccessoRegistro
  211.      */
  212.     private static Configurazione configurazioneGeneralePdD = null;
  213.     private static GestioneErrore gestioneErroreComponenteCooperazione = null;
  214.     private static GestioneErrore gestioneErroreComponenteIntegrazione = null;
  215.     private static RoutingTable routingTable = null;
  216.    
  217.     private static AccessoRegistro accessoRegistro = null;
  218.     public static void setAccessoRegistro(AccessoRegistro accessoRegistro) {
  219.         ConfigurazionePdD.accessoRegistro = accessoRegistro;
  220.     }
  221.     private static AccessoConfigurazione accessoConfigurazione = null;
  222.     public static void setAccessoConfigurazione(AccessoConfigurazione accessoConfigurazione) {
  223.         ConfigurazionePdD.accessoConfigurazione = accessoConfigurazione;
  224.     }
  225.     private static AccessoDatiAutorizzazione accessoDatiAutorizzazione = null;
  226.     public static void setAccessoDatiAutorizzazione(AccessoDatiAutorizzazione accessoDatiAutorizzazione) {
  227.         ConfigurazionePdD.accessoDatiAutorizzazione = accessoDatiAutorizzazione;
  228.     }
  229.     private static AccessoDatiAutenticazione accessoDatiAutenticazione = null;
  230.     public static void setAccessoDatiAutenticazione(AccessoDatiAutenticazione accessoDatiAutenticazione) {
  231.         ConfigurazionePdD.accessoDatiAutenticazione = accessoDatiAutenticazione;
  232.     }
  233.     private static AccessoDatiGestioneToken accessoDatiGestioneToken = null;
  234.     public static void setAccessoDatiGestioneToken(AccessoDatiGestioneToken accessoDatiGestioneToken) {
  235.         ConfigurazionePdD.accessoDatiGestioneToken = accessoDatiGestioneToken;
  236.     }
  237.     private static AccessoDatiAttributeAuthority accessoDatiAttributeAuthority = null;
  238.     public static void setAccessoDatiAttributeAuthority(AccessoDatiAttributeAuthority accessoDatiAttributeAuthority) {
  239.         ConfigurazionePdD.accessoDatiAttributeAuthority = accessoDatiAttributeAuthority;
  240.     }
  241.     private static AccessoDatiKeystore accessoDatiKeystore = null;
  242.     public static void setAccessoDatiKeystore(AccessoDatiKeystore accessoDatiKeystore) {
  243.         ConfigurazionePdD.accessoDatiKeystore = accessoDatiKeystore;
  244.     }
  245.     private static AccessoDatiRichieste accessoDatiRichieste = null;
  246.     public static void setAccessoDatiRichieste(AccessoDatiRichieste accessoDatiRichieste) {
  247.         ConfigurazionePdD.accessoDatiRichieste = accessoDatiRichieste;
  248.     }

  249.     /** ConfigurazioneDinamica */
  250.     private boolean configurazioneDinamica = false;

  251.     /** OpenSPCoop Properties */
  252.     private OpenSPCoop2Properties openspcoopProperties = null;

  253.     /** ConfigLocalProperties */
  254.     private ConfigLocalProperties configLocalProperties = null;
  255.    
  256.     /** ConfigurazionePdD_controlloTraffico */
  257.     private ConfigurazionePdD_controlloTraffico configurazionePdD_controlloTraffico = null;
  258.    
  259.     /** ConfigurazionePdD_plugins */
  260.     private ConfigurazionePdD_plugins configurazionePdD_plugins = null;
  261.     private ConfigurazionePdD_registroPlugins configurazionePdD_registroPlugins = null;

  262.     /** ConfigurazionePdD_allarmi */
  263.     private ConfigurazionePdD_allarmi configurazionePdD_allarmi = null;
  264.    
  265.     /** Configurazione token con https */
  266.     private Boolean _tokenWithHttpsEnabledInitialized = null;
  267.     private boolean _tokenWithHttpsEnabled = false;
  268.     private synchronized void initializeTokenWithHttpsEnabled()throws DriverConfigurazioneException {
  269.         if(this._tokenWithHttpsEnabledInitialized==null) {
  270.             // Inizializzo parametri relativi al protocollo
  271.             // basta un protocollo che lo supporta per doverli cercare anche con la funzionalita' abilitata
  272.             try {
  273.                 this._tokenWithHttpsEnabled = false;
  274.                 for(IProtocolFactory<?> protocolFactory: ProtocolFactoryManager.getInstance().getProtocolFactories().values()) {
  275.                     if(protocolFactory.createProtocolConfiguration().isSupportatoAutenticazioneApplicativiHttpsConToken()) {
  276.                         this._tokenWithHttpsEnabled = true;
  277.                         break;
  278.                     }
  279.                 }
  280.                 this._tokenWithHttpsEnabledInitialized = true;
  281.             }catch(Throwable t) {
  282.                 throw new DriverConfigurazioneException(t.getMessage(),t);
  283.             }
  284.         }
  285.     }
  286.     private boolean isTokenWithHttpsEnabled() throws DriverConfigurazioneException {
  287.         if(this._tokenWithHttpsEnabledInitialized==null) {
  288.             initializeTokenWithHttpsEnabled();
  289.         }
  290.         return this._tokenWithHttpsEnabled;
  291.     }


  292.     /* --------------- Cache --------------------*/
  293.     public boolean isCacheAbilitata(){
  294.         return this.cache!=null;
  295.     }
  296.     public void resetCache() throws DriverConfigurazioneException{
  297.         if(this.cache!=null){
  298.             try{
  299.                 this.cache.clear();
  300.             }catch(Exception e){
  301.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  302.             }
  303.         }
  304.     }
  305.     public String printStatsCache(String separator) throws DriverConfigurazioneException{
  306.         if(this.cache!=null){
  307.             try{
  308.                 return this.cache.printStats(separator);
  309.             }catch(Exception e){
  310.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  311.             }
  312.         }else{
  313.             throw new DriverConfigurazioneException("Cache non abilitata");
  314.         }
  315.     }
  316.     public void abilitaCache() throws DriverConfigurazioneException{
  317.         if(this.cache!=null)
  318.             throw new DriverConfigurazioneException("Cache gia' abilitata");
  319.         else{
  320.             try{
  321.                 this.cache = new Cache(CacheType.JCS, CostantiConfigurazione.CACHE_CONFIGURAZIONE_PDD); // lascio JCS come default abilitato via jmx
  322.                 this.cache.build();
  323.             }catch(Exception e){
  324.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  325.             }
  326.         }
  327.     }
  328.     public void abilitaCache(Long dimensioneCache,Boolean algoritmoCacheLRU,Long itemIdleTime,Long itemLifeSecond, CryptConfig config) throws DriverConfigurazioneException{
  329.         if(this.cache!=null)
  330.             throw new DriverConfigurazioneException("Cache gia' abilitata");
  331.         else{
  332.             try{
  333.                 org.openspcoop2.core.config.Cache configurazioneCache = new org.openspcoop2.core.config.Cache();
  334.                 if(dimensioneCache!=null){
  335.                     configurazioneCache.setDimensione(dimensioneCache+"");
  336.                 }
  337.                 if(algoritmoCacheLRU!=null){
  338.                     if(algoritmoCacheLRU)
  339.                         configurazioneCache.setAlgoritmo(CostantiConfigurazione.CACHE_LRU);
  340.                     else
  341.                         configurazioneCache.setAlgoritmo(CostantiConfigurazione.CACHE_MRU);
  342.                 }
  343.                 if(itemIdleTime!=null){
  344.                     configurazioneCache.setItemIdleTime(itemIdleTime+"");
  345.                 }
  346.                 if(itemLifeSecond!=null){
  347.                     configurazioneCache.setItemLifeSecond(itemLifeSecond+"");
  348.                 }
  349.                 initCacheConfigurazione(CacheType.JCS, configurazioneCache, null, false, config); // lascio JCS come default abilitato via jmx
  350.             }catch(Exception e){
  351.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  352.             }
  353.         }
  354.     }
  355.     public void disabilitaCache() throws DriverConfigurazioneException{
  356.         if(this.cache==null)
  357.             throw new DriverConfigurazioneException("Cache gia' disabilitata");
  358.         else{
  359.             try{
  360.                 this.cache.clear();
  361.                 this.cache = null;
  362.             }catch(Exception e){
  363.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  364.             }
  365.         }
  366.     }
  367.     public String listKeysCache(String separator) throws DriverConfigurazioneException{
  368.         if(this.cache!=null){
  369.             try{
  370.                 return this.cache.printKeys(separator);
  371.             }catch(Exception e){
  372.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  373.             }
  374.         }else{
  375.             throw new DriverConfigurazioneException("Cache non abilitata");
  376.         }
  377.     }
  378.     public List<String> keysCache() throws DriverConfigurazioneException{
  379.         if(this.cache!=null){
  380.             try{
  381.                 return this.cache.keys();
  382.             }catch(Exception e){
  383.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  384.             }
  385.         }else{
  386.             throw new DriverConfigurazioneException("Cache non abilitata");
  387.         }
  388.     }
  389.     public String getObjectCache(String key) throws DriverConfigurazioneException{
  390.         if(this.cache!=null){
  391.             try{
  392.                 Object o = this.cache.get(key);
  393.                 if(o!=null){
  394.                     return o.toString();
  395.                 }else{
  396.                     return "oggetto con chiave ["+key+"] non presente";
  397.                 }
  398.             }catch(Exception e){
  399.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  400.             }
  401.         }else{
  402.             throw new DriverConfigurazioneException("Cache non abilitata");
  403.         }
  404.     }
  405.     public Object getRawObjectCache(String key) throws DriverConfigurazioneException{
  406.         if(this.cache!=null){
  407.             try{
  408.                 Object o = this.cache.get(key);
  409.                 if(o!=null){
  410.                     if(o instanceof CacheResponse) {
  411.                         CacheResponse cR = (CacheResponse) o;
  412.                         if(cR.getObject()!=null) {
  413.                             o = cR.getObject();
  414.                         }
  415.                         else if(cR.getException()!=null) {
  416.                             o = cR.getException();
  417.                         }
  418.                     }
  419.                     return o;
  420.                 }else{
  421.                     return null;
  422.                 }
  423.             }catch(Exception e){
  424.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  425.             }
  426.         }else{
  427.             throw new DriverConfigurazioneException("Cache non abilitata");
  428.         }
  429.     }
  430.     public void removeObjectCache(String key) throws DriverConfigurazioneException{
  431.         if(this.cache!=null){
  432.             try{
  433.                 this.cache.remove(key);
  434.             }catch(Exception e){
  435.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  436.             }
  437.         }else{
  438.             throw new DriverConfigurazioneException("Cache non abilitata");
  439.         }
  440.     }



  441.     /*   -------------- Costruttore -----------------  */

  442.     /**
  443.      * Si occupa di inizializzare l'engine che permette di effettuare
  444.      * query alla configurazione di OpenSPCoop.
  445.      * L'engine inizializzato sara' diverso a seconda del <var>tipo</var> di configurazione :
  446.      * <ul>
  447.      * <li> {@link DriverConfigurazioneXML}, interroga una configurazione realizzata tramite un file xml.
  448.      * <li> {@link DriverConfigurazioneDB}, interroga una configurazione realizzata tramite un database relazionale.
  449.      * </ul>
  450.      *
  451.      * @param accessoConfigurazione Informazioni per accedere alla configurazione della PdD OpenSPCoop.
  452.      */
  453.     public ConfigurazionePdD(AccessoConfigurazionePdD accessoConfigurazione,Logger alog,Logger alogConsole,Properties localProperties,
  454.             String jndiNameDatasourcePdD, boolean forceDisableCache, boolean useOp2UtilsDatasource, boolean bindJMX,
  455.             boolean prefillCache, CryptConfig configApplicativi,
  456.             CacheType cacheType)throws DriverConfigurazioneException{

  457.         try{
  458.             // Inizializzo OpenSPCoopProperties
  459.             this.openspcoopProperties = OpenSPCoop2Properties.getInstance();
  460.             this.configurazioneDinamica = this.openspcoopProperties.isConfigurazioneDinamica();

  461.             if(alog!=null)
  462.                 this.logger = alog;
  463.             else
  464.                 this.logger = LoggerWrapperFactory.getLogger(ConfigurazionePdD.class);

  465.             String msg = "Leggo configurazione di tipo["+accessoConfigurazione.getTipo()+"]   location["+accessoConfigurazione.getLocation()+"]";
  466.             this.logInfo(msg);
  467.             if(alogConsole!=null)
  468.                 alogConsole.info(msg);
  469.            
  470.             // inizializzazione XML
  471.             if(CostantiConfigurazione.CONFIGURAZIONE_XML.equalsIgnoreCase(accessoConfigurazione.getTipo())){
  472.                 this.driverConfigurazionePdD = new DriverConfigurazioneXML(accessoConfigurazione.getLocation(),this.logger);
  473.                 if(this.driverConfigurazionePdD ==null || ((DriverConfigurazioneXML)this.driverConfigurazionePdD).create==false){
  474.                     throw new DriverConfigurazioneException("Riscontrato errore durante l'inizializzazione della configurazione di tipo "+
  475.                             accessoConfigurazione.getTipo()+" con location: "+accessoConfigurazione.getLocation());
  476.                 }
  477.             }

  478.             // inizializzazione DB
  479.             else if(CostantiConfigurazione.CONFIGURAZIONE_DB.equalsIgnoreCase(accessoConfigurazione.getTipo())){            
  480.                 this.driverConfigurazionePdD = new DriverConfigurazioneDB(accessoConfigurazione.getLocation(),accessoConfigurazione.getContext(),
  481.                         this.logger,accessoConfigurazione.getTipoDatabase(),accessoConfigurazione.isCondivisioneDatabasePddRegistro(),
  482.                         useOp2UtilsDatasource, bindJMX);
  483.                 if(this.driverConfigurazionePdD ==null || ((DriverConfigurazioneDB)this.driverConfigurazionePdD).create==false){
  484.                     throw new DriverConfigurazioneException("Riscontrato errore durante l'inizializzazione della configurazione di tipo "+
  485.                             accessoConfigurazione.getTipo()+" con location: "+accessoConfigurazione.getLocation());
  486.                 }
  487.                 this.useConnectionPdD = jndiNameDatasourcePdD.equals(accessoConfigurazione.getLocation());
  488.                 this.tipoDatabase = accessoConfigurazione.getTipoDatabase();
  489.                
  490.                 this.configurazionePdD_controlloTraffico = new ConfigurazionePdD_controlloTraffico(this.openspcoopProperties,
  491.                         ((DriverConfigurazioneDB)this.driverConfigurazionePdD),
  492.                         this.useConnectionPdD);
  493.                
  494.                 if(this.openspcoopProperties.isConfigurazionePluginsEnabled()) {
  495.                     this.configurazionePdD_plugins = new ConfigurazionePdD_plugins(this.openspcoopProperties,
  496.                             ((DriverConfigurazioneDB)this.driverConfigurazionePdD),
  497.                             this.useConnectionPdD);
  498.                     this.configurazionePdD_registroPlugins = new ConfigurazionePdD_registroPlugins(this.openspcoopProperties,
  499.                             ((DriverConfigurazioneDB)this.driverConfigurazionePdD),
  500.                             this.useConnectionPdD);
  501.                 }
  502.                
  503.                 if(this.openspcoopProperties.isAllarmiEnabled()) {
  504.                     this.configurazionePdD_allarmi = new ConfigurazionePdD_allarmi(this.openspcoopProperties,
  505.                             ((DriverConfigurazioneDB)this.driverConfigurazionePdD),
  506.                             this.useConnectionPdD);
  507.                 }
  508.             }

  509.             // tipo di configurazione non conosciuto
  510.             else{
  511.                 throw new DriverConfigurazioneException("Riscontrato errore durante l'inizializzazione della configurazione di tipo sconosciuto "+
  512.                         accessoConfigurazione.getTipo()+" con location: "+accessoConfigurazione.getLocation());
  513.             }

  514.            
  515.             // Inizializzazione ConfigLocalProperties
  516.             this.configLocalProperties = new ConfigLocalProperties(this.logger, this.openspcoopProperties.getRootDirectory(),localProperties);
  517.            

  518.             // Inizializzazione della Cache
  519.             AccessoConfigurazione accessoDatiConfigurazione = null;
  520.             try{
  521.                 accessoDatiConfigurazione = this.driverConfigurazionePdD.getAccessoConfigurazione();
  522.             }catch(DriverConfigurazioneNotFound notFound){
  523.                 // ignore
  524.             }
  525.             if(accessoDatiConfigurazione!=null && accessoDatiConfigurazione.getCache()!=null){
  526.                 if(forceDisableCache==false){
  527.                     initCacheConfigurazione(cacheType, accessoDatiConfigurazione.getCache(),alogConsole,
  528.                             prefillCache, configApplicativi);
  529.                 }
  530.             }

  531.             if(this.driverConfigurazionePdD instanceof IDriverBYOKConfig) {
  532.                 DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNode(this.logger, false, true);
  533.                 if(driverBYOK!=null) {
  534.                     IDriverBYOKConfig c = (IDriverBYOKConfig) this.driverConfigurazionePdD;
  535.                     c.initialize(driverBYOK, false, true);
  536.                 }
  537.             }
  538.            
  539.         }catch(Exception e){
  540.             String msg = "Riscontrato errore durante l'inizializzazione della configurazione di OpenSPCoop: "+e.getMessage();
  541.             this.logError(msg,e);
  542.             if(alogConsole!=null)
  543.                 alogConsole.info(msg);
  544.             throw new DriverConfigurazioneException("Riscontrato errore durante l'inizializzazione della configurazione di OpenSPCoop: "+e.getMessage());
  545.         }
  546.     }

  547.     private void initCacheConfigurazione(CacheType cacheType, org.openspcoop2.core.config.Cache configurazioneCache,Logger alogConsole,
  548.             boolean prefillCache, CryptConfig configApplicativi)throws Exception{
  549.         this.cache = new Cache(cacheType, CostantiConfigurazione.CACHE_CONFIGURAZIONE_PDD);

  550.         String msg = null;
  551.         if( (configurazioneCache.getDimensione()!=null) ||
  552.                 (configurazioneCache.getAlgoritmo() != null) ){

  553.             try{
  554.                 if( configurazioneCache.getDimensione()!=null ){
  555.                     int dimensione = -1;                
  556.                     if(prefillCache){
  557.                         dimensione = Integer.MAX_VALUE;
  558.                     }
  559.                     else{
  560.                         dimensione = Integer.parseInt(configurazioneCache.getDimensione());
  561.                     }
  562.                     msg = "Dimensione della cache (ConfigurazionePdD) impostata al valore: "+dimensione;
  563.                     if(prefillCache){
  564.                         msg = "[Prefill Enabled] " + msg;
  565.                     }
  566.                     if(prefillCache){
  567.                         this.logWarn(msg);
  568.                     }
  569.                     else{
  570.                         this.logInfo(msg);
  571.                     }
  572.                     if(alogConsole!=null){
  573.                         if(prefillCache){
  574.                             alogConsole.warn(msg);
  575.                         }
  576.                         else{
  577.                             alogConsole.info(msg);
  578.                         }
  579.                     }
  580.                     this.cache.setCacheSize(dimensione);
  581.                 }
  582.                 else{
  583.                     if(prefillCache){
  584.                         int dimensione = Integer.MAX_VALUE;
  585.                         msg = "[Prefill Enabled] Dimensione della cache (ConfigurazionePdD) impostata al valore: "+dimensione;
  586.                         this.logWarn(msg);
  587.                         if(alogConsole!=null){
  588.                             alogConsole.warn(msg);
  589.                         }
  590.                         this.cache.setCacheSize(dimensione);
  591.                     }
  592.                 }
  593.             }catch(Exception error){
  594.                 throw new DriverConfigurazioneException("Parametro errato per la dimensione della cache (ConfigurazionePdD): "+error.getMessage());
  595.             }
  596.            
  597.             if( configurazioneCache.getAlgoritmo() != null ){
  598.                 msg = "Algoritmo di cache (ConfigurazionePdD) impostato al valore: "+configurazioneCache.getAlgoritmo();
  599.                 this.logInfo(msg);
  600.                 if(alogConsole!=null)
  601.                     alogConsole.info(msg);
  602.                 if(CostantiConfigurazione.CACHE_MRU.equals(configurazioneCache.getAlgoritmo()))
  603.                     this.cache.setCacheAlgoritm(CacheAlgorithm.MRU);
  604.                 else
  605.                     this.cache.setCacheAlgoritm(CacheAlgorithm.LRU);
  606.             }

  607.         }

  608.         if( (configurazioneCache.getItemIdleTime() != null) ||
  609.                 (configurazioneCache.getItemLifeSecond() != null) ){

  610.             try{
  611.                 if( configurazioneCache.getItemIdleTime() != null  ){
  612.                     int itemIdleTime = -1;
  613.                     if(prefillCache){
  614.                         itemIdleTime = -1;
  615.                     }
  616.                     else{
  617.                         itemIdleTime = Integer.parseInt(configurazioneCache.getItemIdleTime());
  618.                     }
  619.                     msg = "Attributo 'IdleTime' (ConfigurazionePdD) impostato al valore: "+itemIdleTime;
  620.                     if(prefillCache){
  621.                         msg = "[Prefill Enabled] " + msg;
  622.                     }
  623.                     if(prefillCache){
  624.                         this.logWarn(msg);
  625.                     }
  626.                     else{
  627.                         this.logInfo(msg);
  628.                     }
  629.                     if(alogConsole!=null){
  630.                         if(prefillCache){
  631.                             alogConsole.warn(msg);
  632.                         }
  633.                         else{
  634.                             alogConsole.info(msg);
  635.                         }
  636.                     }
  637.                     this.cache.setItemIdleTime(itemIdleTime);  
  638.                 }
  639.                 else{
  640.                     if(prefillCache){
  641.                         int itemIdleTime = -1;
  642.                         msg = "[Prefill Enabled] Attributo 'IdleTime' (ConfigurazionePdD) impostato al valore: "+itemIdleTime;
  643.                         this.logWarn(msg);
  644.                         if(alogConsole!=null){
  645.                             alogConsole.warn(msg);
  646.                         }
  647.                         this.cache.setItemIdleTime(itemIdleTime);
  648.                     }
  649.                 }
  650.             }catch(Exception error){
  651.                 throw new DriverConfigurazioneException("Parametro errato per l'attributo 'IdleTime' (ConfigurazionePdD): "+error.getMessage());
  652.             }
  653.            
  654.             try{
  655.                 if( configurazioneCache.getItemLifeSecond() != null  ){
  656.                     int itemLifeSecond = -1;                
  657.                     if(prefillCache){
  658.                         itemLifeSecond = -1;
  659.                     }
  660.                     else{
  661.                         itemLifeSecond = Integer.parseInt(configurazioneCache.getItemLifeSecond());
  662.                     }
  663.                     msg = "Attributo 'MaxLifeSecond' (ConfigurazionePdD) impostato al valore: "+itemLifeSecond;
  664.                     if(prefillCache){
  665.                         msg = "[Prefill Enabled] " + msg;
  666.                     }
  667.                     if(prefillCache){
  668.                         this.logWarn(msg);
  669.                     }
  670.                     else{
  671.                         this.logInfo(msg);
  672.                     }
  673.                     if(alogConsole!=null){
  674.                         if(prefillCache){
  675.                             alogConsole.warn(msg);
  676.                         }
  677.                         else{
  678.                             alogConsole.info(msg);
  679.                         }
  680.                     }
  681.                     this.cache.setItemLifeTime(itemLifeSecond);
  682.                 }
  683.                 else{
  684.                     if(prefillCache){
  685.                         int itemLifeSecond = -1;
  686.                         msg = "Attributo 'MaxLifeSecond' (ConfigurazionePdD) impostato al valore: "+itemLifeSecond;
  687.                         this.logWarn(msg);
  688.                         if(alogConsole!=null){
  689.                             alogConsole.warn(msg);
  690.                         }
  691.                         this.cache.setItemLifeTime(itemLifeSecond);
  692.                     }
  693.                 }
  694.             }catch(Exception error){
  695.                 throw new DriverConfigurazioneException("Parametro errato per l'attributo 'MaxLifeSecond' (ConfigurazionePdD): "+error.getMessage());
  696.             }

  697.         }
  698.        
  699.         this.cache.build();
  700.        
  701.         if(prefillCache){
  702.             this.prefillCache(null,alogConsole, configApplicativi);
  703.         }
  704.     }

  705.     @SuppressWarnings("deprecation")
  706.     @Deprecated
  707.     public void disableSyncronizedGet() throws UtilsException {
  708.         if(this.cache==null) {
  709.             throw new UtilsException("Cache disabled");
  710.         }
  711.         this.cache.disableSyncronizedGet();
  712.     }
  713.     @SuppressWarnings("deprecation")
  714.     @Deprecated
  715.     public boolean isDisableSyncronizedGet() throws UtilsException {
  716.         if(this.cache==null) {
  717.             throw new UtilsException("Cache disabled");
  718.         }
  719.         return this.cache.isDisableSyncronizedGet();
  720.     }
  721.    

  722.     protected IDriverConfigurazioneGet getDriverConfigurazionePdD() {
  723.         return this.driverConfigurazionePdD;
  724.     }


  725.    
  726.     public void prefillCache(Connection connectionPdD,Logger alogConsole, CryptConfig configApplicativi){
  727.        
  728.         String msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD) in corso ...";
  729.         this.logInfo(msg);
  730.         if(alogConsole!=null){
  731.             alogConsole.info(msg);
  732.         }
  733.        
  734.         try{
  735.             this.cache.remove(_getKey_isForwardProxyEnabled());
  736.             this.isForwardProxyEnabled();
  737.         }
  738.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  739.        
  740.        
  741.         // *** Soggetti ***
  742.        
  743.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recupero soggetti ...";
  744.         this.logDebug(msg);
  745.         if(alogConsole!=null){
  746.             alogConsole.debug(msg);
  747.         }
  748.        
  749.         FiltroRicercaSoggetti filtroRicercaSoggetti = new FiltroRicercaSoggetti();
  750.         List<IDSoggetto> idSoggetti = null;
  751.         try{
  752.             idSoggetti = this.driverConfigurazionePdD.getAllIdSoggetti(filtroRicercaSoggetti);
  753.         }
  754.         catch(DriverConfigurazioneNotFound notFound){
  755.             // ignore
  756.         }
  757.         catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  758.        
  759.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recuperati "+(idSoggetti!=null ? idSoggetti.size() : 0)+" soggetti";
  760.         this.logDebug(msg);
  761.         if(alogConsole!=null){
  762.             alogConsole.debug(msg);
  763.         }
  764.        
  765.         if(idSoggetti!=null && idSoggetti.size()>0){
  766.            
  767.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idSoggetti.size()+" soggetti ...";
  768.             this.logDebug(msg);
  769.             if(alogConsole!=null){
  770.                 alogConsole.debug(msg);
  771.             }
  772.            
  773.             for (IDSoggetto idSoggetto : idSoggetti) {
  774.                
  775.                 try{
  776.                     this.cache.remove(_getKey_getSoggettoByID(idSoggetto));
  777.                     this.getSoggetto(connectionPdD, idSoggetto);
  778.                 }
  779.                 catch(DriverConfigurazioneNotFound notFound){
  780.                     // ignore
  781.                 }
  782.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  783.                
  784.             }
  785.            
  786.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idSoggetti.size()+" soggetti completata";
  787.             this.logDebug(msg);
  788.             if(alogConsole!=null){
  789.                 alogConsole.debug(msg);
  790.             }
  791.         }
  792.        
  793.        
  794.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recupero porte delegate ...";
  795.         this.logDebug(msg);
  796.         if(alogConsole!=null){
  797.             alogConsole.debug(msg);
  798.         }
  799.        
  800.         FiltroRicercaPorteDelegate filtroPorteDelegate = new FiltroRicercaPorteDelegate();
  801.         List<IDPortaDelegata> idPDs = null;
  802.         try{
  803.             idPDs = this.driverConfigurazionePdD.getAllIdPorteDelegate(filtroPorteDelegate);
  804.         }
  805.         catch(DriverConfigurazioneNotFound notFound){
  806.             // ignore
  807.         }
  808.         catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  809.        
  810.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recuperate "+(idPDs!=null ? idPDs.size() : 0)+" porte delegate";
  811.         this.logDebug(msg);
  812.         if(alogConsole!=null){
  813.             alogConsole.debug(msg);
  814.         }
  815.        
  816.         if(idPDs!=null && idPDs.size()>0){
  817.            
  818.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idPDs.size()+" porte delegate ...";
  819.             this.logDebug(msg);
  820.             if(alogConsole!=null){
  821.                 alogConsole.debug(msg);
  822.             }
  823.            
  824.             for (IDPortaDelegata idPortaDelegata : idPDs) {
  825.                
  826.                 msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati della porta delegata ["+idPortaDelegata+"] ...";
  827.                 this.logDebug(msg);
  828.                 if(alogConsole!=null){
  829.                     alogConsole.debug(msg);
  830.                 }
  831.                
  832.                 try{
  833.                     this.cache.remove(_getKey_getIDPortaDelegata(idPortaDelegata.getNome()));
  834.                     this.getIDPortaDelegata(connectionPdD, idPortaDelegata.getNome());
  835.                 }
  836.                 catch(DriverConfigurazioneNotFound notFound){
  837.                     // ignore
  838.                 }
  839.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  840.                
  841.                 try{
  842.                     this.cache.remove(_getKey_getPortaDelegata(idPortaDelegata));
  843.                     this.getPortaDelegata(connectionPdD, idPortaDelegata);
  844.                 }
  845.                 catch(DriverConfigurazioneNotFound notFound){
  846.                     // ignore
  847.                 }
  848.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  849.                
  850.                 PortaDelegata pd = null;
  851.                 try{
  852.                     pd = this.driverConfigurazionePdD.getPortaDelegata(idPortaDelegata);
  853.                 }
  854.                 catch(DriverConfigurazioneNotFound notFound){
  855.                     // ignore
  856.                 }
  857.                 catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  858.                
  859.                 if(pd!=null){
  860.                    
  861.                     IDSoggetto idSoggettoProprietario = new IDSoggetto(pd.getTipoSoggettoProprietario(), pd.getNomeSoggettoProprietario());
  862.                                        
  863.                     IDServizioApplicativo idSA_anonimo = new IDServizioApplicativo();
  864.                     idSA_anonimo.setIdSoggettoProprietario(idSoggettoProprietario);
  865.                     idSA_anonimo.setNome(CostantiPdD.SERVIZIO_APPLICATIVO_ANONIMO);
  866.                     try{
  867.                         this.cache.remove(_getKey_getServizioApplicativo(idSA_anonimo));
  868.                         this.getServizioApplicativo(connectionPdD, idSA_anonimo);
  869.                     }
  870.                     catch(DriverConfigurazioneNotFound notFound){
  871.                         // ignore
  872.                     }
  873.                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  874.                    
  875.                     if(pd.sizeServizioApplicativoList()>0){
  876.                         for (PortaDelegataServizioApplicativo saPD : pd.getServizioApplicativoList()) {
  877.                            
  878.                             IDServizioApplicativo idSA = new IDServizioApplicativo();
  879.                             idSA.setIdSoggettoProprietario(idSoggettoProprietario);
  880.                             idSA.setNome(saPD.getNome());
  881.                            
  882.                             try{
  883.                                 this.cache.remove(_getKey_getServizioApplicativo(idSA));
  884.                                 this.getServizioApplicativo(connectionPdD, idSA);
  885.                             }
  886.                             catch(DriverConfigurazioneNotFound notFound){
  887.                                 // ignore
  888.                             }
  889.                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  890.                            
  891.                             ServizioApplicativo sa = null;
  892.                             try{
  893.                                 sa = this.driverConfigurazionePdD.getServizioApplicativo(idSA);
  894.                             }
  895.                             catch(DriverConfigurazioneNotFound notFound){
  896.                                 // ignore
  897.                             }
  898.                             catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  899.                                    
  900.                             if(sa!=null){
  901.                                 if(sa.getInvocazionePorta()!=null && sa.getInvocazionePorta().sizeCredenzialiList()>0){
  902.                                     for (Credenziali credenziale : sa.getInvocazionePorta().getCredenzialiList()) {
  903.                                         if(CredenzialeTipo.BASIC.equals(credenziale.getTipo())){
  904.                                             try{
  905.                                                 this.cache.remove(_getKey_getServizioApplicativoByCredenzialiBasic(credenziale.getUser(), credenziale.getPassword(), null));
  906.                                                 this.getServizioApplicativoByCredenzialiBasic(connectionPdD, credenziale.getUser(), credenziale.getPassword(), configApplicativi);
  907.                                             }
  908.                                             catch(DriverConfigurazioneNotFound notFound){
  909.                                                 // ignore
  910.                                             }
  911.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  912.                                         }
  913.                                         else if(CredenzialeTipo.APIKEY.equals(credenziale.getTipo())){
  914.                                             try{
  915.                                                 this.cache.remove(_getKey_getServizioApplicativoByCredenzialiApiKey(credenziale.getUser(), credenziale.getPassword(), credenziale.isCertificateStrictVerification(), null));
  916.                                                 this.getServizioApplicativoByCredenzialiApiKey(connectionPdD, credenziale.getUser(), credenziale.getPassword(), credenziale.isCertificateStrictVerification(), configApplicativi);
  917.                                             }
  918.                                             catch(DriverConfigurazioneNotFound notFound){
  919.                                                 // ignore
  920.                                             }
  921.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  922.                                         }
  923.                                         else if(CredenzialeTipo.SSL.equals(credenziale.getTipo())){
  924.                                             if(credenziale.getSubject()!=null) {
  925.                                                 try{
  926.                                                     if(Costanti.MODIPA_PROTOCOL_NAME.equals(sa.getTipoSoggettoProprietario())) {
  927.                                                         ConfigurazioneFiltroServiziApplicativi filtroFirma = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma();
  928.                                                         this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(credenziale.getSubject(), credenziale.getIssuer(),
  929.                                                                 filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni()));
  930.                                                         this.getServizioApplicativoByCredenzialiSsl(connectionPdD, credenziale.getSubject(), credenziale.getIssuer(),
  931.                                                                 filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni());
  932.                                                     }
  933.                                                 } catch(DriverConfigurazioneNotFound notFound){
  934.                                                     // ignore
  935.                                                 }
  936.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  937.                                                 try {
  938.                                                     ConfigurazioneFiltroServiziApplicativi filtroHttps = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps();
  939.                                                     this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(credenziale.getSubject(), credenziale.getIssuer(),
  940.                                                             filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni()));
  941.                                                     this.getServizioApplicativoByCredenzialiSsl(connectionPdD, credenziale.getSubject(), credenziale.getIssuer(),
  942.                                                             filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni());
  943.                                                 }
  944.                                                 catch(DriverConfigurazioneNotFound notFound){
  945.                                                     // ignore
  946.                                                 }
  947.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  948.                                             }
  949.                                             if(credenziale.getCertificate()!=null) {
  950.                                                 try{
  951.                                                     CertificateInfo certificato = ArchiveLoader.load(ArchiveType.CER, credenziale.getCertificate(), 0, null).getCertificate();
  952.                                                     if(Costanti.MODIPA_PROTOCOL_NAME.equals(sa.getTipoSoggettoProprietario())) {
  953.                                                         ConfigurazioneFiltroServiziApplicativi filtroFirma = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma();
  954.                                                         this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(certificato, credenziale.isCertificateStrictVerification(),
  955.                                                                 filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni()));
  956.                                                         this.getServizioApplicativoByCredenzialiSsl(connectionPdD, certificato, credenziale.isCertificateStrictVerification(),
  957.                                                                 filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni());
  958.                                                     }
  959.                                                 }
  960.                                                 catch(DriverConfigurazioneNotFound notFound){
  961.                                                     // ignore
  962.                                                 }
  963.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  964.                                                 try {
  965.                                                     CertificateInfo certificato = ArchiveLoader.load(ArchiveType.CER, credenziale.getCertificate(), 0, null).getCertificate();
  966.                                                     ConfigurazioneFiltroServiziApplicativi filtroHttps = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps();
  967.                                                     this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(certificato, credenziale.isCertificateStrictVerification(),
  968.                                                             filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni()));
  969.                                                     this.getServizioApplicativoByCredenzialiSsl(connectionPdD, certificato, credenziale.isCertificateStrictVerification(),
  970.                                                             filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni());
  971.                                                 }
  972.                                                 catch(DriverConfigurazioneNotFound notFound){
  973.                                                     // ignore
  974.                                                 }
  975.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  976.                                             }          
  977.                                         }
  978.                                         else if(CredenzialeTipo.PRINCIPAL.equals(credenziale.getTipo())){
  979.                                             try{
  980.                                                 this.cache.remove(_getKey_getServizioApplicativoByCredenzialiPrincipal(credenziale.getUser(), null));
  981.                                                 this.getServizioApplicativoByCredenzialiPrincipal(connectionPdD, credenziale.getUser());
  982.                                             }
  983.                                             catch(DriverConfigurazioneNotFound notFound){
  984.                                                 // ignore
  985.                                             }
  986.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  987.                                         }
  988.                                         else if(CredenzialeTipo.TOKEN.equals(credenziale.getTipo())){
  989.                                             try{
  990.                                                 this.cache.remove(_getKey_getServizioApplicativoByCredenzialiToken(credenziale.getTokenPolicy(), credenziale.getUser(), null));
  991.                                                 this.getServizioApplicativoByCredenzialiToken(connectionPdD, credenziale.getTokenPolicy(), credenziale.getUser());
  992.                                             }
  993.                                             catch(DriverConfigurazioneNotFound notFound){
  994.                                                 // ignore
  995.                                             }
  996.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  997.                                         }
  998.                                     }
  999.                                 }
  1000.                             }
  1001.                         }
  1002.                     }
  1003.                                        
  1004.                     try{
  1005.                         IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(pd.getServizio().getTipo(), pd.getServizio().getNome(),
  1006.                                 pd.getTipoSoggettoProprietario(), pd.getNomeSoggettoProprietario(),
  1007.                                 pd.getServizio().getVersione());
  1008.                        
  1009.                         this.cache.remove(_getKey_MappingFruizionePortaDelegataList(idSoggettoProprietario, idServizio, true));
  1010.                         this.getMappingFruizionePortaDelegataList(idSoggettoProprietario, idServizio, connectionPdD);
  1011.                     }
  1012.                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1013.                    
  1014.                     this.prefillElencoPolicyAttive(alogConsole, connectionPdD, true, TipoPdD.DELEGATA, pd.getNome());  
  1015.                    
  1016.                 }
  1017.                
  1018.                 msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati della porta delegata ["+idPortaDelegata+"] completata";
  1019.                 this.logDebug(msg);
  1020.                 if(alogConsole!=null){
  1021.                     alogConsole.debug(msg);
  1022.                 }
  1023.             }
  1024.            
  1025.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idPDs.size()+" porte delegate completata";
  1026.             this.logDebug(msg);
  1027.             if(alogConsole!=null){
  1028.                 alogConsole.debug(msg);
  1029.             }
  1030.         }
  1031.        
  1032.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di router/soggettiVirtuali ...";
  1033.         this.logDebug(msg);
  1034.         if(alogConsole!=null){
  1035.             alogConsole.debug(msg);
  1036.         }
  1037.        
  1038.         try{
  1039.             this.cache.remove(_getKey_getRouter());
  1040.             this.getRouter(connectionPdD);
  1041.         }
  1042.         catch(DriverConfigurazioneNotFound notFound){
  1043.             // ignore
  1044.         }
  1045.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1046.        
  1047.         try{
  1048.             this.cache.remove(_getKey_getSoggettiVirtuali());
  1049.             this.getSoggettiVirtuali(connectionPdD);
  1050.         }
  1051.         catch(DriverConfigurazioneNotFound notFound){
  1052.             // ignore
  1053.         }
  1054.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1055.        
  1056.         try{
  1057.             this.cache.remove(getKeyMethodGetServiziSoggettiVirtuali());
  1058.             this.getServiziSoggettiVirtuali(connectionPdD);
  1059.         }
  1060.         catch(DriverConfigurazioneNotFound notFound){
  1061.             // ignore
  1062.         }
  1063.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1064.        
  1065.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di router/soggettiVirtuali completata";
  1066.         this.logDebug(msg);
  1067.         if(alogConsole!=null){
  1068.             alogConsole.debug(msg);
  1069.         }
  1070.        
  1071.         // *** PorteDelegate ***
  1072.         // getPortaDelegata invocata precedentemente con i soggetti
  1073.        
  1074.         // *** PorteApplicative ***
  1075.        
  1076.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recupero porte applicative ...";
  1077.         this.logDebug(msg);
  1078.         if(alogConsole!=null){
  1079.             alogConsole.debug(msg);
  1080.         }
  1081.        
  1082.         FiltroRicercaPorteApplicative filtroPorteApplicative = new FiltroRicercaPorteApplicative();
  1083.         List<IDPortaApplicativa> idPAs = null;
  1084.         try{
  1085.             idPAs = this.driverConfigurazionePdD.getAllIdPorteApplicative(filtroPorteApplicative);
  1086.         }
  1087.         catch(DriverConfigurazioneNotFound notFound){
  1088.             // ignore
  1089.         }
  1090.         catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1091.        
  1092.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recuperate "+(idPAs!=null ? idPAs.size() : 0)+" porte applicative";
  1093.         this.logDebug(msg);
  1094.         if(alogConsole!=null){
  1095.             alogConsole.debug(msg);
  1096.         }
  1097.        
  1098.         if(idPAs!=null && idPAs.size()>0){
  1099.            
  1100.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idPAs.size()+" porte applicative ...";
  1101.             this.logDebug(msg);
  1102.             if(alogConsole!=null){
  1103.                 alogConsole.debug(msg);
  1104.             }
  1105.            
  1106.             for (IDPortaApplicativa idPA : idPAs) {
  1107.                        
  1108.                 msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati della porta applicativa ["+idPA+"] ...";
  1109.                 this.logDebug(msg);
  1110.                 if(alogConsole!=null){
  1111.                     alogConsole.debug(msg);
  1112.                 }
  1113.                
  1114.                 try{
  1115.                     this.cache.remove(_getKey_getIDPortaApplicativa(idPA.getNome()));
  1116.                     this.getIDPortaApplicativa(connectionPdD, idPA.getNome());
  1117.                 }
  1118.                 catch(DriverConfigurazioneNotFound notFound){
  1119.                     // ignore
  1120.                 }
  1121.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1122.                
  1123.                 try{
  1124.                     this.cache.remove(_getKey_getPortaApplicativa(idPA));
  1125.                     this.getPortaApplicativa(connectionPdD, idPA);
  1126.                 }
  1127.                 catch(DriverConfigurazioneNotFound notFound){
  1128.                     // ignore
  1129.                 }
  1130.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1131.                
  1132.                 PortaApplicativa pa  = null;
  1133.                 try{
  1134.                     pa  = this.driverConfigurazionePdD.getPortaApplicativa(idPA);
  1135.                 }
  1136.                 catch(DriverConfigurazioneNotFound notFound){
  1137.                     // ignore
  1138.                 }
  1139.                 catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1140.                
  1141.                 if(pa!=null){
  1142.                    
  1143.                     IDSoggetto idSoggettoProprietario = new IDSoggetto(pa.getTipoSoggettoProprietario(), pa.getNomeSoggettoProprietario());
  1144.                                            
  1145.                     if(pa.sizeServizioApplicativoList()>0){
  1146.                         for (PortaApplicativaServizioApplicativo saPA : pa.getServizioApplicativoList()) {
  1147.                             try{
  1148.                                 IDServizioApplicativo idSA = new IDServizioApplicativo();
  1149.                                 idSA.setIdSoggettoProprietario(idSoggettoProprietario);
  1150.                                 idSA.setNome(saPA.getNome());
  1151.                                 this.cache.remove(_getKey_getServizioApplicativo(idSA));
  1152.                                 this.getServizioApplicativo(connectionPdD, idSA);
  1153.                             }
  1154.                             catch(DriverConfigurazioneNotFound notFound){
  1155.                                 // ignore
  1156.                             }
  1157.                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1158.                         }
  1159.                     }
  1160.                    
  1161.                     try{
  1162.                         IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(pa.getServizio().getTipo(), pa.getServizio().getNome(),
  1163.                                 idSoggettoProprietario,
  1164.                                 pa.getServizio().getVersione());
  1165.                        
  1166.                         this.cache.remove(_getKey_MappingErogazionePortaApplicativaList(idServizio, true));
  1167.                         this.getMappingErogazionePortaApplicativaList(idServizio, connectionPdD);
  1168.                     }
  1169.                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1170.                    
  1171.                     this.prefillElencoPolicyAttive(alogConsole, connectionPdD, true, TipoPdD.APPLICATIVA, pa.getNome());        
  1172.                    
  1173.                 }
  1174.                
  1175.                 msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati della porta applicativa ["+idPA+"] completata";
  1176.                 this.logDebug(msg);
  1177.                 if(alogConsole!=null){
  1178.                     alogConsole.debug(msg);
  1179.                 }
  1180.                
  1181.             }
  1182.            
  1183.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idPAs.size()+" porte applicative completata";
  1184.             this.logDebug(msg);
  1185.             if(alogConsole!=null){
  1186.                 alogConsole.debug(msg);
  1187.             }
  1188.         }
  1189.        
  1190.         // getPorteApplicativeSoggettiVirtuali non inizializzabile
  1191.         // getPorteApplicativeVirtuali non inizializzabile
  1192.        
  1193.         // *** ServiziApplicativi ***
  1194.         // getServizioApplicativo(PD) invocata precedentemente con i soggetti
  1195.         // getServizioApplicativo(PA) invocata precedentemente con le porte applicative
  1196.         // getServizioApplicativoAutenticatoBasic(PD) invocata precedentemente con i soggetti
  1197.         // getServizioApplicativoAutenticatoSsl(PD) invocata precedentemente con i soggetti
  1198.         // getServizioApplicativoAutenticatoPrincipal(PD) invocata precedentemente con i soggetti
  1199.        
  1200.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recupero servizi applicativi ...";
  1201.         this.logDebug(msg);
  1202.         if(alogConsole!=null){
  1203.             alogConsole.debug(msg);
  1204.         }
  1205.        
  1206.         FiltroRicercaServiziApplicativi filtroServiziApplicativi = new FiltroRicercaServiziApplicativi();
  1207.         List<IDServizioApplicativo> idSAs = null;
  1208.         try{
  1209.             idSAs = this.driverConfigurazionePdD.getAllIdServiziApplicativi(filtroServiziApplicativi);
  1210.         }
  1211.         catch(DriverConfigurazioneNotFound notFound){
  1212.             // ignore
  1213.         }
  1214.         catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1215.        
  1216.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), recuperati "+(idSAs!=null ? idSAs.size() : 0)+" servizi applicativi";
  1217.         this.logDebug(msg);
  1218.         if(alogConsole!=null){
  1219.             alogConsole.debug(msg);
  1220.         }
  1221.        
  1222.         if(idSAs!=null && idSAs.size()>0){
  1223.            
  1224.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idSAs.size()+" servizi applicativi ...";
  1225.             this.logDebug(msg);
  1226.             if(alogConsole!=null){
  1227.                 alogConsole.debug(msg);
  1228.             }
  1229.            
  1230.             for (IDServizioApplicativo idSA : idSAs) {
  1231.                 ServizioApplicativo sa = null;
  1232.                 try{
  1233.                     sa = this.driverConfigurazionePdD.getServizioApplicativo(idSA);
  1234.                 }
  1235.                 catch(DriverConfigurazioneNotFound notFound){
  1236.                     // ignore
  1237.                 }
  1238.                 catch(DriverConfigurazioneException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1239.                        
  1240.                 if(sa!=null){
  1241.                     if(sa.getInvocazionePorta()!=null && sa.getInvocazionePorta().sizeCredenzialiList()>0){
  1242.                         for (Credenziali credenziale : sa.getInvocazionePorta().getCredenzialiList()) {
  1243.                             if(CredenzialeTipo.BASIC.equals(credenziale.getTipo())){
  1244.                                 try{
  1245.                                     this.cache.remove(_getKey_getServizioApplicativoByCredenzialiBasic(credenziale.getUser(), credenziale.getPassword(), null));
  1246.                                     this.getServizioApplicativoByCredenzialiBasic(connectionPdD, credenziale.getUser(), credenziale.getPassword(), configApplicativi);
  1247.                                 }
  1248.                                 catch(DriverConfigurazioneNotFound notFound){
  1249.                                     // ignore
  1250.                                 }
  1251.                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  1252.                             }
  1253.                             else if(CredenzialeTipo.APIKEY.equals(credenziale.getTipo())){
  1254.                                 try{
  1255.                                     this.cache.remove(_getKey_getServizioApplicativoByCredenzialiApiKey(credenziale.getUser(), credenziale.getPassword(), credenziale.isCertificateStrictVerification(), null));
  1256.                                     this.getServizioApplicativoByCredenzialiApiKey(connectionPdD, credenziale.getUser(), credenziale.getPassword(), credenziale.isCertificateStrictVerification(), configApplicativi);
  1257.                                 }
  1258.                                 catch(DriverConfigurazioneNotFound notFound){
  1259.                                     // ignore
  1260.                                 }
  1261.                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  1262.                             }
  1263.                             else if(CredenzialeTipo.SSL.equals(credenziale.getTipo())){
  1264.                                 if(credenziale.getSubject()!=null) {
  1265.                                     try{
  1266.                                         if(Costanti.MODIPA_PROTOCOL_NAME.equals(sa.getTipoSoggettoProprietario())) {
  1267.                                             ConfigurazioneFiltroServiziApplicativi filtroFirma = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma();
  1268.                                             this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(credenziale.getSubject(), credenziale.getIssuer(),
  1269.                                                     filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni()));
  1270.                                             this.getServizioApplicativoByCredenzialiSsl(connectionPdD, credenziale.getSubject(), credenziale.getIssuer(),
  1271.                                                     filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni());
  1272.                                         }
  1273.                                     } catch(DriverConfigurazioneNotFound notFound){
  1274.                                         // ignore
  1275.                                     }
  1276.                                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1277.                                     try {
  1278.                                         ConfigurazioneFiltroServiziApplicativi filtroHttps = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps();
  1279.                                         this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(credenziale.getSubject(), credenziale.getIssuer(),
  1280.                                                 filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni()));
  1281.                                         this.getServizioApplicativoByCredenzialiSsl(connectionPdD, credenziale.getSubject(), credenziale.getIssuer(),
  1282.                                                 filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni());
  1283.                                     }
  1284.                                     catch(DriverConfigurazioneNotFound notFound){
  1285.                                         // ignore
  1286.                                     }
  1287.                                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1288.                                 }
  1289.                                 if(credenziale.getCertificate()!=null) {
  1290.                                     try{
  1291.                                         CertificateInfo certificato = ArchiveLoader.load(ArchiveType.CER, credenziale.getCertificate(), 0, null).getCertificate();
  1292.                                         if(Costanti.MODIPA_PROTOCOL_NAME.equals(sa.getTipoSoggettoProprietario())) {
  1293.                                             ConfigurazioneFiltroServiziApplicativi filtroFirma = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma();
  1294.                                             this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(certificato, credenziale.isCertificateStrictVerification(),
  1295.                                                     filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni()));
  1296.                                             this.getServizioApplicativoByCredenzialiSsl(connectionPdD, certificato, credenziale.isCertificateStrictVerification(),
  1297.                                                     filtroFirma.getTipiSoggetti(), filtroFirma.isIncludiApplicativiNonModI(), filtroFirma.isIncludiApplicativiModIEsterni(), filtroFirma.isIncludiApplicativiModIInterni());
  1298.                                         }
  1299.                                     }
  1300.                                     catch(DriverConfigurazioneNotFound notFound){
  1301.                                         // ignore
  1302.                                     }
  1303.                                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1304.                                     try {
  1305.                                         CertificateInfo certificato = ArchiveLoader.load(ArchiveType.CER, credenziale.getCertificate(), 0, null).getCertificate();
  1306.                                         ConfigurazioneFiltroServiziApplicativi filtroHttps = ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps();
  1307.                                         this.cache.remove(_getKey_getServizioApplicativoByCredenzialiSsl(certificato, credenziale.isCertificateStrictVerification(),
  1308.                                                 filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni()));
  1309.                                         this.getServizioApplicativoByCredenzialiSsl(connectionPdD, certificato, credenziale.isCertificateStrictVerification(),
  1310.                                                 filtroHttps.getTipiSoggetti(), filtroHttps.isIncludiApplicativiNonModI(), filtroHttps.isIncludiApplicativiModIEsterni(), filtroHttps.isIncludiApplicativiModIInterni());
  1311.                                     }
  1312.                                     catch(DriverConfigurazioneNotFound notFound){
  1313.                                         // ignore
  1314.                                     }
  1315.                                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1316.                                 }
  1317.                             }
  1318.                             else if(CredenzialeTipo.PRINCIPAL.equals(credenziale.getTipo())){
  1319.                                 try{
  1320.                                     this.cache.remove(_getKey_getServizioApplicativoByCredenzialiPrincipal(credenziale.getUser(), null));
  1321.                                     this.getServizioApplicativoByCredenzialiPrincipal(connectionPdD, credenziale.getUser());
  1322.                                 }
  1323.                                 catch(DriverConfigurazioneNotFound notFound){
  1324.                                     // ignore
  1325.                                 }
  1326.                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  1327.                             }
  1328.                             else if(CredenzialeTipo.TOKEN.equals(credenziale.getTipo())){
  1329.                                 try{
  1330.                                     this.cache.remove(_getKey_getServizioApplicativoByCredenzialiToken(credenziale.getTokenPolicy(), credenziale.getUser(), null));
  1331.                                     this.getServizioApplicativoByCredenzialiToken(connectionPdD, credenziale.getTokenPolicy(), credenziale.getUser());
  1332.                                 }
  1333.                                 catch(DriverConfigurazioneNotFound notFound){
  1334.                                     // ignore
  1335.                                 }
  1336.                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}            
  1337.                             }
  1338.                         }
  1339.                     }
  1340.                 }
  1341.             }
  1342.            
  1343.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura di "+idSAs.size()+" servizi applicativi completata";
  1344.             this.logDebug(msg);
  1345.             if(alogConsole!=null){
  1346.                 alogConsole.debug(msg);
  1347.             }
  1348.         }
  1349.        
  1350.         // *** Configurazione ***
  1351.        
  1352.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura della configurazione della porta ...";
  1353.         this.logDebug(msg);
  1354.         if(alogConsole!=null){
  1355.             alogConsole.debug(msg);
  1356.         }
  1357.        
  1358.         List<String> code = this.openspcoopProperties.getTimerConsegnaContenutiApplicativiCode();
  1359.         for (String coda : code) {
  1360.             try{
  1361.                 this.cache.remove(getKey_getConnettoriConsegnaNotifichePrioritarie(coda));
  1362.                 this.getConnettoriConsegnaNotifichePrioritarie(connectionPdD, coda);
  1363.             }
  1364.             catch(DriverConfigurazioneNotFound notFound){
  1365.                 // ignore
  1366.             }
  1367.             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1368.         }
  1369.        
  1370.         try{
  1371.             this.cache.remove(_getKey_getRoutingTable());
  1372.             this.getRoutingTable(connectionPdD);
  1373.         }
  1374.         catch(DriverConfigurazioneNotFound notFound){
  1375.             // ignore
  1376.         }
  1377.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1378.        
  1379.         try{
  1380.             this.cache.remove(getKeyMethodGetAccessoRegistro());
  1381.             this.getAccessoRegistro(connectionPdD);
  1382.         }
  1383.         catch(DriverConfigurazioneNotFound notFound){
  1384.             // ignore
  1385.         }
  1386.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1387.        
  1388.         try{
  1389.             this.cache.remove(getKeyMethodGetAccessoConfigurazione());
  1390.             this.getAccessoConfigurazione(connectionPdD);
  1391.         }
  1392.         catch(DriverConfigurazioneNotFound notFound){
  1393.             // ignore
  1394.         }
  1395.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1396.        
  1397.         try{
  1398.             this.cache.remove(getKeyMethodGetAccessoDatiAutorizzazione());
  1399.             this.getAccessoDatiAutorizzazione(connectionPdD);
  1400.         }
  1401.         catch(DriverConfigurazioneNotFound notFound){
  1402.             // ignore
  1403.         }
  1404.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1405.        
  1406.         try{
  1407.             this.cache.remove(getMethodGetAccessoDatiAutenticazione());
  1408.             this.getAccessoDatiAutenticazione(connectionPdD);
  1409.         }
  1410.         catch(DriverConfigurazioneNotFound notFound){
  1411.             // ignore
  1412.         }
  1413.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1414.        
  1415.         try{
  1416.             this.cache.remove(getKeyMethodGetAccessoDatiGestioneToken());
  1417.             this.getAccessoDatiGestioneToken(connectionPdD);
  1418.         }
  1419.         catch(DriverConfigurazioneNotFound notFound){
  1420.             // ignore
  1421.         }
  1422.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1423.        
  1424.         try{
  1425.             this.cache.remove(getKeyMethodGetAccessoDatiAttributeAuthority());
  1426.             this.getAccessoDatiAttributeAuthority(connectionPdD);
  1427.         }
  1428.         catch(DriverConfigurazioneNotFound notFound){
  1429.             // ignore
  1430.         }
  1431.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1432.        
  1433.         try{
  1434.             this.cache.remove(getKeyMethodGetAccessoDatiKeystore());
  1435.             this.getAccessoDatiKeystore(connectionPdD);
  1436.         }
  1437.         catch(DriverConfigurazioneNotFound notFound){
  1438.             // ignore
  1439.         }
  1440.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1441.        
  1442.         try{
  1443.             this.cache.remove(getKeyMethodGetAccessoDatiRichieste());
  1444.             this.getAccessoDatiRichieste(connectionPdD);
  1445.         }
  1446.         catch(DriverConfigurazioneNotFound notFound){
  1447.             // ignore
  1448.         }
  1449.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1450.        
  1451.         try{
  1452.             this.cache.remove(_getKey_getGestioneErrore(false));
  1453.             this.getGestioneErroreComponenteIntegrazione(connectionPdD);
  1454.         }
  1455.         catch(DriverConfigurazioneNotFound notFound){
  1456.             // ignore
  1457.         }
  1458.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1459.        
  1460.         try{
  1461.             this.cache.remove(_getKey_getGestioneErrore(true));
  1462.             this.getGestioneErroreComponenteCooperazione(connectionPdD);
  1463.         }
  1464.         catch(DriverConfigurazioneNotFound notFound){
  1465.             // ignore
  1466.         }
  1467.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}

  1468.         try{
  1469.             this.cache.remove(_getKey_getConfigurazioneGenerale());
  1470.             this.getConfigurazioneGenerale(connectionPdD);
  1471.         }
  1472.         catch(DriverConfigurazioneNotFound notFound){
  1473.             // ignore
  1474.         }
  1475.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1476.        
  1477.         List<GenericProperties> listGenericProperties = null;
  1478.         try{
  1479.             listGenericProperties = this.driverConfigurazionePdD.getGenericProperties();
  1480.         }catch(DriverConfigurazioneNotFound notFound){
  1481.             // ignore
  1482.         }
  1483.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1484.         if(listGenericProperties!=null && listGenericProperties.size()>0) {
  1485.             for (GenericProperties genericProperties : listGenericProperties) {
  1486.                
  1487.                 try{
  1488.                     this.cache.remove(_getKey_getGenericProperties(genericProperties.getTipologia()));
  1489.                     this.getGenericProperties(connectionPdD, genericProperties.getTipologia());
  1490.                 }
  1491.                 catch(DriverConfigurazioneNotFound notFound){
  1492.                     // ignore
  1493.                 }
  1494.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1495.                
  1496.                 try{
  1497.                     this.cache.remove(_getKey_getGenericProperties(genericProperties.getTipologia(), genericProperties.getNome()));
  1498.                     this.getGenericProperties(connectionPdD, genericProperties.getTipologia(), genericProperties.getNome());
  1499.                 }
  1500.                 catch(DriverConfigurazioneNotFound notFound){
  1501.                     // ignore
  1502.                 }
  1503.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1504.             }
  1505.         }
  1506.        
  1507.         try{
  1508.             this.cache.remove(_getKey_getConfigurazioneWithOnlyExtendedInfo());
  1509.             this.getConfigurazioneWithOnlyExtendedInfo(connectionPdD);
  1510.         }
  1511.         catch(DriverConfigurazioneNotFound notFound){
  1512.             // ignore
  1513.         }
  1514.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1515.        

  1516.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD) completata";
  1517.         this.logInfo(msg);
  1518.         if(alogConsole!=null){
  1519.             alogConsole.info(msg);
  1520.         }

  1521.         // *** Controllo Traffico ***
  1522.        
  1523.         if(this.openspcoopProperties.isControlloTrafficoEnabled()) {
  1524.        
  1525.             msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura della configurazione ...";
  1526.             this.logDebug(msg);
  1527.             if(alogConsole!=null){
  1528.                 alogConsole.debug(msg);
  1529.             }
  1530.            
  1531.             try{
  1532.                 this.cache.remove(_getKey_ConfigurazioneControlloTraffico());
  1533.                 this.getConfigurazioneControlloTraffico(connectionPdD);
  1534.             }
  1535.             catch(DriverConfigurazioneNotFound notFound){
  1536.                 // ignore
  1537.             }
  1538.             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1539.            
  1540.             msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura della configurazione completata";
  1541.             this.logDebug(msg);
  1542.             if(alogConsole!=null){
  1543.                 alogConsole.debug(msg);
  1544.             }
  1545.            
  1546.            
  1547.            
  1548.             msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura della configurazione delle policy globali di rate limiting ...";
  1549.             this.logDebug(msg);
  1550.             if(alogConsole!=null){
  1551.                 alogConsole.debug(msg);
  1552.             }
  1553.            
  1554.             try{
  1555.                 this.cache.remove(_getKey_getConfigurazionePolicyRateLimitingGlobali());
  1556.                 this.getConfigurazionePolicyRateLimitingGlobali(connectionPdD);
  1557.             }
  1558.             catch(DriverConfigurazioneNotFound notFound){
  1559.                 // ignore
  1560.             }
  1561.             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1562.            
  1563.             msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura della configurazione delle policy globali di rate limiting completata";
  1564.             this.logDebug(msg);
  1565.             if(alogConsole!=null){
  1566.                 alogConsole.debug(msg);
  1567.             }
  1568.            
  1569.            
  1570.            
  1571.            
  1572.             msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura delle policy configurate ...";
  1573.             this.logDebug(msg);
  1574.             if(alogConsole!=null){
  1575.                 alogConsole.debug(msg);
  1576.             }
  1577.            
  1578.             ElencoIdPolicy elencoPolicyConfigurate = null;
  1579.             try{
  1580.                 this.cache.remove(_getKey_ElencoIdPolicy());
  1581.                 elencoPolicyConfigurate = this.getElencoIdPolicy(connectionPdD, true);
  1582.             }
  1583.             catch(DriverConfigurazioneNotFound notFound){
  1584.                 // ignore
  1585.             }
  1586.             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1587.            
  1588.             if(elencoPolicyConfigurate!=null && elencoPolicyConfigurate.sizeIdPolicyList()>0) {
  1589.                
  1590.                 msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura di "+elencoPolicyConfigurate.sizeIdPolicyList()+" policy configurate ...";
  1591.                 this.logDebug(msg);
  1592.                 if(alogConsole!=null){
  1593.                     alogConsole.debug(msg);
  1594.                 }
  1595.                
  1596.                 for (IdPolicy idPolicy : elencoPolicyConfigurate.getIdPolicyList()) {
  1597.                
  1598.                     try{
  1599.                         this.cache.remove(_getKey_ConfigurazionePolicy(idPolicy.getNome()));
  1600.                         this.getConfigurazionePolicy(connectionPdD, true, idPolicy.getNome());
  1601.                     }
  1602.                     catch(DriverConfigurazioneNotFound notFound){
  1603.                         // ignore
  1604.                     }
  1605.                     catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1606.                    
  1607.                 }
  1608.                
  1609.                 msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura di "+elencoPolicyConfigurate.sizeIdPolicyList()+" policy configurate completata";
  1610.                 this.logDebug(msg);
  1611.                 if(alogConsole!=null){
  1612.                     alogConsole.debug(msg);
  1613.                 }
  1614.                
  1615.             }
  1616.            
  1617.             msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura delle policy configurate completata";
  1618.             this.logDebug(msg);
  1619.             if(alogConsole!=null){
  1620.                 alogConsole.debug(msg);
  1621.             }
  1622.            
  1623.            
  1624.             this.prefillElencoPolicyAttive(alogConsole, connectionPdD, false, null, null);      

  1625.            
  1626.            
  1627.             if(this.openspcoopProperties.isConfigurazionePluginsEnabled()) {
  1628.            
  1629.                 msg = "[Prefill] Inizializzazione cache (Plugins), lettura dei pluins configurati ...";
  1630.                 this.logDebug(msg);
  1631.                 if(alogConsole!=null){
  1632.                     alogConsole.debug(msg);
  1633.                 }
  1634.            
  1635.                 int count = -1;
  1636.                 try {
  1637.                     count = this.configurazionePdD_plugins.countPlugins(connectionPdD);
  1638.                 }
  1639.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1640.                
  1641.                 if(count>-1) {
  1642.                     msg = "[Prefill] Inizializzazione cache (Plugins), trovati "+count+" plugins";
  1643.                     this.logDebug(msg);
  1644.                     if(alogConsole!=null){
  1645.                         alogConsole.debug(msg);
  1646.                     }
  1647.                    
  1648.                     int readed = 0;
  1649.                     while(readed<count) {
  1650.                    
  1651.                         int offset = readed;
  1652.                         int limit = 100;
  1653.                        
  1654.                         msg = "[Prefill] Inizializzazione cache (Plugins), inizializzazione (offset:"+offset+" limit:"+limit+") in corso ...";
  1655.                         this.logDebug(msg);
  1656.                         if(alogConsole!=null){
  1657.                             alogConsole.debug(msg);
  1658.                         }
  1659.                        
  1660.                         List<IdPlugin> list = null;
  1661.                         try {
  1662.                             list = this.configurazionePdD_plugins.findAllPluginIds(connectionPdD, offset, limit);
  1663.                             if(list!=null && !list.isEmpty()) {
  1664.                                 for (IdPlugin idPlugin : list) {
  1665.                                    
  1666.                                     TipoPlugin tipoPlugin = TipoPlugin.toEnumConstant(idPlugin.getTipoPlugin());
  1667.                                     if(tipoPlugin!=null) {
  1668.                                         if(TipoPlugin.AUTENTICAZIONE.equals(tipoPlugin) ||
  1669.                                                 TipoPlugin.AUTORIZZAZIONE.equals(tipoPlugin) ||
  1670.                                                 TipoPlugin.AUTORIZZAZIONE_CONTENUTI.equals(tipoPlugin) ||
  1671.                                                 TipoPlugin.INTEGRAZIONE.equals(tipoPlugin)) {
  1672.                                            
  1673.                                             NameValue nvFruizione = new NameValue(PluginCostanti.FILTRO_RUOLO_NOME, PluginCostanti.FILTRO_RUOLO_VALORE_FRUIZIONE);
  1674.                                             try{
  1675.                                                 this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvFruizione));
  1676.                                                 this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvFruizione);
  1677.                                             }
  1678.                                             catch(DriverConfigurazioneNotFound notFound){
  1679.                                                 // ignore
  1680.                                             }
  1681.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1682.                                             try{
  1683.                                                 this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvFruizione));
  1684.                                                 this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvFruizione);
  1685.                                             }
  1686.                                             catch(DriverConfigurazioneNotFound notFound){
  1687.                                                 // ignore
  1688.                                             }
  1689.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}

  1690.                                             NameValue nvErogazione = new NameValue(PluginCostanti.FILTRO_RUOLO_NOME, PluginCostanti.FILTRO_RUOLO_VALORE_EROGAZIONE);
  1691.                                             try{
  1692.                                                 this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvErogazione));
  1693.                                                 this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvErogazione);
  1694.                                             }
  1695.                                             catch(DriverConfigurazioneNotFound notFound){
  1696.                                                 // ignore
  1697.                                             }
  1698.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1699.                                             try{
  1700.                                                 this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvErogazione));
  1701.                                                 this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvErogazione);
  1702.                                             }
  1703.                                             catch(DriverConfigurazioneNotFound notFound){
  1704.                                                 // ignore
  1705.                                             }
  1706.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1707.                                         }
  1708.                                         else if(TipoPlugin.MESSAGE_HANDLER.equals(tipoPlugin)){
  1709.                                        
  1710.                                             List<String> filtri = PluginCostanti.FILTRO_FASE_MESSAGE_HANDLER_VALORI_RICHIESTA;
  1711.                                             for (String valoreFiltro : filtri) {
  1712.                                                 NameValue nvRuolo = new NameValue(PluginCostanti.FILTRO_RUOLO_MESSAGE_HANDLER_NOME, PluginCostanti.FILTRO_RUOLO_MESSAGE_HANDLER_VALORE_RICHIESTA);
  1713.                                                 NameValue nv = new NameValue(PluginCostanti.FILTRO_FASE_MESSAGE_HANDLER_NOME, valoreFiltro);
  1714.                                                 try{
  1715.                                                     this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvRuolo,nv));
  1716.                                                     this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvRuolo,nv);
  1717.                                                 }
  1718.                                                 catch(DriverConfigurazioneNotFound notFound){
  1719.                                                     // ignore
  1720.                                                 }
  1721.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1722.                                                 try{
  1723.                                                     this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvRuolo,nv));
  1724.                                                     this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvRuolo,nv);
  1725.                                                 }
  1726.                                                 catch(DriverConfigurazioneNotFound notFound){
  1727.                                                     // ignore
  1728.                                                 }
  1729.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1730.                                             }
  1731.                                             filtri = PluginCostanti.FILTRO_FASE_MESSAGE_HANDLER_VALORI_RISPOSTA;
  1732.                                             for (String valoreFiltro : filtri) {
  1733.                                                 NameValue nvRuolo = new NameValue(PluginCostanti.FILTRO_RUOLO_MESSAGE_HANDLER_NOME, PluginCostanti.FILTRO_RUOLO_MESSAGE_HANDLER_VALORE_RISPOSTA);
  1734.                                                 NameValue nv = new NameValue(PluginCostanti.FILTRO_FASE_MESSAGE_HANDLER_NOME, valoreFiltro);
  1735.                                                 try{
  1736.                                                     this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvRuolo,nv));
  1737.                                                     this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvRuolo,nv);
  1738.                                                 }
  1739.                                                 catch(DriverConfigurazioneNotFound notFound){
  1740.                                                     // ignore
  1741.                                                 }
  1742.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1743.                                                 try{
  1744.                                                     this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvRuolo,nv));
  1745.                                                     this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvRuolo,nv);
  1746.                                                 }
  1747.                                                 catch(DriverConfigurazioneNotFound notFound){
  1748.                                                     // ignore
  1749.                                                 }
  1750.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1751.                                             }
  1752.                                            
  1753.                                         }
  1754.                                         else if(TipoPlugin.SERVICE_HANDLER.equals(tipoPlugin)){
  1755.                                            
  1756.                                             List<String> filtri = PluginCostanti.FILTRO_SERVICE_HANDLER_VALORI_CON_INTEGRATION_MANAGER;
  1757.                                             for (String valoreFiltro : filtri) {
  1758.                                                 NameValue nv = new NameValue(PluginCostanti.FILTRO_SERVICE_HANDLER_NOME, valoreFiltro);
  1759.                                                 try{
  1760.                                                     this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nv));
  1761.                                                     this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nv);
  1762.                                                 }
  1763.                                                 catch(DriverConfigurazioneNotFound notFound){
  1764.                                                     // ignore
  1765.                                                 }
  1766.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1767.                                                 try{
  1768.                                                     this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nv));
  1769.                                                     this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nv);
  1770.                                                 }
  1771.                                                 catch(DriverConfigurazioneNotFound notFound){
  1772.                                                     // ignore
  1773.                                                 }
  1774.                                                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1775.                                             }

  1776.                                         }
  1777.                                         else if(TipoPlugin.ALLARME.equals(tipoPlugin) && this.openspcoopProperties.isAllarmiEnabled()) {
  1778.                                            
  1779.                                             NameValue nvFruizione = new NameValue(PluginCostanti.FILTRO_APPLICABILITA_NOME, PluginCostanti.FILTRO_APPLICABILITA_VALORE_FRUIZIONE);
  1780.                                             try{
  1781.                                                 this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvFruizione));
  1782.                                                 this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvFruizione);
  1783.                                             }
  1784.                                             catch(DriverConfigurazioneNotFound notFound){
  1785.                                                 // ignore
  1786.                                             }
  1787.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1788.                                             try{
  1789.                                                 this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvFruizione));
  1790.                                                 this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvFruizione);
  1791.                                             }
  1792.                                             catch(DriverConfigurazioneNotFound notFound){
  1793.                                                 // ignore
  1794.                                             }
  1795.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}

  1796.                                             NameValue nvErogazione = new NameValue(PluginCostanti.FILTRO_APPLICABILITA_NOME, PluginCostanti.FILTRO_APPLICABILITA_VALORE_EROGAZIONE);
  1797.                                             try{
  1798.                                                 this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvErogazione));
  1799.                                                 this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvErogazione);
  1800.                                             }
  1801.                                             catch(DriverConfigurazioneNotFound notFound){
  1802.                                                 // ignore
  1803.                                             }
  1804.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1805.                                             try{
  1806.                                                 this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvErogazione));
  1807.                                                 this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvErogazione);
  1808.                                             }
  1809.                                             catch(DriverConfigurazioneNotFound notFound){
  1810.                                                 // ignore
  1811.                                             }
  1812.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1813.                                            
  1814.                                             NameValue nvConfigurazione = new NameValue(PluginCostanti.FILTRO_APPLICABILITA_NOME, PluginCostanti.FILTRO_APPLICABILITA_VALORE_CONFIGURAZIONE);
  1815.                                             try{
  1816.                                                 this.cache.remove(_getKey_PluginClassNameByFilter(idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvConfigurazione));
  1817.                                                 this.getPluginClassNameByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo(),nvConfigurazione);
  1818.                                             }
  1819.                                             catch(DriverConfigurazioneNotFound notFound){
  1820.                                                 // ignore
  1821.                                             }
  1822.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1823.                                             try{
  1824.                                                 this.cache.remove(_getKey_PluginTipoByFilter(idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvConfigurazione));
  1825.                                                 this.getPluginTipoByFilter(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName(),nvConfigurazione);
  1826.                                             }
  1827.                                             catch(DriverConfigurazioneNotFound notFound){
  1828.                                                 // ignore
  1829.                                             }
  1830.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1831.                                         }
  1832.                                         else {
  1833.                                             try{
  1834.                                                 this.cache.remove(_getKey_PluginClassName(idPlugin.getTipoPlugin(),idPlugin.getTipo()));
  1835.                                                 this.getPluginClassName(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo());
  1836.                                             }
  1837.                                             catch(DriverConfigurazioneNotFound notFound){
  1838.                                                 // ignore
  1839.                                             }
  1840.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1841.                                            
  1842.                                             try{
  1843.                                                 this.cache.remove(_getKey_PluginTipo(idPlugin.getTipoPlugin(),idPlugin.getClassName()));
  1844.                                                 this.getPluginTipo(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName());
  1845.                                             }
  1846.                                             catch(DriverConfigurazioneNotFound notFound){
  1847.                                                 // ignore
  1848.                                             }
  1849.                                             catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1850.                                         }
  1851.                                     }
  1852.                                     else {
  1853.                                         try{
  1854.                                             this.cache.remove(_getKey_PluginClassName(idPlugin.getTipoPlugin(),idPlugin.getTipo()));
  1855.                                             this.getPluginClassName(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getTipo());
  1856.                                         }
  1857.                                         catch(DriverConfigurazioneNotFound notFound){
  1858.                                             // ignore
  1859.                                         }
  1860.                                         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1861.                                         try{
  1862.                                             this.cache.remove(_getKey_PluginTipo(idPlugin.getTipoPlugin(),idPlugin.getClassName()));
  1863.                                             this.getPluginTipo(connectionPdD, idPlugin.getTipoPlugin(),idPlugin.getClassName());
  1864.                                         }
  1865.                                         catch(DriverConfigurazioneNotFound notFound){
  1866.                                             // ignore
  1867.                                         }
  1868.                                         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1869.                                     }
  1870.                                 }
  1871.                                 readed = readed + list.size();
  1872.                             }
  1873.                             else {
  1874.                                 readed = count; // condizione per uscire da while
  1875.                             }
  1876.                         }
  1877.                         catch(Exception e){
  1878.                             this.logError("[prefill] errore"+e.getMessage(),e);
  1879.                             readed = count; // condizione per uscire da while
  1880.                         }
  1881.                        
  1882.                     }
  1883.                 }
  1884.                
  1885.                 msg = "[Prefill] Inizializzazione cache (Plugins), lettura dei pluins configurati completata";
  1886.                 this.logDebug(msg);
  1887.                 if(alogConsole!=null){
  1888.                     alogConsole.debug(msg);
  1889.                 }
  1890.             }
  1891.         }
  1892.     }
  1893.    
  1894.     private void prefillElencoPolicyAttive(Logger alogConsole, Connection connectionPdD, boolean api, TipoPdD tipoPdD, String nomePorta) {
  1895.        
  1896.         String tipo = "API";
  1897.         if(!api) {
  1898.             tipo = "globali";
  1899.         }
  1900.        
  1901.         String msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura delle policy "+tipo+" attive ...";
  1902.         this.logDebug(msg);
  1903.         if(alogConsole!=null){
  1904.             alogConsole.debug(msg);
  1905.         }
  1906.        
  1907.         Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> mapPolicyAttive = null;
  1908.         try{
  1909.             if(api) {
  1910.                 this.cache.remove(getKeyMethodElencoIdPolicyAttiveAPI(tipoPdD, nomePorta));
  1911.                 mapPolicyAttive = this.getElencoIdPolicyAttiveAPI(connectionPdD, true, tipoPdD, nomePorta);
  1912.             }
  1913.             else {
  1914.                 this.cache.remove(getKeyMethodElencoIdPolicyAttiveGlobali());
  1915.                 mapPolicyAttive = this.getElencoIdPolicyAttiveGlobali(connectionPdD, true);
  1916.             }
  1917.         }
  1918.         catch(DriverConfigurazioneNotFound notFound){
  1919.             // ignore
  1920.         }
  1921.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1922.        
  1923.         if(mapPolicyAttive!=null && !mapPolicyAttive.isEmpty()) {
  1924.        
  1925.             Iterator<TipoRisorsaPolicyAttiva> it = mapPolicyAttive.keySet().iterator();
  1926.             while (it.hasNext()) {
  1927.                 TipoRisorsaPolicyAttiva tipoRisorsaPolicyAttiva = (TipoRisorsaPolicyAttiva) it.next();
  1928.                 ElencoIdPolicyAttive elencoPolicyAttive = mapPolicyAttive.get(tipoRisorsaPolicyAttiva);
  1929.            
  1930.                 if(elencoPolicyAttive!=null && elencoPolicyAttive.sizeIdActivePolicyList()>0) {
  1931.                    
  1932.                     msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura di "+elencoPolicyAttive.sizeIdActivePolicyList()+" policy "+tipo+" attive (risorsa: "+tipoRisorsaPolicyAttiva+") ...";
  1933.                     this.logDebug(msg);
  1934.                     if(alogConsole!=null){
  1935.                         alogConsole.debug(msg);
  1936.                     }
  1937.                    
  1938.                     for (IdActivePolicy idActivePolicy : elencoPolicyAttive.getIdActivePolicyList()) {
  1939.                    
  1940.                         try{
  1941.                             String id = UniqueIdentifierUtilities.getUniqueId(idActivePolicy);
  1942.                             this.cache.remove(_getKey_AttivazionePolicy(id));
  1943.                             this.getAttivazionePolicy(connectionPdD, true, id);
  1944.                         }
  1945.                         catch(DriverConfigurazioneNotFound notFound){
  1946.                             // ignore
  1947.                         }
  1948.                         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1949.                        
  1950.                     }
  1951.                    
  1952.                     msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura di "+elencoPolicyAttive.sizeIdActivePolicyList()+" policy "+tipo+" attive (risorsa: "+tipoRisorsaPolicyAttiva+") completata";
  1953.                     this.logDebug(msg);
  1954.                     if(alogConsole!=null){
  1955.                         alogConsole.debug(msg);
  1956.                     }
  1957.                    
  1958.                 }
  1959.             }
  1960.                        
  1961.         }
  1962.        
  1963.         Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> mapPolicyAttiveDimensioneMessaggio = null;
  1964.         try{
  1965.             if(api) {
  1966.                 this.cache.remove(getKeyMethodElencoIdPolicyAttiveAPIDimensioneMessaggio(tipoPdD, nomePorta));
  1967.                 mapPolicyAttiveDimensioneMessaggio = this.getElencoIdPolicyAttiveAPIDimensioneMessaggio(connectionPdD, true, tipoPdD, nomePorta);
  1968.             }
  1969.             else {
  1970.                 this.cache.remove(getKeyMethodElencoIdPolicyAttiveGlobaliDimensioneMessaggio());
  1971.                 mapPolicyAttiveDimensioneMessaggio = this.getElencoIdPolicyAttiveGlobaliDimensioneMessaggio(connectionPdD, true);
  1972.             }
  1973.         }
  1974.         catch(DriverConfigurazioneNotFound notFound){
  1975.             // ignore
  1976.         }
  1977.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  1978.        
  1979.         if(mapPolicyAttiveDimensioneMessaggio!=null && !mapPolicyAttiveDimensioneMessaggio.isEmpty()) {
  1980.        
  1981.             Iterator<TipoRisorsaPolicyAttiva> it = mapPolicyAttiveDimensioneMessaggio.keySet().iterator();
  1982.             while (it.hasNext()) {
  1983.                 TipoRisorsaPolicyAttiva tipoRisorsaPolicyAttiva = (TipoRisorsaPolicyAttiva) it.next();
  1984.                 ElencoIdPolicyAttive elencoPolicyAttive = mapPolicyAttiveDimensioneMessaggio.get(tipoRisorsaPolicyAttiva);
  1985.            
  1986.                 if(elencoPolicyAttive!=null && elencoPolicyAttive.sizeIdActivePolicyList()>0) {
  1987.                    
  1988.                     msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura di "+elencoPolicyAttive.sizeIdActivePolicyList()+" policy "+tipo+" attive (risorsa: "+tipoRisorsaPolicyAttiva+") ...";
  1989.                     this.logDebug(msg);
  1990.                     if(alogConsole!=null){
  1991.                         alogConsole.debug(msg);
  1992.                     }
  1993.                    
  1994.                     for (IdActivePolicy idActivePolicy : elencoPolicyAttive.getIdActivePolicyList()) {
  1995.                    
  1996.                         try{
  1997.                             String id = UniqueIdentifierUtilities.getUniqueId(idActivePolicy);
  1998.                             this.cache.remove(_getKey_AttivazionePolicy(id));
  1999.                             this.getAttivazionePolicy(connectionPdD, true, id);
  2000.                         }
  2001.                         catch(DriverConfigurazioneNotFound notFound){
  2002.                             // ignore
  2003.                         }
  2004.                         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2005.                        
  2006.                     }
  2007.                    
  2008.                     msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura di "+elencoPolicyAttive.sizeIdActivePolicyList()+" policy "+tipo+" attive (risorsa: "+tipoRisorsaPolicyAttiva+") completata";
  2009.                     this.logDebug(msg);
  2010.                     if(alogConsole!=null){
  2011.                         alogConsole.debug(msg);
  2012.                     }
  2013.                    
  2014.                 }
  2015.             }
  2016.                        
  2017.         }
  2018.        
  2019.         msg = "[Prefill] Inizializzazione cache (ControlloTraffico), lettura delle policy "+tipo+" attive completata";
  2020.         this.logDebug(msg);
  2021.         if(alogConsole!=null){
  2022.             alogConsole.debug(msg);
  2023.         }
  2024.     }
  2025.    
  2026.     public void prefillCacheConInformazioniRegistro(Logger alogConsole){
  2027.        
  2028.         String msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD-RegistroServizi) in corso ...";
  2029.         this.logInfo(msg);
  2030.         if(alogConsole!=null){
  2031.             alogConsole.info(msg);
  2032.         }
  2033.        
  2034.         RegistroServiziReader registroServiziReader = RegistroServiziManager.getInstance().getRegistroServiziReader();
  2035.        
  2036.        
  2037.         org.openspcoop2.core.registry.driver.FiltroRicercaSoggetti filtroSoggetti = new org.openspcoop2.core.registry.driver.FiltroRicercaSoggetti();
  2038.         @SuppressWarnings("unused")
  2039.         List<IDSoggetto> listSoggetti = null;
  2040.         try{
  2041.             listSoggetti = registroServiziReader.getAllIdSoggetti_noCache(filtroSoggetti,null);
  2042.         }
  2043.         catch(DriverRegistroServiziNotFound notFound){
  2044.             // ignore
  2045.         }
  2046.         catch(DriverRegistroServiziException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2047.        
  2048.         org.openspcoop2.core.registry.driver.FiltroRicercaServizi filtroServizi = new org.openspcoop2.core.registry.driver.FiltroRicercaServizi();
  2049.         List<IDServizio> listIdServizi = null;
  2050.         try{
  2051.             listIdServizi = registroServiziReader.getAllIdServizi_noCache(filtroServizi,null);
  2052.         }
  2053.         catch(DriverRegistroServiziNotFound notFound){
  2054.             // ignore
  2055.         }
  2056.         catch(DriverRegistroServiziException e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2057.        
  2058.         List<IDSoggetto> soggettiVirtuali = null;
  2059.         try{
  2060.             this.cache.remove(_getKey_getSoggettiVirtuali());
  2061.             soggettiVirtuali = this.getSoggettiVirtuali(null);
  2062.         }
  2063.         catch(DriverConfigurazioneNotFound notFound){
  2064.             // ignore
  2065.         }
  2066.         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2067.        
  2068.         if(listIdServizi!=null && listIdServizi.size()>0){
  2069.        
  2070.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD-RegistroServizi), lettura di "+listIdServizi.size()+" servizi ...";
  2071.             this.logDebug(msg);
  2072.             if(alogConsole!=null){
  2073.                 alogConsole.debug(msg);
  2074.             }
  2075.            
  2076.             for (IDServizio idServizio : listIdServizi) {
  2077.            
  2078.                 msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati registro correlati al servizio ["+idServizio+"] ...";
  2079.                 this.logDebug(msg);
  2080.                 if(alogConsole!=null){
  2081.                     alogConsole.debug(msg);
  2082.                 }
  2083.                
  2084.                 try{
  2085.                     this.cache.remove(_getKey_getPorteApplicative(idServizio,false));
  2086.                     this.getPorteApplicative(null, idServizio, false);
  2087.                 }
  2088.                 catch(DriverConfigurazioneNotFound notFound){
  2089.                     // ignore
  2090.                 }
  2091.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2092.                
  2093.                 try{
  2094.                     this.cache.remove(_getKey_getPorteApplicative(idServizio,true));
  2095.                     this.getPorteApplicative(null, idServizio, true);
  2096.                 }
  2097.                 catch(DriverConfigurazioneNotFound notFound){
  2098.                     // ignore
  2099.                 }
  2100.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2101.                
  2102.                 try{
  2103.                     this.cache.remove(getKeyMethodGetPorteApplicativeSoggettiVirtuali(idServizio));
  2104.                     this.getPorteApplicativeSoggettiVirtuali(null, idServizio, null, false);
  2105.                 }
  2106.                 catch(DriverConfigurazioneNotFound notFound){
  2107.                     // ignore
  2108.                 }
  2109.                 catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2110.                
  2111.                 if(soggettiVirtuali!=null && soggettiVirtuali.size()>0) {
  2112.                    
  2113.                     msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati registro correlati al servizio per soggetti virtuali ("+soggettiVirtuali.size()+") ["+idServizio+"] ...";
  2114.                     this.logDebug(msg);
  2115.                     if(alogConsole!=null){
  2116.                         alogConsole.debug(msg);
  2117.                     }
  2118.                    
  2119.                     for (IDSoggetto idSoggetto : soggettiVirtuali) {
  2120.                        
  2121.                         try{
  2122.                             this.cache.remove(_getKey_getPorteApplicativeVirtuali(idSoggetto, idServizio,false));
  2123.                             this.getPorteApplicativeVirtuali(null, idSoggetto, idServizio, false);
  2124.                         }
  2125.                         catch(DriverConfigurazioneNotFound notFound){
  2126.                             // ignore
  2127.                         }
  2128.                         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2129.                        
  2130.                         try{
  2131.                             this.cache.remove(_getKey_getPorteApplicativeVirtuali(idSoggetto, idServizio,true));
  2132.                             this.getPorteApplicativeVirtuali(null, idSoggetto, idServizio, true);
  2133.                         }
  2134.                         catch(DriverConfigurazioneNotFound notFound){
  2135.                             // ignore
  2136.                         }
  2137.                         catch(Exception e){this.logError("[prefill] errore"+e.getMessage(),e);}
  2138.                        
  2139.                     }
  2140.                        
  2141.                     msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati registro correlati al servizio per soggetti virtuali ("+soggettiVirtuali.size()+") ["+idServizio+"] completata";
  2142.                     this.logDebug(msg);
  2143.                     if(alogConsole!=null){
  2144.                         alogConsole.debug(msg);
  2145.                     }
  2146.                 }
  2147.                
  2148.                 msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD), lettura dati registro correlati al servizio ["+idServizio+"] completata";
  2149.                 this.logDebug(msg);
  2150.                 if(alogConsole!=null){
  2151.                     alogConsole.debug(msg);
  2152.                 }
  2153.             }
  2154.             msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD-RegistroServizi), lettura di "+listIdServizi.size()+" servizi completata";
  2155.             this.logDebug(msg);
  2156.             if(alogConsole!=null){
  2157.                 alogConsole.debug(msg);
  2158.             }
  2159.         }
  2160.        
  2161.         msg = "[Prefill] Inizializzazione cache (ConfigurazionePdD-RegistroServizi) completata";
  2162.         this.logInfo(msg);
  2163.         if(alogConsole!=null){
  2164.             alogConsole.info(msg);
  2165.         }
  2166.     }
  2167.    
  2168.    
  2169.    
  2170.    
  2171.    
  2172.     /**
  2173.      * Si occupa di effettuare una ricerca nella configurazione, e di inserire la ricerca in cache
  2174.      */
  2175.     public Object getObjectCache(String keyCache,String methodName,
  2176.             Connection connectionPdD,
  2177.             ConfigurazionePdDType tipoConfigurazione,
  2178.             Object ... instances) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2179.         Class<?>[] classArgoments = null;
  2180.         Object[] values = null;
  2181.         if(instances!=null && instances.length>0){
  2182.             classArgoments = new Class<?>[instances.length];
  2183.             values = new Object[instances.length];
  2184.             for (int i = 0; i < instances.length; i++) {
  2185.                 classArgoments[i] = instances[i].getClass();
  2186.                 if(classArgoments[i].getPackage()!=null &&
  2187.                         classArgoments[i].getPackage().getName()!=null &&
  2188.                         classArgoments[i].getPackage().getName().equals("org.openspcoop2.protocol.sdk.registry")) {
  2189.                     try {
  2190.                         if(classArgoments[i].getSimpleName().startsWith("ProtocolFiltro")) {
  2191.                             classArgoments[i] = Class.forName("org.openspcoop2.core.config.driver."+classArgoments[i].getSimpleName().replace("ProtocolFiltro", "Filtro"));
  2192.                         }
  2193.                         else {
  2194.                             classArgoments[i] = Class.forName("org.openspcoop2.core.config.driver."+classArgoments[i].getSimpleName());
  2195.                         }
  2196.                     }catch(Exception e) {
  2197.                         throw new DriverConfigurazioneException(e.getMessage(),e);
  2198.                     }
  2199.                 }
  2200.                 if("getServizioApplicativoByCredenzialiApiKey".equals(methodName) && i==2) {
  2201.                     classArgoments[i] = boolean.class;
  2202.                 }
  2203.                 else if("getServizioApplicativoByCredenzialiToken".equals(methodName) && i==2) {
  2204.                     classArgoments[i] = boolean.class;
  2205.                 }
  2206.                 else if("instanceAllarmi".equals(methodName) && i==0) {
  2207.                     classArgoments[i] = List.class;
  2208.                 }
  2209.                 values[i] = instances[i];
  2210.             }
  2211.         }
  2212.         return getObjectCache(keyCache, methodName, connectionPdD, tipoConfigurazione, classArgoments, values);
  2213.     }
  2214.     private static org.openspcoop2.utils.Semaphore semaphore_getObjectCache = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_Object");
  2215.     public Object getObjectCache(String keyCache,String methodName,
  2216.             Connection connectionPdD,
  2217.             ConfigurazionePdDType tipoConfigurazione,
  2218.             Class<?>[] classArgoments, Object[] values) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2219.         SemaphoreLock lock = semaphore_getObjectCache.acquireThrowRuntime("getObjectCache");
  2220.         DriverConfigurazioneNotFound dNotFound = null;
  2221.         Object obj = null;
  2222.         try{

  2223.             //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  2224.             //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));

  2225.             // Raccolta dati
  2226.             if(keyCache == null)
  2227.                 throw new DriverConfigurazioneException("["+methodName+"]: KeyCache non definita");

  2228.             // se e' attiva una cache provo ad utilizzarla
  2229.             if(this.cache!=null){
  2230.                 org.openspcoop2.utils.cache.CacheResponse response =
  2231.                         (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  2232.                 if(response != null){
  2233.                     if(response.getObject()!=null){
  2234.                         this.logDebug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  2235.                         return response.getObject();
  2236.                     }else if(response.getException()!=null){
  2237.                         this.logDebug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  2238.                         throw (Exception) response.getException();
  2239.                     }else{
  2240.                         this.logError("In cache non e' presente ne un oggetto ne un'eccezione.");
  2241.                     }
  2242.                 }
  2243.             }

  2244.             // Effettuo le query nella mia gerarchia di registri.
  2245.             this.logDebug("oggetto con chiave ["+keyCache+"] (methodo:"+methodName+") ricerco nella configurazione...");
  2246.             try{
  2247.                 obj = getObject(methodName,connectionPdD,tipoConfigurazione,classArgoments,values);
  2248.             }catch(DriverConfigurazioneNotFound e){
  2249.                 dNotFound = e;
  2250.             }

  2251.             // Aggiungo la risposta in cache (se esiste una cache)  
  2252.             // Se ho una eccezione aggiungo in cache solo una not found
  2253.             if( this.cache!=null ){    
  2254.                 if(dNotFound!=null){
  2255.                     this.logInfo("Aggiungo eccezione not found ["+keyCache+"] in cache");
  2256.                 }else if(obj!=null){
  2257.                     this.logInfo("Aggiungo oggetto ["+keyCache+"] in cache");
  2258.                 }else{
  2259.                     throw new Exception("Metodo ("+methodName+") ha ritornato un valore null");
  2260.                 }
  2261.                 try{    
  2262.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  2263.                     if(dNotFound!=null){
  2264.                         responseCache.setException(dNotFound);
  2265.                     }else{
  2266.                         responseCache.setObject((java.io.Serializable)obj);
  2267.                     }
  2268.                     this.cache.put(keyCache,responseCache);
  2269.                 }catch(UtilsException e){
  2270.                     this.logError("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  2271.                 }
  2272.             }

  2273.         }catch(DriverConfigurazioneException e){
  2274.             throw e;
  2275.         }catch(DriverConfigurazioneNotFound e){
  2276.             throw e;
  2277.         }catch(Exception e){
  2278.             if(notFoundClassName.equals(e.getClass().getName()))
  2279.                 throw (DriverConfigurazioneNotFound) e;
  2280.             else
  2281.                 throw new DriverConfigurazioneException("Configurazione, Algoritmo di Cache fallito: "+e.getMessage(),e);
  2282.         }finally {
  2283.             semaphore_getObjectCache.release(lock, "getObjectCache");
  2284.         }

  2285.         if(dNotFound!=null){
  2286.             throw dNotFound;
  2287.         }else
  2288.             return obj;
  2289.     }

  2290.     /**
  2291.      * Si occupa di effettuare una ricerca nella configurazione
  2292.      */
  2293.     public Object getObject(String methodNameParam,
  2294.             Connection connectionPdD,
  2295.             ConfigurazionePdDType tipoConfigurazione,
  2296.             Object ... instances) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2297.         Class<?>[] classArgoments = null;
  2298.         Object[] values = null;
  2299.         if(instances!=null && instances.length>0){
  2300.             classArgoments = new Class<?>[instances.length];
  2301.             values = new Object[instances.length];
  2302.             for (int i = 0; i < instances.length; i++) {
  2303.                 classArgoments[i] = instances[i].getClass();
  2304.                 if(classArgoments[i].getPackage()!=null &&
  2305.                         classArgoments[i].getPackage().getName()!=null &&
  2306.                         classArgoments[i].getPackage().getName().equals("org.openspcoop2.protocol.sdk.registry")) {
  2307.                     try {
  2308.                         if(classArgoments[i].getSimpleName().startsWith("ProtocolFiltro")) {
  2309.                             classArgoments[i] = Class.forName("org.openspcoop2.core.config.driver."+classArgoments[i].getSimpleName().replace("ProtocolFiltro", "Filtro"));
  2310.                         }
  2311.                         else {
  2312.                             classArgoments[i] = Class.forName("org.openspcoop2.core.config.driver."+classArgoments[i].getSimpleName());
  2313.                         }
  2314.                     }catch(Exception e) {
  2315.                         throw new DriverConfigurazioneException(e.getMessage(),e);
  2316.                     }
  2317.                 }
  2318.                 if("getServizioApplicativoByCredenzialiApiKey".equals(methodNameParam) && i==2) {
  2319.                     classArgoments[i] = boolean.class;
  2320.                 }
  2321.                 else if("getServizioApplicativoByCredenzialiToken".equals(methodNameParam) && i==2) {
  2322.                     classArgoments[i] = boolean.class;
  2323.                 }
  2324.                 else if("instanceAllarmi".equals(methodNameParam) && i==0) {
  2325.                     classArgoments[i] = List.class;
  2326.                 }
  2327.                 values[i] = instances[i];
  2328.             }
  2329.         }
  2330.         return getObject(methodNameParam, connectionPdD, tipoConfigurazione, classArgoments, values);
  2331.     }
  2332.     public Object getObject(String methodNameParam,
  2333.             Connection connectionPdD,
  2334.             ConfigurazionePdDType tipoConfigurazione,
  2335.             Class<?>[] classArgoments, Object[] values) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2336.         String methodName = null;
  2337.         if("getConfigurazioneWithOnlyExtendedInfo".equals(methodNameParam)){
  2338.             methodName = "getConfigurazioneGenerale";
  2339.         }
  2340.         else{
  2341.             methodName = methodNameParam+"";
  2342.         }

  2343.         // Effettuo le query nella mia gerarchia di registri.
  2344.         Object obj = null;
  2345.         DriverConfigurazioneNotFound notFound = null;
  2346.         this.logDebug("Cerco nella configurazione");
  2347.         try{
  2348.             switch (tipoConfigurazione) {
  2349.             case controlloTraffico:
  2350.             {
  2351.                 if(this.configurazionePdD_controlloTraffico==null) {
  2352.                     throw new Exception("Driver ControlloTraffico non istanziato");
  2353.                 }
  2354.                 this.logDebug("invocazione metodo ["+methodName+"]...");
  2355.                 if(classArgoments==null || classArgoments.length==0){
  2356.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class);
  2357.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD);
  2358.                 }else if(classArgoments.length==1){
  2359.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class, classArgoments[0]);
  2360.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD,values[0]);
  2361.                 }else if(classArgoments.length==2){
  2362.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1]);
  2363.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD,values[0],values[1]);
  2364.                 }else if(classArgoments.length==3){
  2365.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2]);
  2366.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD,values[0],values[1],values[2]);
  2367.                 }else if(classArgoments.length==4){
  2368.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3]);
  2369.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD,values[0],values[1],values[2],values[3]);
  2370.                 }else if(classArgoments.length==5){
  2371.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4]);
  2372.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD,values[0],values[1],values[2],values[3],values[4]);
  2373.                 }else if(classArgoments.length==6){
  2374.                     Method method =  this.configurazionePdD_controlloTraffico.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4],classArgoments[5]);
  2375.                     obj = method.invoke(this.configurazionePdD_controlloTraffico, connectionPdD,values[0],values[1],values[2],values[3],values[4],values[5]);
  2376.                 }else
  2377.                     throw new Exception("Troppi argomenti per gestire la chiamata del metodo");
  2378.                 break;
  2379.             }
  2380.             case plugins: {
  2381.                 if(this.configurazionePdD_plugins==null) {
  2382.                     throw new Exception("Driver Plugins non istanziato");
  2383.                 }
  2384.                 this.logDebug("invocazione metodo ["+methodName+"]...");
  2385.                 if(classArgoments==null || classArgoments.length==0){
  2386.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class);
  2387.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD);
  2388.                 }else if(classArgoments.length==1){
  2389.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class, classArgoments[0]);
  2390.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD,values[0]);
  2391.                 }else if(classArgoments.length==2){
  2392.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1]);
  2393.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD,values[0],values[1]);
  2394.                 }else if(classArgoments.length==3){
  2395.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2]);
  2396.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD,values[0],values[1],values[2]);
  2397.                 }else if(classArgoments.length==4){
  2398.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3]);
  2399.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD,values[0],values[1],values[2],values[3]);
  2400.                 }else if(classArgoments.length==5){
  2401.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4]);
  2402.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD,values[0],values[1],values[2],values[3],values[4]);
  2403.                 }else if(classArgoments.length==6){
  2404.                     Method method =  this.configurazionePdD_plugins.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4],classArgoments[5]);
  2405.                     obj = method.invoke(this.configurazionePdD_plugins, connectionPdD,values[0],values[1],values[2],values[3],values[4],values[5]);
  2406.                 }else
  2407.                     throw new Exception("Troppi argomenti per gestire la chiamata del metodo");
  2408.                 break;
  2409.             }
  2410.             case allarmi:
  2411.             {
  2412.                 if(this.configurazionePdD_allarmi==null) {
  2413.                     throw new Exception("Driver Allarmi non istanziato");
  2414.                 }
  2415.                 this.logDebug("invocazione metodo ["+methodName+"]...");
  2416.                 if(classArgoments==null || classArgoments.length==0){
  2417.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class);
  2418.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD);
  2419.                 }else if(classArgoments.length==1){
  2420.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class, classArgoments[0]);
  2421.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD,values[0]);
  2422.                 }else if(classArgoments.length==2){
  2423.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1]);
  2424.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD,values[0],values[1]);
  2425.                 }else if(classArgoments.length==3){
  2426.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2]);
  2427.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD,values[0],values[1],values[2]);
  2428.                 }else if(classArgoments.length==4){
  2429.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3]);
  2430.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD,values[0],values[1],values[2],values[3]);
  2431.                 }else if(classArgoments.length==5){
  2432.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4]);
  2433.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD,values[0],values[1],values[2],values[3],values[4]);
  2434.                 }else if(classArgoments.length==6){
  2435.                     Method method =  this.configurazionePdD_allarmi.getClass().getMethod(methodName, Connection.class, classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4],classArgoments[5]);
  2436.                     obj = method.invoke(this.configurazionePdD_allarmi, connectionPdD,values[0],values[1],values[2],values[3],values[4],values[5]);
  2437.                 }else
  2438.                     throw new Exception("Troppi argomenti per gestire la chiamata del metodo");
  2439.                 break;
  2440.             }
  2441.             case config: {
  2442.                 org.openspcoop2.core.config.driver.IDriverConfigurazioneGet driver = getDriver(connectionPdD);
  2443.                 this.logDebug("invocazione metodo ["+methodName+"]...");
  2444.                 if(classArgoments==null || classArgoments.length==0){
  2445.                     Method method =  driver.getClass().getMethod(methodName);
  2446.                     obj = method.invoke(driver);
  2447.                 }else if(classArgoments.length==1){
  2448.                     Method method =  driver.getClass().getMethod(methodName,classArgoments[0]);
  2449.                     obj = method.invoke(driver,values[0]);
  2450.                 }else if(classArgoments.length==2){
  2451.                     Method method =  driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1]);
  2452.                     obj = method.invoke(driver,values[0],values[1]);
  2453.                 }else if(classArgoments.length==3){
  2454.                     Method method =  driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2]);
  2455.                     obj = method.invoke(driver,values[0],values[1],values[2]);
  2456.                 }else if(classArgoments.length==4){
  2457.                     Method method =  driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3]);
  2458.                     obj = method.invoke(driver,values[0],values[1],values[2],values[3]);
  2459.                 }else if(classArgoments.length==5){
  2460.                     Method method =  driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4]);
  2461.                     obj = method.invoke(driver,values[0],values[1],values[2],values[3],values[4]);
  2462.                 }else if(classArgoments.length==6){
  2463.                     Method method =  driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2],classArgoments[3],classArgoments[4],classArgoments[5]);
  2464.                     obj = method.invoke(driver,values[0],values[1],values[2],values[3],values[4],values[5]);
  2465.                 }else
  2466.                     throw new Exception("Troppi argomenti per gestire la chiamata del metodo");
  2467.                 break;
  2468.             }
  2469.             }
  2470.         }catch(DriverConfigurazioneNotFound e){
  2471.             this.logDebug("Ricerca nella configurazione non riuscita (metodo ["+methodName+"]): "+e.getMessage());
  2472.             notFound=e;
  2473.         }
  2474.         catch(java.lang.reflect.InvocationTargetException e){
  2475.             if(e.getTargetException()!=null){
  2476.                 if(notFoundClassName.equals(e.getTargetException().getClass().getName())){
  2477.                     // Non presente
  2478.                     this.logDebug("Ricerca nella configurazione non riuscita [NotFound] (metodo ["+methodName+"]): "+e.getTargetException().getMessage());
  2479.                     notFound=new DriverConfigurazioneNotFound(e.getTargetException().getMessage(),e.getTargetException());
  2480.                 }else if(excClassName.equals(e.getTargetException().getClass().getName())){
  2481.                     // Non presente
  2482.                     this.logDebug("Ricerca nella configurazione non riuscita [DriverException] (metodo ["+methodName+"]): "+e.getTargetException().getMessage(),e.getTargetException());
  2483.                     throw new DriverConfigurazioneException(e.getTargetException().getMessage(),e.getTargetException());
  2484.                 }else{
  2485.                     this.logDebug("Ricerca nella configurazione non riuscita [InvTargetExcp.getTarget] (metodo ["+methodName+"]), "+e.getTargetException().getMessage(),e.getTargetException());
  2486.                     throw new DriverConfigurazioneException(e.getTargetException().getMessage(),e.getTargetException());
  2487.                 }
  2488.             }else{
  2489.                 this.logDebug("Ricerca nella configurazione non riuscita [InvTargetExcp] (metodo ["+methodName+"]), "+e.getMessage(),e);
  2490.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  2491.             }
  2492.         }
  2493.         catch(Exception e){
  2494.             this.logDebug("ricerca nella configurazione non riuscita (metodo ["+methodName+"]), "+e.getMessage(),e);
  2495.             throw new DriverConfigurazioneException(e.getMessage(),e);
  2496.         }

  2497.         // Refresh configurazione locale
  2498.         if(notFound!=null){
  2499.             try{
  2500.                 if("getGestioneErroreComponenteCooperazione".equals(methodName)){
  2501.                     obj = this.configLocalProperties.updateGestioneErroreCooperazione(null);
  2502.                 }
  2503.                 else if("getGestioneErroreComponenteIntegrazione".equals(methodName)){
  2504.                     obj = this.configLocalProperties.updateGestioneErroreIntegrazione(null);
  2505.                 }              
  2506.             }catch(Exception e){
  2507.                 this.logDebug("Refresh nella configurazione locale non riuscita (metodo ["+methodName+"]): "+e.getMessage());
  2508.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  2509.             }
  2510.             if(obj==null){
  2511.                 throw notFound;
  2512.             }
  2513.         }
  2514.         else{      
  2515.             try{
  2516.                 if("getRoutingTable".equals(methodName)){
  2517.                     obj = this.configLocalProperties.updateRouting((RoutingTable)obj);
  2518.                 }
  2519.                 else if("getAccessoRegistro".equals(methodName)){
  2520.                     obj = this.configLocalProperties.updateAccessoRegistro((AccessoRegistro)obj);
  2521.                 }
  2522.                 else if("getAccessoConfigurazione".equals(methodName)){
  2523.                     obj = this.configLocalProperties.updateAccessoConfigurazione((AccessoConfigurazione)obj);
  2524.                 }
  2525.                 else if("getAccessoDatiAutorizzazione".equals(methodName)){
  2526.                     obj = this.configLocalProperties.updateAccessoDatiAutorizzazione((AccessoDatiAutorizzazione)obj);
  2527.                 }
  2528.                 else if("getAccessoDatiAutenticazione".equals(methodName)){
  2529.                     obj = this.configLocalProperties.updateAccessoDatiAutenticazione((AccessoDatiAutenticazione)obj);
  2530.                 }
  2531.                 else if("getGestioneErroreComponenteCooperazione".equals(methodName)){
  2532.                     obj = this.configLocalProperties.updateGestioneErroreCooperazione((GestioneErrore)obj);
  2533.                 }
  2534.                 else if("getGestioneErroreComponenteIntegrazione".equals(methodName)){
  2535.                     obj = this.configLocalProperties.updateGestioneErroreIntegrazione((GestioneErrore)obj);
  2536.                 }
  2537.                 else if("getConfigurazioneGenerale".equals(methodName)){
  2538.                     obj = this.configLocalProperties.updateConfigurazione((Configurazione)obj);
  2539.                 }
  2540.             }catch(Exception e){
  2541.                 this.logDebug("Refresh nella configurazione locale non riuscita (metodo ["+methodName+"]): "+e.getMessage());
  2542.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  2543.             }

  2544.             try{
  2545.                 if("getConfigurazioneWithOnlyExtendedInfo".equals(methodNameParam)){
  2546.                     Configurazione config = (Configurazione) obj;
  2547.                     Configurazione c = new Configurazione();
  2548.                     if(config!=null) {
  2549.                         for (Object object : config.getExtendedInfoList()) {
  2550.                             c.addExtendedInfo(object);
  2551.                         }
  2552.                     }
  2553.                     obj = c;
  2554.                 }
  2555.             }catch(Exception e){
  2556.                 this.logDebug("Aggiornamento Configurazione Extended non riuscita (metodo ["+methodNameParam+"]): "+e.getMessage());
  2557.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  2558.             }
  2559.         }

  2560.         this.logDebug("invocazione metodo ["+methodName+"] completata.");
  2561.         return obj;

  2562.     }


  2563.     private org.openspcoop2.core.config.driver.IDriverConfigurazioneGet getDriver(Connection connectionPdD) throws DriverConfigurazioneException{

  2564.         org.openspcoop2.core.config.driver.IDriverConfigurazioneGet driver = this.driverConfigurazionePdD;
  2565.         if((driver instanceof DriverConfigurazioneDB)){
  2566.             if(connectionPdD!=null && this.useConnectionPdD){
  2567.                 //System.out.println("[CONFIG] USE CONNECTION VERSIONE!!!!!");
  2568.                 driver = new DriverConfigurazioneDB(connectionPdD, this.logger, this.tipoDatabase);
  2569.                 if( ((DriverConfigurazioneDB)driver).create == false){
  2570.                     throw new DriverConfigurazioneException("Inizializzazione DriverConfigurazioneDB con connessione PdD non riuscita");
  2571.                 }
  2572.             }
  2573.             else{
  2574.                 //System.out.println("[CONFIG] USE DATASOURCE VERSIONE!!!!!");
  2575.             }
  2576.         }

  2577.         return driver;
  2578.     }  










  2579.     // SOGGETTO

  2580.     protected static String _getKey_getSoggettoByID(IDSoggetto aSoggetto){
  2581.         return "getSoggetto_" + aSoggetto.getTipo() + aSoggetto.getNome();
  2582.     }
  2583.     public Soggetto getSoggetto(Connection connectionPdD,IDSoggetto aSoggetto) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2584.         // Raccolta dati
  2585.         if(aSoggetto == null || aSoggetto.getNome()==null || aSoggetto.getTipo()==null)
  2586.             throw new DriverConfigurazioneException("[getSoggetto]: Parametro non definito");  

  2587.         // se e' attiva una cache provo ad utilizzarla
  2588.         String key = null;  
  2589.         if(this.cache!=null){
  2590.             key = _getKey_getSoggettoByID(aSoggetto);
  2591.             org.openspcoop2.utils.cache.CacheResponse response =
  2592.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2593.             if(response != null){
  2594.                 if(response.getException()!=null){
  2595.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2596.                         throw (DriverConfigurazioneNotFound) response.getException();
  2597.                     else
  2598.                         throw (DriverConfigurazioneException) response.getException();
  2599.                 }else{
  2600.                     return ((Soggetto) response.getObject());
  2601.                 }
  2602.             }
  2603.         }

  2604.         // Algoritmo CACHE
  2605.         Soggetto sogg = null;
  2606.         if(this.cache!=null){
  2607.             sogg = (Soggetto) this.getObjectCache(key,"getSoggetto",connectionPdD,ConfigurazionePdDType.config,aSoggetto);
  2608.         }else{
  2609.             sogg = (Soggetto) this.getObject("getSoggetto",connectionPdD,ConfigurazionePdDType.config,aSoggetto);
  2610.         }

  2611.         if(sogg!=null)
  2612.             return sogg;
  2613.         else
  2614.             throw new DriverConfigurazioneNotFound("[getSoggetto] Soggetto non trovato");
  2615.     }

  2616.     protected static String _getKey_getRouter(){
  2617.         return "getRouter";
  2618.     }
  2619.     public Soggetto getRouter(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2620.         // se e' attiva una cache provo ad utilizzarla
  2621.         String key = null;  
  2622.         if(this.cache!=null){
  2623.             key = _getKey_getRouter();
  2624.             org.openspcoop2.utils.cache.CacheResponse response =
  2625.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2626.             if(response != null){
  2627.                 if(response.getException()!=null){
  2628.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2629.                         throw (DriverConfigurazioneNotFound) response.getException();
  2630.                     else
  2631.                         throw (DriverConfigurazioneException) response.getException();
  2632.                 }else{
  2633.                     return ((Soggetto) response.getObject());
  2634.                 }
  2635.             }
  2636.         }

  2637.         // Algoritmo CACHE
  2638.         Soggetto sogg = null;
  2639.         if(this.cache!=null){
  2640.             sogg = (Soggetto) this.getObjectCache(key,"getRouter",connectionPdD,ConfigurazionePdDType.config);
  2641.         }else{
  2642.             sogg = (Soggetto) this.getObject("getRouter",connectionPdD,ConfigurazionePdDType.config);
  2643.         }

  2644.         if(sogg!=null)
  2645.             return sogg;
  2646.         else
  2647.             throw new DriverConfigurazioneNotFound("[getRouter] Soggetto non trovato");
  2648.     }

  2649.     protected static String _getKey_getSoggettiVirtuali(){
  2650.         return "getSoggettiVirtuali";
  2651.     }
  2652.     @SuppressWarnings(value = "unchecked")
  2653.     public List<IDSoggetto> getSoggettiVirtuali(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2654.         // se e' attiva una cache provo ad utilizzarla
  2655.         String key = null;  
  2656.         if(this.cache!=null){
  2657.             key = _getKey_getSoggettiVirtuali();
  2658.             org.openspcoop2.utils.cache.CacheResponse response =
  2659.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2660.             if(response != null){
  2661.                 if(response.getException()!=null){
  2662.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2663.                         throw (DriverConfigurazioneNotFound) response.getException();
  2664.                     else
  2665.                         throw (DriverConfigurazioneException) response.getException();
  2666.                 }else{
  2667.                     return ((List<IDSoggetto>) response.getObject());
  2668.                 }
  2669.             }
  2670.         }

  2671.         // Algoritmo CACHE
  2672.         List<IDSoggetto> lista = null;
  2673.         if(this.cache!=null){
  2674.             lista = (List<IDSoggetto>) this.getObjectCache(key,"getSoggettiVirtuali",connectionPdD,ConfigurazionePdDType.config);
  2675.         }else{
  2676.             lista = (List<IDSoggetto>) this.getObject("getSoggettiVirtuali",connectionPdD,ConfigurazionePdDType.config);
  2677.         }

  2678.         if(lista!=null)
  2679.             return lista;
  2680.         else
  2681.             throw new DriverConfigurazioneNotFound("[getSoggettiVirtuali] Lista Soggetti Virtuali non costruita");
  2682.     }

  2683.     private static final String KEY_METHOD_GET_SERVIZI_SOGGETTI_VIRTUALI = "getServiziSoggettiVirtuali";
  2684.     protected static String getKeyMethodGetServiziSoggettiVirtuali(){
  2685.         return KEY_METHOD_GET_SERVIZI_SOGGETTI_VIRTUALI;
  2686.     }
  2687.     @SuppressWarnings(value = "unchecked")
  2688.     public List<IDServizio> getServiziSoggettiVirtuali(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2689.         // se e' attiva una cache provo ad utilizzarla
  2690.         String key = null;  
  2691.         if(this.cache!=null){
  2692.              key = getKeyMethodGetServiziSoggettiVirtuali();
  2693.             org.openspcoop2.utils.cache.CacheResponse response =
  2694.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2695.             if(response != null){
  2696.                 if(response.getException()!=null){
  2697.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2698.                         throw (DriverConfigurazioneNotFound) response.getException();
  2699.                     else
  2700.                         throw (DriverConfigurazioneException) response.getException();
  2701.                 }else{
  2702.                     return ((List<IDServizio>) response.getObject());
  2703.                 }
  2704.             }
  2705.         }

  2706.         // Algoritmo CACHE
  2707.         List<IDServizio> lista = null;
  2708.         if(this.cache!=null){
  2709.             lista = (List<IDServizio>) this.getObjectCache(key,KEY_METHOD_GET_SERVIZI_SOGGETTI_VIRTUALI,connectionPdD,ConfigurazionePdDType.config);
  2710.         }else{
  2711.             lista = (List<IDServizio>) this.getObject(KEY_METHOD_GET_SERVIZI_SOGGETTI_VIRTUALI,connectionPdD,ConfigurazionePdDType.config);
  2712.         }

  2713.         if(lista!=null)
  2714.             return lista;
  2715.         else
  2716.             throw new DriverConfigurazioneNotFound("["+KEY_METHOD_GET_SERVIZI_SOGGETTI_VIRTUALI+"] Lista Servizi erogati da Soggetti Virtuali non costruita");

  2717.     }





  2718.     // PORTA DELEGATA

  2719.     protected static String _getKey_getIDPortaDelegata(String nome){
  2720.          return "getIDPortaDelegata_" + nome;
  2721.     }
  2722.     public IDPortaDelegata getIDPortaDelegata(Connection connectionPdD,String nome) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2723.         // Raccolta dati
  2724.         if(nome==null)
  2725.             throw new DriverConfigurazioneException("[getIDPortaDelegata]: Parametro non definito (nome)");

  2726.         // se e' attiva una cache provo ad utilizzarla
  2727.         String key = null;  
  2728.         if(this.cache!=null){
  2729.             key = _getKey_getIDPortaDelegata(nome);
  2730.             org.openspcoop2.utils.cache.CacheResponse response =
  2731.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2732.             if(response != null){
  2733.                 if(response.getException()!=null){
  2734.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2735.                         throw (DriverConfigurazioneNotFound) response.getException();
  2736.                     else
  2737.                         throw (DriverConfigurazioneException) response.getException();
  2738.                 }else{
  2739.                     return ((IDPortaDelegata) response.getObject());
  2740.                 }
  2741.             }
  2742.         }

  2743.         // Algoritmo CACHE
  2744.         IDPortaDelegata idPD = null;
  2745.         if(this.cache!=null){
  2746.             idPD = (IDPortaDelegata) this.getObjectCache(key,"getIDPortaDelegata",connectionPdD,ConfigurazionePdDType.config,nome);
  2747.         }else{
  2748.             idPD = (IDPortaDelegata) this.getObject("getIDPortaDelegata",connectionPdD,ConfigurazionePdDType.config,nome);
  2749.         }

  2750.         if(idPD!=null)
  2751.             return idPD;
  2752.         else
  2753.             throw new DriverConfigurazioneNotFound("Porta Delegata ["+nome+"] non esistente");
  2754.     }
  2755.    
  2756.     protected static String _getKey_getPortaDelegata(IDPortaDelegata idPD){
  2757.          return "getPortaDelegata_" + idPD.getNome();
  2758.     }
  2759.     public PortaDelegata getPortaDelegata(Connection connectionPdD,IDPortaDelegata idPD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  2760.         // Raccolta dati
  2761.         if(idPD==null)
  2762.             throw new DriverConfigurazioneException("[getPortaDelegata]: Parametro non definito (idPD)");
  2763.         if(idPD.getNome()==null)
  2764.             throw new DriverConfigurazioneException("[getPortaDelegata]: Parametro non definito (nome)");

  2765.         // se e' attiva una cache provo ad utilizzarla
  2766.         String key = null;  
  2767.         if(this.cache!=null){
  2768.             key = _getKey_getPortaDelegata(idPD);
  2769.             org.openspcoop2.utils.cache.CacheResponse response =
  2770.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2771.             if(response != null){
  2772.                 if(response.getException()!=null){
  2773.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2774.                         throw (DriverConfigurazioneNotFound) response.getException();
  2775.                     else
  2776.                         throw (DriverConfigurazioneException) response.getException();
  2777.                 }else{
  2778.                     return ((PortaDelegata) response.getObject());
  2779.                 }
  2780.             }
  2781.         }

  2782.         // Algoritmo CACHE
  2783.         PortaDelegata pd = null;
  2784.         if(this.cache!=null){
  2785.             pd = (PortaDelegata) this.getObjectCache(key,"getPortaDelegata",connectionPdD,ConfigurazionePdDType.config,idPD);
  2786.         }else{
  2787.             pd = (PortaDelegata) this.getObject("getPortaDelegata",connectionPdD,ConfigurazionePdDType.config,idPD);
  2788.         }

  2789.         if(pd!=null)
  2790.             return pd;
  2791.         else
  2792.             throw new DriverConfigurazioneNotFound("Porta Delegata ["+idPD.getNome()+"] non esistente");
  2793.     }
  2794.    
  2795.     public void updateStatoPortaDelegata(Connection connectionPdD,IDPortaDelegata idPD, StatoFunzionalita stato) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2796.        
  2797.         if(this.cache==null){
  2798.             return;
  2799.         }
  2800.        
  2801.         // Raccolta dati
  2802.         if(idPD==null)
  2803.             throw new DriverConfigurazioneException("[updateStatoPortaDelegataInCache]: Parametro non definito (idPD)");
  2804.         if(idPD.getNome()==null)
  2805.             throw new DriverConfigurazioneException("[updateStatoPortaDelegataInCache]: Parametro non definito (nome)");

  2806.         // se e' attiva una cache provo ad utilizzarla
  2807.         String key = _getKey_getPortaDelegata(idPD);
  2808.         org.openspcoop2.utils.cache.CacheResponse response =
  2809.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2810.         if(response != null){
  2811.             if(response.getException()==null && response.getObject()!=null){
  2812.                 PortaDelegata pd = (PortaDelegata)  response.getObject();
  2813.                 pd.setStato(stato);
  2814.             }
  2815.         }
  2816.        
  2817.         PortaDelegata pd = (PortaDelegata) this.getObject("getPortaDelegata",connectionPdD,ConfigurazionePdDType.config,idPD);
  2818.         if(!stato.equals(pd.getStato())) {
  2819.             org.openspcoop2.core.config.driver.IDriverConfigurazioneGet driver = getDriver(connectionPdD);
  2820.             if(driver instanceof DriverConfigurazioneDB) {
  2821.                 DriverConfigurazioneDB db = (DriverConfigurazioneDB) driver;
  2822.                 IDPortaDelegata oldIDPortaDelegataForUpdate = new IDPortaDelegata();
  2823.                 oldIDPortaDelegataForUpdate.setNome(idPD.getNome());
  2824.                 pd.setOldIDPortaDelegataForUpdate(oldIDPortaDelegataForUpdate);
  2825.                 pd.setStato(stato);
  2826.                 db.updatePortaDelegata(pd);
  2827.             }
  2828.         }
  2829.     }
  2830.    
  2831.     private static org.openspcoop2.utils.Semaphore semaphore_getTemplateTrasformazionePD = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_TemplateTrasformazionePD");
  2832.     protected static String getKey_getPortaDelegataTemplate(IDPortaDelegata idPD, TemplateSource source, String identificativo){
  2833.         String prefixPD = _getKey_getPortaDelegata(idPD);
  2834.         return prefixPD+"_getTemplate_"+source.name()+"_"+identificativo;
  2835.     }
  2836.     public Template getTemplateTrasformazioneRichiesta(Connection connectionPdD,IDPortaDelegata idPD, String nomeTrasformazione, TrasformazioneRegolaRichiesta richiesta,
  2837.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2838.         TipoTrasformazione tipoTrasformazione = null;
  2839.         if(richiesta.getConversioneTipo()!=null) {
  2840.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(richiesta.getConversioneTipo());
  2841.         }
  2842.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  2843.             return new Template(nomeTrasformazione, richiesta.getConversioneTemplate());
  2844.         }
  2845.         return _getTemplate(connectionPdD, idPD, "getTemplateTrasformazioneRichiesta", TemplateSource.TRASFORMAZIONE_RICHIESTA, nomeTrasformazione, richiesta.getConversioneTemplate(),
  2846.                 requestInfo);
  2847.     }
  2848.     public Template getTemplateTrasformazioneSoapRichiesta(Connection connectionPdD,IDPortaDelegata idPD, String nomeTrasformazione, TrasformazioneRegolaRichiesta richiesta,
  2849.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2850.         TipoTrasformazione tipoTrasformazione = null;
  2851.         if(richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo()!=null) {
  2852.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo());
  2853.         }
  2854.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  2855.             return new Template(nomeTrasformazione, richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  2856.         }
  2857.         return _getTemplate(connectionPdD, idPD, "getTemplateTrasformazioneSoapRichiesta", TemplateSource.TRASFORMAZIONE_SOAP_RICHIESTA, nomeTrasformazione, richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate(),
  2858.                 requestInfo);
  2859.     }
  2860.     public Template getTemplateTrasformazioneRisposta(Connection connectionPdD,IDPortaDelegata idPD, String nomeTrasformazione, TrasformazioneRegolaRisposta risposta,
  2861.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2862.         TipoTrasformazione tipoTrasformazione = null;
  2863.         if(risposta.getConversioneTipo()!=null) {
  2864.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(risposta.getConversioneTipo());
  2865.         }
  2866.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  2867.             return new Template(nomeTrasformazione, risposta.getConversioneTemplate());
  2868.         }
  2869.         return _getTemplate(connectionPdD, idPD, "getTemplateTrasformazioneRisposta", TemplateSource.TRASFORMAZIONE_RISPOSTA, nomeTrasformazione+"@@"+risposta.getNome(), risposta.getConversioneTemplate(),
  2870.                 requestInfo);
  2871.     }
  2872.     public Template getTemplateTrasformazioneSoapRisposta(Connection connectionPdD,IDPortaDelegata idPD, String nomeTrasformazione, TrasformazioneRegolaRisposta risposta,
  2873.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2874.         TipoTrasformazione tipoTrasformazione = null;
  2875.         if(risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo()!=null) {
  2876.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo());
  2877.         }
  2878.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  2879.             return new Template(nomeTrasformazione, risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  2880.         }
  2881.         return _getTemplate(connectionPdD, idPD, "getTemplateTrasformazioneSoapRisposta", TemplateSource.TRASFORMAZIONE_SOAP_RISPOSTA, nomeTrasformazione+"@@"+risposta.getNome(), risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate(),
  2882.                 requestInfo);
  2883.     }

  2884.     public Template getTemplateCorrelazioneApplicativaRichiesta(Connection connectionPdD,IDPortaDelegata idPD, String nomeRegola, byte[] template,
  2885.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2886.         return _getTemplate(connectionPdD, idPD, "getTemplateCorrelazioneApplicativaRichiesta", TemplateSource.CORRELAZIONE_APPLICATIVA_RICHIESTA, (nomeRegola!=null ? nomeRegola : "___default___"), template,
  2887.                 requestInfo);
  2888.     }
  2889.     public Template getTemplateCorrelazioneApplicativaRisposta(Connection connectionPdD,IDPortaDelegata idPD, String nomeRegola, byte[] template,
  2890.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2891.         return _getTemplate(connectionPdD, idPD, "getTemplateCorrelazioneApplicativaRisposta", TemplateSource.CORRELAZIONE_APPLICATIVA_RISPOSTA, (nomeRegola!=null ? nomeRegola : "___default___"), template,
  2892.                 requestInfo);
  2893.     }
  2894.    
  2895.     private Template _getTemplate(Connection connectionPdD,IDPortaDelegata idPD, String nomeMetodo, TemplateSource templateSource, String identificativo, byte[] templateBytes,
  2896.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2897.        
  2898.         String key = getKey_getPortaDelegataTemplate(idPD, templateSource, identificativo);
  2899.        
  2900.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  2901.         if(useRequestInfo) {
  2902.             Object o = requestInfo.getRequestConfig().getTemplate(key);
  2903.             if(o!=null && o instanceof Template) {
  2904.                 return (Template) o;
  2905.             }
  2906.         }
  2907.        
  2908.         Template template = _getTemplate(connectionPdD,idPD, nomeMetodo, templateSource, identificativo, templateBytes, key);
  2909.         if(useRequestInfo && requestInfo!=null) {
  2910.             requestInfo.getRequestConfig().addTemplate(key, template,
  2911.                     requestInfo.getIdTransazione());
  2912.         }
  2913.         return template;
  2914.     }
  2915.     private Template _getTemplate(Connection connectionPdD,IDPortaDelegata idPD, String nomeMetodo, TemplateSource templateSource, String identificativo, byte[] templateBytes,
  2916.             String key) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2917.        
  2918.         // Raccolta dati
  2919.         if(idPD == null)
  2920.             throw new DriverConfigurazioneException("["+nomeMetodo+"]: Parametro non definito (idPD is null)");
  2921.         if(idPD.getNome()==null)
  2922.             throw new DriverConfigurazioneException("["+nomeMetodo+"]: Parametro non definito (idPD.getNome() is null)");

  2923.         // se e' attiva una cache provo ad utilizzarla  
  2924.         if(this.cache!=null) {
  2925.             org.openspcoop2.utils.cache.CacheResponse response =
  2926.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2927.             if(response != null){
  2928.                 if(response.getException()!=null){
  2929.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2930.                         throw (DriverConfigurazioneNotFound) response.getException();
  2931.                     else
  2932.                         throw (DriverConfigurazioneException) response.getException();
  2933.                 }else{
  2934.                     Template template = (Template) response.getObject();
  2935.                     if(template!=null){
  2936.                         return template;
  2937.                     }
  2938.                 }
  2939.             }
  2940.         }

  2941.         Template template = null;
  2942.        
  2943.         SemaphoreLock lock = semaphore_getTemplateTrasformazionePD.acquireThrowRuntime(nomeMetodo);
  2944.         try {
  2945.            
  2946.             if(this.cache!=null) {
  2947.                 org.openspcoop2.utils.cache.CacheResponse response =
  2948.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2949.                 if(response != null){
  2950.                     if(response.getException()!=null){
  2951.                         if(notFoundClassName.equals(response.getException().getClass().getName()))
  2952.                             throw (DriverConfigurazioneNotFound) response.getException();
  2953.                         else
  2954.                             throw (DriverConfigurazioneException) response.getException();
  2955.                     }else{
  2956.                         template = (Template) response.getObject();
  2957.                         if(template!=null){
  2958.                             return template;
  2959.                         }
  2960.                     }
  2961.                 }
  2962.             }
  2963.            
  2964.             template = new Template(key, templateBytes);
  2965.            
  2966.             // Aggiungo la risposta in cache (se esiste una cache)  
  2967.             // Se ho una eccezione aggiungo in cache solo una not found
  2968.             if( this.cache!=null ){    
  2969.                 this.logInfo("Aggiungo oggetto ["+key+"] in cache");
  2970.                 try{    
  2971.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  2972.                     responseCache.setObject((java.io.Serializable)template);
  2973.                     this.cache.put(key,responseCache);
  2974.                 }catch(UtilsException e){
  2975.                     this.logError("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  2976.                 }
  2977.             }
  2978.            
  2979.         }finally {
  2980.             semaphore_getTemplateTrasformazionePD.release(lock, nomeMetodo);
  2981.         }

  2982.         return template;

  2983.     }  
  2984.    
  2985.    
  2986.     public Template getTemplateIntegrazione(Connection connectionPdD,IDPortaDelegata idPD, File file,
  2987.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2988.         return _getTemplate(connectionPdD, idPD, "getTemplateIntegrazione", TemplateSource.INTEGRAZIONE, file,
  2989.                 requestInfo);
  2990.     }
  2991.     private Template _getTemplate(Connection connectionPdD,IDPortaDelegata idPD, String nomeMetodo, TemplateSource templateSource, File file,
  2992.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  2993.        
  2994.         String key = getKey_getPortaDelegataTemplate(idPD, templateSource, file.getAbsolutePath());
  2995.        
  2996.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  2997.         if(useRequestInfo) {
  2998.             Object o = requestInfo.getRequestConfig().getTemplate(key);
  2999.             if(o!=null && o instanceof Template) {
  3000.                 return (Template) o;
  3001.             }
  3002.         }
  3003.        
  3004.         Template template = _getTemplate(connectionPdD, idPD, nomeMetodo, templateSource, file, key);
  3005.         if(useRequestInfo && requestInfo!=null) {
  3006.             requestInfo.getRequestConfig().addTemplate(key, template,
  3007.                     requestInfo.getIdTransazione());
  3008.         }
  3009.         return template;
  3010.     }
  3011.     private Template _getTemplate(Connection connectionPdD,IDPortaDelegata idPD, String nomeMetodo, TemplateSource templateSource, File file,
  3012.             String key) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3013.        
  3014.         // se e' attiva una cache provo ad utilizzarla
  3015.         if(this.cache!=null) {
  3016.             org.openspcoop2.utils.cache.CacheResponse response =
  3017.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3018.             if(response != null){
  3019.                 if(response.getException()!=null){
  3020.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3021.                         throw (DriverConfigurazioneNotFound) response.getException();
  3022.                     else
  3023.                         throw (DriverConfigurazioneException) response.getException();
  3024.                 }else{
  3025.                     Template template = (Template) response.getObject();
  3026.                     if(template!=null){
  3027.                         return template;
  3028.                     }
  3029.                 }
  3030.             }
  3031.         }

  3032.         Template template = null;
  3033.        
  3034.         SemaphoreLock lock = semaphore_getTemplateTrasformazionePD.acquireThrowRuntime(nomeMetodo);
  3035.         try {
  3036.            
  3037.             if(this.cache!=null) {
  3038.                 org.openspcoop2.utils.cache.CacheResponse response =
  3039.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3040.                 if(response != null){
  3041.                     if(response.getException()!=null){
  3042.                         if(notFoundClassName.equals(response.getException().getClass().getName()))
  3043.                             throw (DriverConfigurazioneNotFound) response.getException();
  3044.                         else
  3045.                             throw (DriverConfigurazioneException) response.getException();
  3046.                     }else{
  3047.                         template = (Template) response.getObject();
  3048.                         if(template!=null){
  3049.                             return template;
  3050.                         }
  3051.                     }
  3052.                 }
  3053.             }
  3054.            
  3055.             ContentFile cf = getContentFileEngine(file);
  3056.             if(cf.isExists()) {
  3057.                 template = new Template(key, cf.getContent());
  3058.             }
  3059.             else {
  3060.                 throw new DriverConfigurazioneException("File '"+file.getAbsolutePath()+"' cannot exists");
  3061.             }
  3062.            
  3063.             // Aggiungo la risposta in cache (se esiste una cache)  
  3064.             // Se ho una eccezione aggiungo in cache solo una not found
  3065.             if( this.cache!=null ){    
  3066.                 this.logInfo("Aggiungo oggetto ["+key+"] in cache");
  3067.                 try{    
  3068.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  3069.                     responseCache.setObject((java.io.Serializable)template);
  3070.                     this.cache.put(key,responseCache);
  3071.                 }catch(UtilsException e){
  3072.                     this.logError("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  3073.                 }
  3074.             }
  3075.            
  3076.         }finally {
  3077.             semaphore_getTemplateTrasformazionePD.release(lock, nomeMetodo);
  3078.         }

  3079.         return template;

  3080.     }
  3081.    
  3082.    
  3083.    
  3084.    
  3085.     // PORTA APPLICATIVA
  3086.    
  3087.     protected static String _getKey_getIDPortaApplicativa(String nome){
  3088.          return "getIDPortaApplicativa_" + nome;
  3089.     }
  3090.     public IDPortaApplicativa getIDPortaApplicativa(Connection connectionPdD,String nome) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3091.         // Raccolta dati
  3092.         if(nome==null)
  3093.             throw new DriverConfigurazioneException("[getIDPortaApplicativa]: Parametro non definito (nome)");

  3094.         // se e' attiva una cache provo ad utilizzarla
  3095.         String key = null;  
  3096.         if(this.cache!=null){
  3097.             key = _getKey_getIDPortaApplicativa(nome);
  3098.             org.openspcoop2.utils.cache.CacheResponse response =
  3099.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3100.             if(response != null){
  3101.                 if(response.getException()!=null){
  3102.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3103.                         throw (DriverConfigurazioneNotFound) response.getException();
  3104.                     else
  3105.                         throw (DriverConfigurazioneException) response.getException();
  3106.                 }else{
  3107.                     return ((IDPortaApplicativa) response.getObject());
  3108.                 }
  3109.             }
  3110.         }

  3111.         // Algoritmo CACHE
  3112.         IDPortaApplicativa idPA = null;
  3113.         if(this.cache!=null){
  3114.             idPA = (IDPortaApplicativa) this.getObjectCache(key,"getIDPortaApplicativa",connectionPdD,ConfigurazionePdDType.config,nome);
  3115.         }else{
  3116.             idPA = (IDPortaApplicativa) this.getObject("getIDPortaApplicativa",connectionPdD,ConfigurazionePdDType.config,nome);
  3117.         }

  3118.         if(idPA!=null)
  3119.             return idPA;
  3120.         else
  3121.             throw new DriverConfigurazioneNotFound("Porta Applicativa ["+nome+"] non esistente");
  3122.     }
  3123.    
  3124.     protected static String _getKey_getPortaApplicativa(IDPortaApplicativa idPA){
  3125.          return "getPortaApplicativa_" + idPA.getNome();
  3126.     }
  3127.     public PortaApplicativa getPortaApplicativa(Connection connectionPdD,IDPortaApplicativa idPA) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3128.         // Raccolta dati
  3129.         if(idPA == null)
  3130.             throw new DriverConfigurazioneException("[getPortaApplicativa]: Parametro non definito (idPA is null)");
  3131.         if(idPA.getNome()==null)
  3132.             throw new DriverConfigurazioneException("[getPortaApplicativa]: Parametro non definito (idPA.getNome() is null)");

  3133.         // se e' attiva una cache provo ad utilizzarla
  3134.         String key = null;  
  3135.         if(this.cache!=null){
  3136.             key = _getKey_getPortaApplicativa(idPA);
  3137.             org.openspcoop2.utils.cache.CacheResponse response =
  3138.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3139.             if(response != null){
  3140.                 if(response.getException()!=null){
  3141.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3142.                         throw (DriverConfigurazioneNotFound) response.getException();
  3143.                     else
  3144.                         throw (DriverConfigurazioneException) response.getException();
  3145.                 }else{
  3146.                     PortaApplicativa pa = (PortaApplicativa) response.getObject();
  3147.                     if(pa!=null){
  3148.                         return pa;
  3149.                     }
  3150.                 }
  3151.             }
  3152.         }

  3153.         // Algoritmo CACHE
  3154.         PortaApplicativa pa = null;
  3155.         if(this.cache!=null){
  3156.             pa = (PortaApplicativa) this.getObjectCache(key,"getPortaApplicativa",connectionPdD,ConfigurazionePdDType.config,idPA);
  3157.         }else{
  3158.             pa = (PortaApplicativa) this.getObject("getPortaApplicativa",connectionPdD,ConfigurazionePdDType.config,idPA);
  3159.         }

  3160.         if(pa!=null){
  3161.             return pa;
  3162.         }
  3163.         else{
  3164.             throw new DriverConfigurazioneNotFound("Porta Applicativa ["+idPA.getNome()+"] non esistente");
  3165.         }
  3166.     }
  3167.    
  3168.     public void updateStatoPortaApplicativa(Connection connectionPdD,IDPortaApplicativa idPA, StatoFunzionalita stato) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3169.        
  3170.         if(this.cache==null){
  3171.             return;
  3172.         }
  3173.        
  3174.         // Raccolta dati
  3175.         if(idPA==null)
  3176.             throw new DriverConfigurazioneException("[updateStatoPortaApplicativa]: Parametro non definito (idPA)");
  3177.         if(idPA.getNome()==null)
  3178.             throw new DriverConfigurazioneException("[updateStatoPortaApplicativa]: Parametro non definito (nome)");

  3179.         // se e' attiva una cache provo ad utilizzarla
  3180.         String key = _getKey_getPortaApplicativa(idPA);
  3181.         org.openspcoop2.utils.cache.CacheResponse response =
  3182.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3183.         if(response != null){
  3184.             if(response.getException()==null && response.getObject()!=null){
  3185.                 PortaApplicativa pa = (PortaApplicativa)  response.getObject();
  3186.                 pa.setStato(stato);
  3187.             }
  3188.         }
  3189.        
  3190.        
  3191.         PortaApplicativa pa = (PortaApplicativa) this.getObject("getPortaApplicativa",connectionPdD,ConfigurazionePdDType.config,idPA);
  3192.         if(!stato.equals(pa.getStato())) {
  3193.             org.openspcoop2.core.config.driver.IDriverConfigurazioneGet driver = getDriver(connectionPdD);
  3194.             if(driver instanceof DriverConfigurazioneDB) {
  3195.                 DriverConfigurazioneDB db = (DriverConfigurazioneDB) driver;
  3196.                 IDPortaApplicativa oldIDPortaApplicativaForUpdate = new IDPortaApplicativa();
  3197.                 oldIDPortaApplicativaForUpdate.setNome(idPA.getNome());
  3198.                 pa.setOldIDPortaApplicativaForUpdate(oldIDPortaApplicativaForUpdate);
  3199.                 pa.setStato(stato);
  3200.                 db.updatePortaApplicativa(pa);
  3201.             }
  3202.         }
  3203.     }
  3204.    
  3205.     public String updateStatoConnettoreMultiplo(Connection connectionPdD,IDPortaApplicativa idPA, String nomeConnettore, StatoFunzionalita stato) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3206.         return updateStatoConnettoreMultiploEngine(connectionPdD,idPA, nomeConnettore, null, stato, false);
  3207.     }
  3208.     public String updateStatoConnettoreMultiplo(Connection connectionPdD,IDPortaApplicativa idPA, String nomeConnettore, String user, StatoFunzionalita stato) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3209.         return updateStatoConnettoreMultiploEngine(connectionPdD,idPA, nomeConnettore, user, stato, false);
  3210.     }
  3211.     public String updateSchedulingConnettoreMultiplo(Connection connectionPdD,IDPortaApplicativa idPA, String nomeConnettore, StatoFunzionalita stato) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3212.         return updateStatoConnettoreMultiploEngine(connectionPdD,idPA, nomeConnettore, null,stato,  true);
  3213.     }
  3214.     public String updateSchedulingConnettoreMultiplo(Connection connectionPdD,IDPortaApplicativa idPA, String nomeConnettore, String user, StatoFunzionalita stato) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3215.         return updateStatoConnettoreMultiploEngine(connectionPdD,idPA, nomeConnettore, user, stato, true);
  3216.     }
  3217.     private String updateStatoConnettoreMultiploEngine(Connection connectionPdD,IDPortaApplicativa idPA, String nomeConnettore, String user, StatoFunzionalita stato, boolean scheduling) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3218.            
  3219.         if(this.cache==null){
  3220.             return null;
  3221.         }
  3222.        
  3223.         // Raccolta dati
  3224.         if(idPA==null)
  3225.             throw new DriverConfigurazioneException("[updateStatoPortaApplicativa]: Parametro non definito (idPA)");
  3226.         if(idPA.getNome()==null)
  3227.             throw new DriverConfigurazioneException("[updateStatoPortaApplicativa]: Parametro non definito (nome)");
  3228.         if(nomeConnettore==null)
  3229.             throw new DriverConfigurazioneException("[updateStatoPortaApplicativa]: Parametro non definito (nomeConnettore)");

  3230.         // se e' attiva una cache provo ad utilizzarla
  3231.         String key = _getKey_getPortaApplicativa(idPA);
  3232.         org.openspcoop2.utils.cache.CacheResponse response =
  3233.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3234.         if(response != null){
  3235.             if(response.getException()==null && response.getObject()!=null){
  3236.                 PortaApplicativa pa = (PortaApplicativa)  response.getObject();
  3237.                 if(pa.sizeServizioApplicativoList()>0) {
  3238.                     for (PortaApplicativaServizioApplicativo paSA : pa.getServizioApplicativoList()) {
  3239.                         String nomePaSA = paSA.getDatiConnettore()!= null ? paSA.getDatiConnettore().getNome() : CostantiConfigurazione.NOME_CONNETTORE_DEFAULT;
  3240.                         if(nomeConnettore.equals(nomePaSA)) {
  3241.                             if(paSA.getDatiConnettore()==null) {
  3242.                                 paSA.setDatiConnettore(new PortaApplicativaServizioApplicativoConnettore());
  3243.                             }
  3244.                             if(scheduling) {
  3245.                                 paSA.getDatiConnettore().setScheduling(stato);
  3246.                             }
  3247.                             else {
  3248.                                 paSA.getDatiConnettore().setStato(stato);
  3249.                             }
  3250.                             break;
  3251.                         }
  3252.                     }
  3253.                 }
  3254.             }
  3255.         }
  3256.        
  3257.        
  3258.         PortaApplicativa pa = (PortaApplicativa) this.getObject("getPortaApplicativa",connectionPdD,ConfigurazionePdDType.config,idPA);
  3259.         boolean update = false;
  3260.         String nomeSA = null;
  3261.         if(pa.sizeServizioApplicativoList()>0) {
  3262.             for (PortaApplicativaServizioApplicativo paSA : pa.getServizioApplicativoList()) {
  3263.                 String nomePaSA = paSA.getDatiConnettore()!= null ? paSA.getDatiConnettore().getNome() : CostantiConfigurazione.NOME_CONNETTORE_DEFAULT;
  3264.                 if(nomeConnettore.equals(nomePaSA)) {
  3265.                     nomeSA = paSA.getNome();
  3266.                     StatoFunzionalita check = null;
  3267.                     if(paSA.getDatiConnettore()!=null) {
  3268.                         check = paSA.getDatiConnettore().getStato();
  3269.                     }
  3270.                     if(!stato.equals(check)) {
  3271.                         update = true;
  3272.                         if(paSA.getDatiConnettore()==null) {
  3273.                             paSA.setDatiConnettore(new PortaApplicativaServizioApplicativoConnettore());
  3274.                         }
  3275.                         if(scheduling) {
  3276.                             paSA.getDatiConnettore().setScheduling(stato);
  3277.                         }
  3278.                         else {
  3279.                             paSA.getDatiConnettore().setStato(stato);
  3280.                         }
  3281.                        
  3282.                         if(user!=null) {
  3283.                             if(paSA.getDatiConnettore().getProprietaOggetto()==null) {
  3284.                                 paSA.getDatiConnettore().setProprietaOggetto(new ProprietaOggetto());
  3285.                             }
  3286.                             paSA.getDatiConnettore().getProprietaOggetto().setUtenteUltimaModifica(user);
  3287.                             paSA.getDatiConnettore().getProprietaOggetto().setDataUltimaModifica(DateManager.getDate());
  3288.                         }
  3289.                     }
  3290.                     break;
  3291.                 }
  3292.             }
  3293.         }
  3294.         if(update) {
  3295.             org.openspcoop2.core.config.driver.IDriverConfigurazioneGet driver = getDriver(connectionPdD);
  3296.             if(driver instanceof DriverConfigurazioneDB) {
  3297.                 DriverConfigurazioneDB db = (DriverConfigurazioneDB) driver;
  3298.                 IDPortaApplicativa oldIDPortaApplicativaForUpdate = new IDPortaApplicativa();
  3299.                 oldIDPortaApplicativaForUpdate.setNome(idPA.getNome());
  3300.                 pa.setOldIDPortaApplicativaForUpdate(oldIDPortaApplicativaForUpdate);
  3301.                 db.updatePortaApplicativa(pa);
  3302.             }
  3303.         }
  3304.         return nomeSA;
  3305.     }
  3306.    
  3307.     protected static String _toKey_getPorteApplicativePrefix(IDServizio idServizio, boolean ricercaPuntuale){
  3308.         String key = "getPorteApplicative_ricercaPuntuale("+ricercaPuntuale+")_" +
  3309.                 idServizio.getSoggettoErogatore().getTipo()+idServizio.getSoggettoErogatore().getNome() + "_" +
  3310.                 idServizio.getTipo() + idServizio.getNome()+ ":" + idServizio.getVersione();
  3311.         return key;
  3312.     }
  3313.     private String _getKey_getPorteApplicative(IDServizio idServizio, boolean ricercaPuntuale){
  3314.         String key = _toKey_getPorteApplicativePrefix(idServizio, ricercaPuntuale);
  3315.         if(idServizio.getAzione()!=null)
  3316.             key = key + "_" + idServizio.getAzione();
  3317.         return key;
  3318.     }
  3319.     @SuppressWarnings("unchecked")
  3320.     public List<PortaApplicativa> getPorteApplicative(Connection connectionPdD,IDServizio idServizio, boolean ricercaPuntuale) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3321.         // Raccolta dati
  3322.         if(idServizio == null || idServizio.getNome()==null || idServizio.getTipo()==null || idServizio.getVersione()==null ||
  3323.                 idServizio.getSoggettoErogatore()==null || idServizio.getSoggettoErogatore().getTipo()==null || idServizio.getSoggettoErogatore().getNome()==null)
  3324.             throw new DriverConfigurazioneException("[getPorteApplicative]: Parametri non definito");  
  3325.        

  3326.         // se e' attiva una cache provo ad utilizzarla
  3327.         String key = null;  
  3328.         if(this.cache!=null){
  3329.             key = _getKey_getPorteApplicative(idServizio, ricercaPuntuale);
  3330.            
  3331.             org.openspcoop2.utils.cache.CacheResponse response =
  3332.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3333.             if(response != null){
  3334.                 if(response.getException()!=null){
  3335.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3336.                         throw (DriverConfigurazioneNotFound) response.getException();
  3337.                     else
  3338.                         throw (DriverConfigurazioneException) response.getException();
  3339.                 }else{
  3340.                     List<PortaApplicativa> list = (List<PortaApplicativa>) response.getObject();
  3341.                     if(list!=null){
  3342.                         return list;
  3343.                     }
  3344.                 }
  3345.             }
  3346.         }

  3347.         Class<?> [] classArgoments = {IDServizio.class,boolean.class};
  3348.         Object [] values = {idServizio,ricercaPuntuale};
  3349.        
  3350.         // Algoritmo CACHE
  3351.         List<PortaApplicativa> list = null;
  3352.         if(this.cache!=null){
  3353.             list = (List<PortaApplicativa>) this.getObjectCache(key,"getPorteApplicative",connectionPdD,ConfigurazionePdDType.config,classArgoments,values);
  3354.         }else{
  3355.             list = (List<PortaApplicativa>) this.getObject("getPorteApplicative",connectionPdD,ConfigurazionePdDType.config,classArgoments,values);
  3356.         }

  3357.         if(list!=null){
  3358.             return list;
  3359.         }
  3360.         else{
  3361.             throw new DriverConfigurazioneNotFound("Porte Applicative non trovate");
  3362.         }
  3363.     }
  3364.    
  3365.     protected static String _toKey_getPorteApplicativeVirtualiPrefix(boolean ricercaPuntuale) {
  3366.         return "getPorteApplicativeVirtuali_ricercaPuntuale("+ricercaPuntuale+")_";
  3367.     }
  3368.     protected static String _toKey_getPorteApplicativeVirtuali_idSoggettoVirtuale(IDSoggetto soggettoVirtuale) {
  3369.         return soggettoVirtuale.getTipo()+soggettoVirtuale.getNome();
  3370.     }
  3371.     protected static String _toKey_getPorteApplicativeVirtuali_idServizio(IDServizio idServizio) {
  3372.         return idServizio.getSoggettoErogatore().getTipo()+idServizio.getSoggettoErogatore().getNome() + "_" +
  3373.                 idServizio.getTipo() + idServizio.getNome()+":"+idServizio.getVersione();
  3374.     }
  3375.     private String _getKey_getPorteApplicativeVirtuali(IDSoggetto soggettoVirtuale,IDServizio idServizio, boolean ricercaPuntuale){
  3376.         String key = _toKey_getPorteApplicativeVirtualiPrefix(ricercaPuntuale) +
  3377.                 _toKey_getPorteApplicativeVirtuali_idSoggettoVirtuale(soggettoVirtuale)+
  3378.                 "_"+
  3379.                 _toKey_getPorteApplicativeVirtuali_idServizio(idServizio);
  3380.         if(idServizio.getAzione()!=null)
  3381.             key = key + "_" + idServizio.getAzione();
  3382.         return key;
  3383.     }
  3384.     @SuppressWarnings("unchecked")
  3385.     public List<PortaApplicativa> getPorteApplicativeVirtuali(Connection connectionPdD,IDSoggetto soggettoVirtuale,IDServizio idServizio, boolean ricercaPuntuale) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3386.         // Raccolta dati
  3387.         if(soggettoVirtuale==null || soggettoVirtuale.getTipo()==null || soggettoVirtuale.getNome()==null){
  3388.             throw new DriverConfigurazioneException("[getPorteApplicative]: Parametri (SoggettoVirtuale) non definito");    
  3389.         }
  3390.         if(idServizio == null || idServizio.getNome()==null || idServizio.getTipo()==null || idServizio.getVersione()==null ||
  3391.                 idServizio.getSoggettoErogatore()==null || idServizio.getSoggettoErogatore().getTipo()==null || idServizio.getSoggettoErogatore().getNome()==null)
  3392.             throw new DriverConfigurazioneException("[getPorteApplicative]: Parametri (IDServizio) non definito");  
  3393.        

  3394.         // se e' attiva una cache provo ad utilizzarla
  3395.         String key = null;  
  3396.         if(this.cache!=null){
  3397.             key = this._getKey_getPorteApplicativeVirtuali(soggettoVirtuale, idServizio, ricercaPuntuale);
  3398.            
  3399.             org.openspcoop2.utils.cache.CacheResponse response =
  3400.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3401.             if(response != null){
  3402.                 if(response.getException()!=null){
  3403.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3404.                         throw (DriverConfigurazioneNotFound) response.getException();
  3405.                     else
  3406.                         throw (DriverConfigurazioneException) response.getException();
  3407.                 }else{
  3408.                     List<PortaApplicativa> list = (List<PortaApplicativa>) response.getObject();
  3409.                     if(list!=null){
  3410.                         return list;
  3411.                     }
  3412.                 }
  3413.             }
  3414.         }

  3415.         Class<?> [] classArgoments = {IDSoggetto.class,IDServizio.class,boolean.class};
  3416.         Object [] values = {soggettoVirtuale,idServizio,ricercaPuntuale};
  3417.        
  3418.         // Algoritmo CACHE
  3419.         List<PortaApplicativa> list = null;
  3420.         if(this.cache!=null){
  3421.             list = (List<PortaApplicativa>) this.getObjectCache(key,"getPorteApplicativeVirtuali",connectionPdD,ConfigurazionePdDType.config,classArgoments,values);
  3422.         }else{
  3423.             list = (List<PortaApplicativa>) this.getObject("getPorteApplicativeVirtuali",connectionPdD,ConfigurazionePdDType.config,classArgoments,values);
  3424.         }

  3425.         if(list!=null){
  3426.             return list;
  3427.         }
  3428.         else{
  3429.             throw new DriverConfigurazioneNotFound("Porte Applicative non trovate");
  3430.         }
  3431.     }
  3432.    
  3433.     private static final String METHOD_GET_PORTE_APPLICATIVE_SOGGETTI_VIRTUALI = "getPorteApplicativeSoggettiVirtuali";
  3434.     protected static String toKeyMethodGetPorteApplicativeSoggettiVirtualiPrefix(IDServizio idServizio){
  3435.         return METHOD_GET_PORTE_APPLICATIVE_SOGGETTI_VIRTUALI+"_" + idServizio.getSoggettoErogatore().getTipo()+idServizio.getSoggettoErogatore().getNome() + "_" +
  3436.                 idServizio.getTipo() + idServizio.getNome()+":"+idServizio.getVersione();
  3437.     }
  3438.     private String getKeyMethodGetPorteApplicativeSoggettiVirtuali(IDServizio idServizio){
  3439.         String key = toKeyMethodGetPorteApplicativeSoggettiVirtualiPrefix(idServizio);
  3440.         if(idServizio.getAzione()!=null)
  3441.             key = key + "_" + idServizio.getAzione();
  3442.         return key;
  3443.     }
  3444.     @SuppressWarnings(value = "unchecked")
  3445.     public Map<IDSoggetto,PortaApplicativa> getPorteApplicativeSoggettiVirtuali(Connection connectionPdD,IDServizio idServizio,
  3446.             Map<String, String> proprietaPresentiBustaRicevuta,boolean useFiltroProprieta)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3447.         // Raccolta dati
  3448.         if(idServizio == null || idServizio.getNome()==null || idServizio.getTipo()==null || idServizio.getVersione()==null ||
  3449.                 idServizio.getSoggettoErogatore()==null || idServizio.getSoggettoErogatore().getTipo()==null || idServizio.getSoggettoErogatore().getNome()==null)
  3450.             throw new DriverConfigurazioneException("["+METHOD_GET_PORTE_APPLICATIVE_SOGGETTI_VIRTUALI+"]: Parametro non definito");    

  3451.         // se e' attiva una cache provo ad utilizzarla
  3452.         String key = null;  
  3453.         if(this.cache!=null){
  3454.             this.logDebug("Search porte applicative soggetti virtuali in cache...");
  3455.             key = this.getKeyMethodGetPorteApplicativeSoggettiVirtuali(idServizio);
  3456.             org.openspcoop2.utils.cache.CacheResponse response =
  3457.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3458.             if(response != null){
  3459.                 if(response.getException()!=null){
  3460.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3461.                         throw (DriverConfigurazioneNotFound) response.getException();
  3462.                     else
  3463.                         throw (DriverConfigurazioneException) response.getException();
  3464.                 }else{
  3465.                     if(response.getObject()!=null){
  3466.                         this.logDebug("Oggetto in cache trovato. Analizzo porte virtuali trovate rispetto alle proprieta' presenti nella busta arrivata: "+this.toStringFiltriProprieta(proprietaPresentiBustaRicevuta));
  3467.                         Map<IDSoggetto,PortaApplicativa> pa = (Map<IDSoggetto,PortaApplicativa>) response.getObject();
  3468.                         Map<IDSoggetto,PortaApplicativa> paChecked = new java.util.HashMap<>();
  3469.                         Iterator<IDSoggetto> it = pa.keySet().iterator();
  3470.                         while (it.hasNext()) {
  3471.                             IDSoggetto idS = it.next();
  3472.                             PortaApplicativa paC = pa.get(idS);
  3473.                             this.logDebug("Analizzo pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]...");
  3474.                             if(useFiltroProprieta){
  3475.                                 boolean ricezioneAutorizzata = checkProprietaFiltroPortaApplicativa(paC,proprietaPresentiBustaRicevuta);
  3476.                                 if(ricezioneAutorizzata){
  3477.                                     this.logDebug("Filtri matchano le protocol properties della pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]");
  3478.                                     paChecked.put(idS,paC);
  3479.                                 }else{
  3480.                                     this.logDebug("Filtri non matchano le protocol properties della pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]");
  3481.                                 }
  3482.                             }else{
  3483.                                 this.logDebug("Invocazione metodo senza la richiesta di filtro per proprieta, aggiunta pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]");
  3484.                                 paChecked.put(idS,paC);
  3485.                             }
  3486.                         }
  3487.                         if(paChecked.size()>0)
  3488.                             return paChecked;
  3489.                     }
  3490.                 }
  3491.             }
  3492.         }

  3493.         // Algoritmo CACHE
  3494.         Map<IDSoggetto,PortaApplicativa> pa = null;
  3495.         if(this.cache!=null){
  3496.             pa = (Map<IDSoggetto,PortaApplicativa>) this.getObjectCache(key,METHOD_GET_PORTE_APPLICATIVE_SOGGETTI_VIRTUALI,connectionPdD,ConfigurazionePdDType.config,idServizio);
  3497.         }else{
  3498.             pa = (Map<IDSoggetto,PortaApplicativa>) this.getObject(METHOD_GET_PORTE_APPLICATIVE_SOGGETTI_VIRTUALI,connectionPdD,ConfigurazionePdDType.config,idServizio);
  3499.         }

  3500.         if(pa!=null){
  3501.             this.logDebug("Oggetto trovato. Analizzo porte virtuali trovate rispetto alle proprieta' presenti nella busta arrivata: "+this.toStringFiltriProprieta(proprietaPresentiBustaRicevuta));
  3502.             Map<IDSoggetto,PortaApplicativa> paChecked = new java.util.HashMap<>();
  3503.             Iterator<IDSoggetto> it = pa.keySet().iterator();
  3504.             while (it.hasNext()) {
  3505.                 IDSoggetto idS = it.next();
  3506.                 PortaApplicativa paC = pa.get(idS);
  3507.                 this.logDebug("Analizzo pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]...");
  3508.                 if(useFiltroProprieta){
  3509.                     boolean ricezioneAutorizzata = checkProprietaFiltroPortaApplicativa(paC,proprietaPresentiBustaRicevuta);
  3510.                     if(ricezioneAutorizzata){
  3511.                         this.logDebug("Filtri matchano le protocol properties della pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]");
  3512.                         paChecked.put(idS,paC);
  3513.                     }else{
  3514.                         this.logDebug("Filtri non matchano le protocol properties della pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]");
  3515.                     }
  3516.                 }else{
  3517.                     this.logDebug("Invocazione metodo senza la richiesta di filtro per proprieta, aggiunta pa ["+paC.getNome()+"] del soggetto ["+idS.toString()+"]");
  3518.                     paChecked.put(idS,paC);
  3519.                 }
  3520.             }
  3521.             if(paChecked.size()>0)
  3522.                 return paChecked;
  3523.         }

  3524.         throw new DriverConfigurazioneNotFound("["+METHOD_GET_PORTE_APPLICATIVE_SOGGETTI_VIRTUALI+"] PA_SoggettiVirtuali non trovati");
  3525.     }
  3526.    
  3527.     private String toStringFiltriProprieta(Map<String, String> filtroProprietaPorteApplicative){
  3528.         StringBuilder bf = new StringBuilder();
  3529.         if(filtroProprietaPorteApplicative==null || filtroProprietaPorteApplicative.size()<=0){
  3530.             bf.append("Non presenti");
  3531.         }else{
  3532.             Iterator<String> it = filtroProprietaPorteApplicative.keySet().iterator();
  3533.             while (it.hasNext()) {
  3534.                 String key = it.next();
  3535.                 bf.append("\n");
  3536.                 bf.append(key+" = "+filtroProprietaPorteApplicative.get(key));
  3537.             }
  3538.         }
  3539.         return bf.toString();
  3540.     }
  3541.     private boolean checkProprietaFiltroPortaApplicativa(PortaApplicativa pa,Map<String, String> proprietaPresentiBustaRicevuta){
  3542.         boolean filtriPAPresenti = false;
  3543.         //System.out.println("Entro.... PROPRIETA' PRESENTI["+pa.sizeSetProtocolPropertyList()+"] JMS["+filtroProprietaPorteApplicative.size()+"]");

  3544.         /*Enumeration<String> en = filtroProprietaPorteApplicative.keys();
  3545.         while (en.hasMoreElements()){
  3546.             String key = en.nextElement();
  3547.             String value = filtroProprietaPorteApplicative.get(key);
  3548.             System.out.println("Proprieta' JMS: ["+key+"]=["+value+"]");
  3549.         }*/

  3550.         if(proprietaPresentiBustaRicevuta!=null && (proprietaPresentiBustaRicevuta.size()>0) ){

  3551.             for(int i=0; i<pa.sizeProprietaList(); i++){
  3552.                 String nome = pa.getProprieta(i).getNome();
  3553.                 String value = pa.getProprieta(i).getValore();
  3554.                 this.logDebug("ProprietaProtocollo della PA["+pa.getNome()+"] nome["+nome+"] valore["+value+"]");

  3555.                 //System.out.println("Esamino ["+nome+"]["+value+"]");
  3556.                 if(value.indexOf("!#!")!=-1){
  3557.                     //System.out.println("FILTRIPAPresenti");
  3558.                     filtriPAPresenti = true;
  3559.                     String [] split = value.split("!#!");
  3560.                     if(split!=null && split.length==2){
  3561.                         // operator come filtro
  3562.                         // I filtri nelle Protocol Properties sono in OR
  3563.                         //System.out.println("prelevo proprrieta...");

  3564.                         String operatoreP = split[1].trim();
  3565.                         String valoreP = split[0].trim();

  3566.                         String proprietaArrivata = proprietaPresentiBustaRicevuta.get(nome);

  3567.                         this.logDebug("ProtocolProperty della PA["+pa.getNome()+"] nome["+nome+"] valore["+value+"] interpretata come ["+nome+"]["+operatoreP+"]["+valoreP+"]. Viene utilizzata per la proprieta' della busta con valore ["+proprietaArrivata+"]");

  3568.                         if(proprietaArrivata!=null){

  3569.                             proprietaArrivata = proprietaArrivata.trim();
  3570.                             //System.out.println("NOMEP["+nome+"] OPERATORE["+operatoreP+"] PROPRIETA' ARRIVATA["+proprietaArrivata+"] VALORE["+split[0].trim()+"]");

  3571.                             if("=".equals(operatoreP)){
  3572.                                 if(proprietaArrivata.equals(valoreP)){
  3573.                                     return true;
  3574.                                 }
  3575.                             }else if(">".equals(operatoreP)){
  3576.                                 if(proprietaArrivata.compareTo(valoreP)>0){
  3577.                                     return true;
  3578.                                 }
  3579.                             }else if(">=".equals(operatoreP)){
  3580.                                 if(proprietaArrivata.compareTo(valoreP)>=0){
  3581.                                     return true;
  3582.                                 }
  3583.                             }else if("<".equals(operatoreP)){
  3584.                                 if(proprietaArrivata.compareTo(valoreP)<0){
  3585.                                     return true;
  3586.                                 }
  3587.                             }else if("<=".equals(operatoreP)){
  3588.                                 if(proprietaArrivata.compareTo(valoreP)<=0){
  3589.                                     return true;
  3590.                                 }
  3591.                             }else if("<>".equals(operatoreP)){
  3592.                                 if(!proprietaArrivata.equals(valoreP)){
  3593.                                     return true;
  3594.                                 }
  3595.                             }else if("like".equalsIgnoreCase(operatoreP)){
  3596.                                 String valoreMatch = valoreP.replaceAll("%", "");
  3597.                                 int indexExpr = proprietaArrivata.indexOf(valoreMatch);
  3598.                                 if(indexExpr>=0){
  3599.                                     return true;
  3600.                                 }
  3601.                             }
  3602.                             else{
  3603.                                 this.logError("[checkProprietaFiltroPortaApplicativa] Operator ["+operatoreP+"] non supportato per le protocol properties...");
  3604.                             }
  3605.                         }
  3606.                     }
  3607.                 }
  3608.             }

  3609.         }else{

  3610.             // Proprieta' non presenti nella busta ricevuta
  3611.             // Controllo se la PA richiedeva un filtro per protocol properties.
  3612.             for(int i=0; i<pa.sizeProprietaList(); i++){
  3613.                 String nome = pa.getProprieta(i).getNome();
  3614.                 String value = pa.getProprieta(i).getValore();
  3615.                 this.logDebug("ProtocolProperty della PA["+pa.getNome()+"] nome["+nome+"] valore["+value+"]");

  3616.                 //System.out.println("Esamino ["+nome+"]["+value+"]");
  3617.                 if(value.indexOf("!#!")!=-1){
  3618.                     //System.out.println("FILTRIPAPresenti");
  3619.                     this.logDebug("ProtocolProperty della PA["+pa.getNome()+"] nome["+nome+"] valore["+value+"] contiene una richiesta di filtro, siccome la busta arrivata non contiene proprieta', la PA non ha diritto a riceverla.");
  3620.                     filtriPAPresenti = true;
  3621.                     break;
  3622.                 }
  3623.             }
  3624.         }


  3625.         //System.out.println("FILTRI PA["+filtriPAPresenti+"]");
  3626.         if(filtriPAPresenti)
  3627.             return false;
  3628.         else
  3629.             return true;
  3630.     }
  3631.  
  3632.     private static org.openspcoop2.utils.Semaphore semaphore_getTemplateTrasformazionePA = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_TemplateTrasformazionePA");
  3633.     protected static String getKey_getPortaApplicativaTemplate(IDPortaApplicativa idPA, TemplateSource source, String identificativo){
  3634.         String prefixPA = _getKey_getPortaApplicativa(idPA);
  3635.         return prefixPA+"_getTemplate_"+source.name()+"_"+identificativo;
  3636.     }
  3637.     public Template getTemplateTrasformazioneRichiesta(Connection connectionPdD,IDPortaApplicativa idPA, String nomeTrasformazione, TrasformazioneRegolaRichiesta richiesta,
  3638.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3639.         TipoTrasformazione tipoTrasformazione = null;
  3640.         if(richiesta.getConversioneTipo()!=null) {
  3641.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(richiesta.getConversioneTipo());
  3642.         }
  3643.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  3644.             return new Template(nomeTrasformazione, richiesta.getConversioneTemplate());
  3645.         }
  3646.         return _getTemplate(connectionPdD, idPA, "getTemplateTrasformazioneRichiesta", TemplateSource.TRASFORMAZIONE_RICHIESTA, nomeTrasformazione, richiesta.getConversioneTemplate(),
  3647.                 requestInfo);
  3648.     }
  3649.     public Template getTemplateTrasformazioneSoapRichiesta(Connection connectionPdD,IDPortaApplicativa idPA, String nomeTrasformazione, TrasformazioneRegolaRichiesta richiesta,
  3650.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3651.         TipoTrasformazione tipoTrasformazione = null;
  3652.         if(richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo()!=null) {
  3653.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo());
  3654.         }
  3655.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  3656.             return new Template(nomeTrasformazione, richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  3657.         }
  3658.         return _getTemplate(connectionPdD, idPA, "getTemplateTrasformazioneSoapRichiesta", TemplateSource.TRASFORMAZIONE_SOAP_RICHIESTA, nomeTrasformazione, richiesta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate(),
  3659.                 requestInfo);
  3660.     }
  3661.     public Template getTemplateTrasformazioneRisposta(Connection connectionPdD,IDPortaApplicativa idPA, String nomeTrasformazione, TrasformazioneRegolaRisposta risposta,
  3662.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3663.         TipoTrasformazione tipoTrasformazione = null;
  3664.         if(risposta.getConversioneTipo()!=null) {
  3665.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(risposta.getConversioneTipo());
  3666.         }
  3667.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  3668.             return new Template(nomeTrasformazione, risposta.getConversioneTemplate());
  3669.         }
  3670.         return _getTemplate(connectionPdD, idPA, "getTemplateTrasformazioneRisposta", TemplateSource.TRASFORMAZIONE_RISPOSTA, nomeTrasformazione+"@@"+risposta.getNome(), risposta.getConversioneTemplate(),
  3671.                 requestInfo);
  3672.     }
  3673.     public Template getTemplateTrasformazioneSoapRisposta(Connection connectionPdD,IDPortaApplicativa idPA, String nomeTrasformazione, TrasformazioneRegolaRisposta risposta,
  3674.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3675.         TipoTrasformazione tipoTrasformazione = null;
  3676.         if(risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo()!=null) {
  3677.             tipoTrasformazione = TipoTrasformazione.toEnumConstant(risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo());
  3678.         }
  3679.         if(tipoTrasformazione==null || (!tipoTrasformazione.isTemplateFreemarker() && !tipoTrasformazione.isTemplateVelocity())) {
  3680.             return new Template(nomeTrasformazione, risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  3681.         }
  3682.         return _getTemplate(connectionPdD, idPA, "getTemplateTrasformazioneSoapRisposta", TemplateSource.TRASFORMAZIONE_SOAP_RISPOSTA, nomeTrasformazione+"@@"+risposta.getNome(), risposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate(),
  3683.                 requestInfo);
  3684.     }
  3685.    
  3686.     public Template getTemplateConnettoreMultiploSticky(Connection connectionPdD,IDPortaApplicativa idPA, byte[] template,
  3687.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3688.         return _getTemplate(connectionPdD, idPA, "getTemplateConnettoreMultiploSticky", TemplateSource.CONNETTORI_MULTIPLI_STICKY, "sticky", template,
  3689.                 requestInfo);
  3690.     }
  3691.     public Template getTemplateConnettoreMultiploCondizionale(Connection connectionPdD,IDPortaApplicativa idPA, String nomeRegola, byte[] template,
  3692.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3693.         return _getTemplate(connectionPdD, idPA, "getTemplateConnettoreMultiploCondizionale", TemplateSource.CONNETTORI_MULTIPLI_CONSEGNA_CONDIZIONALE, (nomeRegola!=null ? nomeRegola : "___default___"), template,
  3694.                 requestInfo);
  3695.     }
  3696.    
  3697.     public Template getTemplateCorrelazioneApplicativaRichiesta(Connection connectionPdD,IDPortaApplicativa idPA, String nomeRegola, byte[] template,
  3698.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3699.         return _getTemplate(connectionPdD, idPA, "getTemplateCorrelazioneApplicativaRichiesta", TemplateSource.CORRELAZIONE_APPLICATIVA_RICHIESTA, (nomeRegola!=null ? nomeRegola : "___default___"), template,
  3700.                 requestInfo);
  3701.     }
  3702.     public Template getTemplateCorrelazioneApplicativaRisposta(Connection connectionPdD,IDPortaApplicativa idPA, String nomeRegola, byte[] template,
  3703.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3704.         return _getTemplate(connectionPdD, idPA, "getTemplateCorrelazioneApplicativaRisposta", TemplateSource.CORRELAZIONE_APPLICATIVA_RISPOSTA, (nomeRegola!=null ? nomeRegola : "___default___"), template,
  3705.                 requestInfo);
  3706.     }
  3707.    
  3708.     private Template _getTemplate(Connection connectionPdD,IDPortaApplicativa idPA, String nomeMetodo, TemplateSource templateSource, String identificativo, byte[] templateBytes,
  3709.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3710.        
  3711.         String key = getKey_getPortaApplicativaTemplate(idPA, templateSource, identificativo);
  3712.    
  3713.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  3714.         if(useRequestInfo) {
  3715.             Object o = requestInfo.getRequestConfig().getTemplate(key);
  3716.             if(o!=null && o instanceof Template) {
  3717.                 return (Template) o;
  3718.             }
  3719.         }
  3720.    
  3721.         Template template = _getTemplate(connectionPdD, idPA, nomeMetodo, templateSource, identificativo, templateBytes, key);
  3722.         if(useRequestInfo && requestInfo!=null) {
  3723.             requestInfo.getRequestConfig().addTemplate(key, template,
  3724.                     requestInfo.getIdTransazione());
  3725.         }
  3726.         return template;
  3727.     }
  3728.     private Template _getTemplate(Connection connectionPdD,IDPortaApplicativa idPA, String nomeMetodo, TemplateSource templateSource, String identificativo, byte[] templateBytes,
  3729.         String key) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3730.        
  3731.         // Raccolta dati
  3732.         if(idPA == null)
  3733.             throw new DriverConfigurazioneException("["+nomeMetodo+"]: Parametro non definito (idPA is null)");
  3734.         if(idPA.getNome()==null)
  3735.             throw new DriverConfigurazioneException("["+nomeMetodo+"]: Parametro non definito (idPA.getNome() is null)");

  3736.         // se e' attiva una cache provo ad utilizzarla
  3737.         if(this.cache!=null) {
  3738.             org.openspcoop2.utils.cache.CacheResponse response =
  3739.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3740.             if(response != null){
  3741.                 if(response.getException()!=null){
  3742.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3743.                         throw (DriverConfigurazioneNotFound) response.getException();
  3744.                     else
  3745.                         throw (DriverConfigurazioneException) response.getException();
  3746.                 }else{
  3747.                     Template template = (Template) response.getObject();
  3748.                     if(template!=null){
  3749.                         return template;
  3750.                     }
  3751.                 }
  3752.             }
  3753.         }

  3754.         Template template = null;
  3755.        
  3756.         SemaphoreLock lock = semaphore_getTemplateTrasformazionePA.acquireThrowRuntime(nomeMetodo);
  3757.         try {
  3758.            
  3759.             if(this.cache!=null) {
  3760.                 org.openspcoop2.utils.cache.CacheResponse response =
  3761.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3762.                 if(response != null){
  3763.                     if(response.getException()!=null){
  3764.                         if(notFoundClassName.equals(response.getException().getClass().getName()))
  3765.                             throw (DriverConfigurazioneNotFound) response.getException();
  3766.                         else
  3767.                             throw (DriverConfigurazioneException) response.getException();
  3768.                     }else{
  3769.                         template = (Template) response.getObject();
  3770.                         if(template!=null){
  3771.                             return template;
  3772.                         }
  3773.                     }
  3774.                 }
  3775.             }
  3776.            
  3777.             template = new Template(key, templateBytes);
  3778.            
  3779.             // Aggiungo la risposta in cache (se esiste una cache)  
  3780.             // Se ho una eccezione aggiungo in cache solo una not found
  3781.             if( this.cache!=null ){    
  3782.                 this.logInfo("Aggiungo oggetto ["+key+"] in cache");
  3783.                 try{    
  3784.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  3785.                     responseCache.setObject((java.io.Serializable)template);
  3786.                     this.cache.put(key,responseCache);
  3787.                 }catch(UtilsException e){
  3788.                     this.logError("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  3789.                 }
  3790.             }
  3791.            
  3792.         }finally {
  3793.             semaphore_getTemplateTrasformazionePA.release(lock, nomeMetodo);
  3794.         }

  3795.         return template;

  3796.     }  
  3797.    
  3798.     public Template getTemplateIntegrazione(Connection connectionPdD,IDPortaApplicativa idPA, File file,
  3799.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3800.         return _getTemplate(connectionPdD, idPA, "getTemplateIntegrazione", TemplateSource.INTEGRAZIONE, file,
  3801.                 requestInfo);
  3802.     }
  3803.     private Template _getTemplate(Connection connectionPdD,IDPortaApplicativa idPA, String nomeMetodo, TemplateSource templateSource, File file,
  3804.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3805.            
  3806.         String key = getKey_getPortaApplicativaTemplate(idPA, templateSource, file.getAbsolutePath());
  3807.        
  3808.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  3809.         if(useRequestInfo) {
  3810.             Object o = requestInfo.getRequestConfig().getTemplate(key);
  3811.             if(o!=null && o instanceof Template) {
  3812.                 return (Template) o;
  3813.             }
  3814.         }
  3815.        
  3816.         Template template = _getTemplate(connectionPdD, idPA, nomeMetodo, templateSource, file, key);
  3817.         if(useRequestInfo && requestInfo!=null) {
  3818.             requestInfo.getRequestConfig().addTemplate(key, template,
  3819.                     requestInfo.getIdTransazione());
  3820.         }
  3821.         return template;
  3822.     }
  3823.     private Template _getTemplate(Connection connectionPdD,IDPortaApplicativa idPA, String nomeMetodo, TemplateSource templateSource, File file,
  3824.             String key) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3825.        
  3826.         // se e' attiva una cache provo ad utilizzarla  
  3827.         if(this.cache!=null) {
  3828.             org.openspcoop2.utils.cache.CacheResponse response =
  3829.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3830.             if(response != null){
  3831.                 if(response.getException()!=null){
  3832.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3833.                         throw (DriverConfigurazioneNotFound) response.getException();
  3834.                     else
  3835.                         throw (DriverConfigurazioneException) response.getException();
  3836.                 }else{
  3837.                     Template template = (Template) response.getObject();
  3838.                     if(template!=null){
  3839.                         return template;
  3840.                     }
  3841.                 }
  3842.             }
  3843.         }

  3844.         Template template = null;
  3845.        
  3846.         SemaphoreLock lock = semaphore_getTemplateTrasformazionePA.acquireThrowRuntime(nomeMetodo);
  3847.         try {
  3848.            
  3849.             if(this.cache!=null) {
  3850.                 org.openspcoop2.utils.cache.CacheResponse response =
  3851.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3852.                 if(response != null){
  3853.                     if(response.getException()!=null){
  3854.                         if(notFoundClassName.equals(response.getException().getClass().getName()))
  3855.                             throw (DriverConfigurazioneNotFound) response.getException();
  3856.                         else
  3857.                             throw (DriverConfigurazioneException) response.getException();
  3858.                     }else{
  3859.                         template = (Template) response.getObject();
  3860.                         if(template!=null){
  3861.                             return template;
  3862.                         }
  3863.                     }
  3864.                 }
  3865.             }
  3866.            
  3867.             ContentFile cf = getContentFileEngine(file);
  3868.             if(cf.isExists()) {
  3869.                 template = new Template(key, cf.getContent());
  3870.             }
  3871.             else {
  3872.                 throw new DriverConfigurazioneException("File '"+file.getAbsolutePath()+"' cannot exists");
  3873.             }
  3874.            
  3875.             // Aggiungo la risposta in cache (se esiste una cache)  
  3876.             // Se ho una eccezione aggiungo in cache solo una not found
  3877.             if( this.cache!=null ){    
  3878.                 this.logInfo("Aggiungo oggetto ["+key+"] in cache");
  3879.                 try{    
  3880.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  3881.                     responseCache.setObject((java.io.Serializable)template);
  3882.                     this.cache.put(key,responseCache);
  3883.                 }catch(UtilsException e){
  3884.                     this.logError("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  3885.                 }
  3886.             }
  3887.            
  3888.         }finally {
  3889.             semaphore_getTemplateTrasformazionePA.release(lock, nomeMetodo);
  3890.         }

  3891.         return template;

  3892.     }
  3893.    
  3894.    
  3895.      
  3896.    
  3897.    
  3898.     // SERVIZIO APPLICATIVO
  3899.    
  3900.     protected static String _getKey_getServizioApplicativo(IDServizioApplicativo idServizioApplicativo){
  3901.         String key = "getServizioApplicativo_" + idServizioApplicativo.getIdSoggettoProprietario().getTipo() + idServizioApplicativo.getIdSoggettoProprietario().getNome()+"_"+
  3902.                 idServizioApplicativo.getNome();
  3903.         return key;
  3904.     }
  3905.     public ServizioApplicativo getServizioApplicativo(Connection connectionPdD,IDServizioApplicativo idServizioApplicativo)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3906.         // Raccolta dati
  3907.         if(idServizioApplicativo == null)
  3908.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (idServizioApplicativo)");    
  3909.         if(idServizioApplicativo.getNome()==null)
  3910.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (nome)");
  3911.         if(idServizioApplicativo.getIdSoggettoProprietario()==null || idServizioApplicativo.getIdSoggettoProprietario().getTipo()==null || idServizioApplicativo.getIdSoggettoProprietario().getNome()==null )
  3912.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (soggetto proprietario)");
  3913.        
  3914.         // se e' attiva una cache provo ad utilizzarla
  3915.         String key = null;  
  3916.         if(this.cache!=null){
  3917.             key = _getKey_getServizioApplicativo(idServizioApplicativo);
  3918.             org.openspcoop2.utils.cache.CacheResponse response =
  3919.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3920.             if(response != null){
  3921.                 if(response.getException()!=null){
  3922.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3923.                         throw (DriverConfigurazioneNotFound) response.getException();
  3924.                     else
  3925.                         throw (DriverConfigurazioneException) response.getException();
  3926.                 }else{
  3927.                     return ((ServizioApplicativo) response.getObject());
  3928.                 }
  3929.             }
  3930.         }

  3931.         // Algoritmo CACHE
  3932.         ServizioApplicativo s = null;
  3933.         if(this.cache!=null){
  3934.             s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativo",connectionPdD,ConfigurazionePdDType.config,idServizioApplicativo);
  3935.         }else{
  3936.             s = (ServizioApplicativo) this.getObject("getServizioApplicativo",connectionPdD,ConfigurazionePdDType.config,idServizioApplicativo);
  3937.         }

  3938.         if(s!=null)
  3939.             return s;
  3940.         else
  3941.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  3942.     }
  3943.    
  3944.     protected static String _toKey_getServizioApplicativoByCredenzialiBasicPrefix(){
  3945.         return "getServizioApplicativoByCredenzialiBasic";
  3946.     }
  3947.     private String _getKey_getServizioApplicativoByCredenzialiBasic(String aUser,String aPassword,
  3948.             List<String> tipiSoggetto){
  3949.         String key = _toKey_getServizioApplicativoByCredenzialiBasicPrefix();
  3950.         key = key +"_"+aUser+"_"+aPassword;
  3951.         if(tipiSoggetto!=null && !tipiSoggetto.isEmpty()) {
  3952.             key = key +"_"+tipiSoggetto.toString();
  3953.         }
  3954.         return key;
  3955.     }
  3956.     public ServizioApplicativo getServizioApplicativoByCredenzialiBasic(Connection connectionPdD,String aUser,String aPassword, CryptConfig config)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  3957.         return getServizioApplicativoByCredenzialiBasic(connectionPdD, aUser, aPassword, config, null);
  3958.     }
  3959.     public ServizioApplicativo getServizioApplicativoByCredenzialiBasic(Connection connectionPdD,String aUser,String aPassword, CryptConfig config,
  3960.             List<String> tipiSoggetto)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  3961.         // Raccolta dati
  3962.         if(aUser == null)
  3963.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (username)");
  3964.         if(aPassword == null)
  3965.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (password)");
  3966.        
  3967.         // se e' attiva una cache provo ad utilizzarla
  3968.         String key = null;  
  3969.         if(this.cache!=null){
  3970.             key = this._getKey_getServizioApplicativoByCredenzialiBasic(aUser, aPassword, tipiSoggetto);
  3971.             org.openspcoop2.utils.cache.CacheResponse response =
  3972.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3973.             if(response != null){
  3974.                 if(response.getException()!=null){
  3975.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3976.                         throw (DriverConfigurazioneNotFound) response.getException();
  3977.                     else
  3978.                         throw (DriverConfigurazioneException) response.getException();
  3979.                 }else{
  3980.                     return ((ServizioApplicativo) response.getObject());
  3981.                 }
  3982.             }
  3983.         }

  3984.         // Algoritmo CACHE
  3985.         ServizioApplicativo s = null;
  3986.         if(tipiSoggetto!=null) {
  3987.             if(this.cache!=null){
  3988.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiBasic",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, config, tipiSoggetto);
  3989.             }else{
  3990.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiBasic",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, config, tipiSoggetto);
  3991.             }
  3992.         }
  3993.         else {
  3994.             if(this.cache!=null){
  3995.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiBasic",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, config);
  3996.             }else{
  3997.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiBasic",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, config);
  3998.             }
  3999.         }

  4000.         if(s!=null)
  4001.             return s;
  4002.         else
  4003.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  4004.     }
  4005.    
  4006.     protected static String _toKey_getServizioApplicativoByCredenzialiApiKeyPrefix(boolean appId){
  4007.         return (appId ? "getServizioApplicativoByCredenzialiMultipleApiKey_" : "getServizioApplicativoByCredenzialiApiKey_");
  4008.     }
  4009.     private String _getKey_getServizioApplicativoByCredenzialiApiKey(String aUser,String aPassword, boolean appId,
  4010.             List<String> tipiSoggetto){
  4011.         String key = _toKey_getServizioApplicativoByCredenzialiApiKeyPrefix(appId);
  4012.         key = key +"_"+aUser+"_"+aPassword;
  4013.         if(tipiSoggetto!=null && !tipiSoggetto.isEmpty()) {
  4014.             key = key +"_"+tipiSoggetto.toString();
  4015.         }
  4016.         return key;
  4017.     }
  4018.     public ServizioApplicativo getServizioApplicativoByCredenzialiApiKey(Connection connectionPdD,String aUser,String aPassword, boolean appId, CryptConfig config)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4019.         return getServizioApplicativoByCredenzialiApiKey(connectionPdD, aUser, aPassword, appId, config, null);
  4020.     }
  4021.     public ServizioApplicativo getServizioApplicativoByCredenzialiApiKey(Connection connectionPdD,String aUser,String aPassword, boolean appId, CryptConfig config,
  4022.             List<String> tipiSoggetto)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4023.         // Raccolta dati
  4024.         if(aUser == null)
  4025.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (username)");
  4026.         if(aPassword == null)
  4027.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (password)");
  4028.        
  4029.         // se e' attiva una cache provo ad utilizzarla
  4030.         String key = null;  
  4031.         if(this.cache!=null){
  4032.             key = this._getKey_getServizioApplicativoByCredenzialiApiKey(aUser, aPassword, appId, tipiSoggetto);
  4033.             org.openspcoop2.utils.cache.CacheResponse response =
  4034.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4035.             if(response != null){
  4036.                 if(response.getException()!=null){
  4037.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4038.                         throw (DriverConfigurazioneNotFound) response.getException();
  4039.                     else
  4040.                         throw (DriverConfigurazioneException) response.getException();
  4041.                 }else{
  4042.                     return ((ServizioApplicativo) response.getObject());
  4043.                 }
  4044.             }
  4045.         }

  4046.         // Algoritmo CACHE
  4047.         ServizioApplicativo s = null;
  4048.         if(tipiSoggetto!=null) {
  4049.             if(this.cache!=null){
  4050.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiApiKey",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, appId, config, tipiSoggetto);
  4051.             }else{
  4052.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiApiKey",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, appId, config, tipiSoggetto);
  4053.             }
  4054.         }
  4055.         else {
  4056.             if(this.cache!=null){
  4057.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiApiKey",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, appId, config);
  4058.             }else{
  4059.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiApiKey",connectionPdD,ConfigurazionePdDType.config,aUser,aPassword, appId, config);
  4060.             }
  4061.         }

  4062.         if(s!=null)
  4063.             return s;
  4064.         else
  4065.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  4066.     }
  4067.    
  4068.     protected static String _toKey_getServizioApplicativoByCredenzialiSslPrefix(boolean separator){
  4069.         return "getServizioApplicativoByCredenzialiSsl"+(separator?"_":"");
  4070.     }
  4071.     private String _getKey_getServizioApplicativoByCredenzialiSsl(String aSubject, String Issuer,
  4072.             List<String> tipiSoggetto,
  4073.             boolean includiApplicativiNonModI, boolean includiApplicativiModIEsterni, boolean includiApplicativiModIInterni){
  4074.         String key = _toKey_getServizioApplicativoByCredenzialiSslPrefix(false);
  4075.         key = key +"_subject:"+aSubject;
  4076.         if(Issuer!=null) {
  4077.             key = key +"_issuer:"+Issuer;
  4078.         }
  4079.         else {
  4080.             key = key +"_issuer:nonDefinito";
  4081.         }
  4082.         if(tipiSoggetto!=null && !tipiSoggetto.isEmpty()) {
  4083.             key = key +"_"+tipiSoggetto.toString();
  4084.             key = key +"_noModi:"+includiApplicativiNonModI;
  4085.             key = key +"_modiExt:"+includiApplicativiModIEsterni;
  4086.             key = key +"_modiInt:"+includiApplicativiModIInterni;
  4087.         }
  4088.         return key;
  4089.     }
  4090.     public ServizioApplicativo getServizioApplicativoByCredenzialiSsl(Connection connectionPdD,String aSubject, String aIssuer)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4091.         return getServizioApplicativoByCredenzialiSsl(connectionPdD, aSubject, aIssuer,
  4092.                 null);
  4093.     }
  4094.     public ServizioApplicativo getServizioApplicativoByCredenzialiSsl(Connection connectionPdD,String aSubject, String aIssuer,
  4095.             List<String> tipiSoggetto)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4096.         return getServizioApplicativoByCredenzialiSsl(connectionPdD, aSubject, aIssuer,
  4097.                 tipiSoggetto,
  4098.                 false, false, false);
  4099.     }
  4100.     public ServizioApplicativo getServizioApplicativoByCredenzialiSsl(Connection connectionPdD,String aSubject, String aIssuer,
  4101.             List<String> tipiSoggetto,
  4102.             boolean includiApplicativiNonModI, boolean includiApplicativiModIEsterni, boolean includiApplicativiModIInterni)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4103.         // Raccolta dati
  4104.         if(aSubject == null)
  4105.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (subject)");      
  4106.        
  4107.         // se e' attiva una cache provo ad utilizzarla
  4108.         String key = null;  
  4109.         if(this.cache!=null){
  4110.             key = this._getKey_getServizioApplicativoByCredenzialiSsl(aSubject, aIssuer, tipiSoggetto,
  4111.                     includiApplicativiNonModI, includiApplicativiModIEsterni, includiApplicativiModIInterni);
  4112.             org.openspcoop2.utils.cache.CacheResponse response =
  4113.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4114.             if(response != null){
  4115.                 if(response.getException()!=null){
  4116.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4117.                         throw (DriverConfigurazioneNotFound) response.getException();
  4118.                     else
  4119.                         throw (DriverConfigurazioneException) response.getException();
  4120.                 }else{
  4121.                     return ((ServizioApplicativo) response.getObject());
  4122.                 }
  4123.             }
  4124.         }

  4125.         // Algoritmo CACHE
  4126.         Class<?>[] classArguments = null;
  4127.         Object[]values = null;
  4128.         boolean driverXml = this.driverConfigurazionePdD instanceof DriverConfigurazioneXML;
  4129.         if(tipiSoggetto!=null && !driverXml) {
  4130.             if(includiApplicativiNonModI || includiApplicativiModIEsterni || includiApplicativiModIInterni) {
  4131.                 classArguments = new Class[] {String.class, String.class, List.class, boolean.class, boolean.class, boolean.class};
  4132.                 values = new Object[] {aSubject , aIssuer, tipiSoggetto, includiApplicativiNonModI, includiApplicativiModIEsterni, includiApplicativiModIInterni}; // passo gli argomenti tramite array poich' aIssuer puo' essere null
  4133.             }
  4134.             else {
  4135.                 classArguments = new Class[] {String.class, String.class, List.class};
  4136.                 values = new Object[] {aSubject , aIssuer, tipiSoggetto}; // passo gli argomenti tramite array poich' aIssuer puo' essere null
  4137.             }
  4138.         }
  4139.         else {
  4140.             classArguments = new Class[] {String.class, String.class};
  4141.             values = new Object[] {aSubject , aIssuer}; // passo gli argomenti tramite array poich' aIssuer puo' essere null
  4142.         }
  4143.         ServizioApplicativo s = null;
  4144.         if(this.cache!=null){
  4145.             s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiSsl",connectionPdD,ConfigurazionePdDType.config,classArguments, values);
  4146.         }else{
  4147.             s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiSsl",connectionPdD,ConfigurazionePdDType.config,classArguments, values);
  4148.         }

  4149.         if(s!=null)
  4150.             return s;
  4151.         else
  4152.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  4153.     }
  4154.    
  4155.     protected static String _toKey_getServizioApplicativoByCredenzialiSslCertPrefix(boolean separator){
  4156.         return "getServizioApplicativoByCredenzialiSslCert"+(separator?"_":"");
  4157.     }
  4158.     private String _getKey_getServizioApplicativoByCredenzialiSsl(CertificateInfo certificate, boolean strictVerifier,
  4159.             List<String> tipiSoggetto,
  4160.             boolean includiApplicativiNonModI, boolean includiApplicativiModIEsterni, boolean includiApplicativiModIInterni) throws DriverConfigurazioneException{
  4161.         try {
  4162.             String key = _toKey_getServizioApplicativoByCredenzialiSslCertPrefix(false);
  4163.             key = key +"_cert:"+certificate.digestBase64Encoded();
  4164.             key = key +"_strictVerifier:"+strictVerifier;
  4165.             if(tipiSoggetto!=null && !tipiSoggetto.isEmpty()) {
  4166.                 key = key +"_"+tipiSoggetto.toString();
  4167.                 key = key +"_noModi:"+includiApplicativiNonModI;
  4168.                 key = key +"_modiExt:"+includiApplicativiModIEsterni;
  4169.                 key = key +"_modiInt:"+includiApplicativiModIInterni;
  4170.             }
  4171.             return key;
  4172.         }catch(Exception e) {
  4173.             throw new DriverConfigurazioneException(e.getMessage(),e);
  4174.         }
  4175.     }
  4176.     public ServizioApplicativo getServizioApplicativoByCredenzialiSsl(Connection connectionPdD, CertificateInfo certificate, boolean strictVerifier) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4177.         return getServizioApplicativoByCredenzialiSsl(connectionPdD, certificate, strictVerifier,
  4178.                 null);
  4179.     }
  4180.     public ServizioApplicativo getServizioApplicativoByCredenzialiSsl(Connection connectionPdD, CertificateInfo certificate, boolean strictVerifier,
  4181.             List<String> tipiSoggetto) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4182.         return getServizioApplicativoByCredenzialiSsl(connectionPdD, certificate, strictVerifier,
  4183.                 tipiSoggetto,
  4184.                 false, false, false);
  4185.     }
  4186.     public ServizioApplicativo getServizioApplicativoByCredenzialiSsl(Connection connectionPdD, CertificateInfo certificate, boolean strictVerifier,
  4187.             List<String> tipiSoggetto,
  4188.             boolean includiApplicativiNonModI, boolean includiApplicativiModIEsterni, boolean includiApplicativiModIInterni) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4189.        
  4190.         // Raccolta dati
  4191.         if(certificate == null)
  4192.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (certificate)");      
  4193.        
  4194.         // se e' attiva una cache provo ad utilizzarla
  4195.         String key = null;  
  4196.         if(this.cache!=null){
  4197.             key = this._getKey_getServizioApplicativoByCredenzialiSsl(certificate, strictVerifier, tipiSoggetto,
  4198.                     includiApplicativiNonModI, includiApplicativiModIEsterni, includiApplicativiModIInterni);
  4199.             org.openspcoop2.utils.cache.CacheResponse response =
  4200.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4201.             if(response != null){
  4202.                 if(response.getException()!=null){
  4203.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4204.                         throw (DriverConfigurazioneNotFound) response.getException();
  4205.                     else
  4206.                         throw (DriverConfigurazioneException) response.getException();
  4207.                 }else{
  4208.                     return ((ServizioApplicativo) response.getObject());
  4209.                 }
  4210.             }
  4211.         }

  4212.         // Algoritmo CACHE
  4213.         Class<?>[] classArguments = null;
  4214.         Object[]values = null;
  4215.         boolean driverXml = this.driverConfigurazionePdD instanceof DriverConfigurazioneXML;
  4216.         if(tipiSoggetto!=null && !driverXml) {
  4217.             if(includiApplicativiNonModI || includiApplicativiModIEsterni || includiApplicativiModIInterni) {
  4218.                 classArguments = new Class[] {CertificateInfo.class, boolean.class, List.class, boolean.class, boolean.class, boolean.class};
  4219.                 values = new Object[] {certificate , strictVerifier, tipiSoggetto, includiApplicativiNonModI, includiApplicativiModIEsterni, includiApplicativiModIInterni};
  4220.             }
  4221.             else {
  4222.                 classArguments = new Class[] {CertificateInfo.class, boolean.class, List.class};
  4223.                 values = new Object[] {certificate , strictVerifier, tipiSoggetto};
  4224.             }
  4225.         }
  4226.         else {
  4227.             classArguments = new Class[] {CertificateInfo.class, boolean.class};
  4228.             values = new Object[] {certificate , strictVerifier};
  4229.         }
  4230.         ServizioApplicativo s = null;
  4231.         if(this.cache!=null){
  4232.             s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiSsl",connectionPdD,ConfigurazionePdDType.config, classArguments, values);
  4233.         }else{
  4234.             s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiSsl",connectionPdD,ConfigurazionePdDType.config, classArguments, values);
  4235.         }

  4236.         if(s!=null)
  4237.             return s;
  4238.         else
  4239.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  4240.     }
  4241.    
  4242.     protected static String _toKey_getServizioApplicativoByCredenzialiPrincipalPrefix(){
  4243.         return "getServizioApplicativoByCredenzialiPrincipal";
  4244.     }
  4245.     private String _getKey_getServizioApplicativoByCredenzialiPrincipal(String principal,
  4246.             List<String> tipiSoggetto){
  4247.         String key = _toKey_getServizioApplicativoByCredenzialiPrincipalPrefix();
  4248.         key = key +"_"+principal;
  4249.         if(tipiSoggetto!=null && !tipiSoggetto.isEmpty()) {
  4250.             key = key +"_"+tipiSoggetto.toString();
  4251.         }
  4252.         return key;
  4253.     }
  4254.     public ServizioApplicativo getServizioApplicativoByCredenzialiPrincipal(Connection connectionPdD,String principal)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4255.         return getServizioApplicativoByCredenzialiPrincipal(connectionPdD, principal, null);
  4256.     }
  4257.     public ServizioApplicativo getServizioApplicativoByCredenzialiPrincipal(Connection connectionPdD,String principal,
  4258.             List<String> tipiSoggetto)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4259.         // Raccolta dati
  4260.         if(principal == null)
  4261.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (principal)");        
  4262.        
  4263.         // se e' attiva una cache provo ad utilizzarla
  4264.         String key = null;  
  4265.         if(this.cache!=null){
  4266.             key = this._getKey_getServizioApplicativoByCredenzialiPrincipal(principal, tipiSoggetto);
  4267.             org.openspcoop2.utils.cache.CacheResponse response =
  4268.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4269.             if(response != null){
  4270.                 if(response.getException()!=null){
  4271.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4272.                         throw (DriverConfigurazioneNotFound) response.getException();
  4273.                     else
  4274.                         throw (DriverConfigurazioneException) response.getException();
  4275.                 }else{
  4276.                     return ((ServizioApplicativo) response.getObject());
  4277.                 }
  4278.             }
  4279.         }

  4280.         // Algoritmo CACHE
  4281.         ServizioApplicativo s = null;
  4282.         if(tipiSoggetto!=null) {
  4283.             if(this.cache!=null){
  4284.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiPrincipal",connectionPdD,ConfigurazionePdDType.config,principal,tipiSoggetto);
  4285.             }else{
  4286.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiPrincipal",connectionPdD,ConfigurazionePdDType.config,principal,tipiSoggetto);
  4287.             }
  4288.         }
  4289.         else {
  4290.             if(this.cache!=null){
  4291.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiPrincipal",connectionPdD,ConfigurazionePdDType.config,principal);
  4292.             }else{
  4293.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiPrincipal",connectionPdD,ConfigurazionePdDType.config,principal);
  4294.             }
  4295.         }

  4296.         if(s!=null)
  4297.             return s;
  4298.         else
  4299.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  4300.     }
  4301.    
  4302.     protected static String _toKey_getServizioApplicativoByCredenzialiTokenPrefix(){
  4303.         return "getServizioApplicativoByCredenzialiToken";
  4304.     }
  4305.     private String _getKey_getServizioApplicativoByCredenzialiToken(String tokenPolicy, String tokenClientId,
  4306.             List<String> tipiSoggetto) throws DriverConfigurazioneException{
  4307.         String key = _toKey_getServizioApplicativoByCredenzialiTokenPrefix();
  4308.         key = key +"_"+tokenPolicy+"@[https:"+this.isTokenWithHttpsEnabled()+"]"+tokenClientId;
  4309.         if(tipiSoggetto!=null && !tipiSoggetto.isEmpty()) {
  4310.             key = key +"_"+tipiSoggetto.toString();
  4311.         }
  4312.         return key;
  4313.     }
  4314.     public ServizioApplicativo getServizioApplicativoByCredenzialiToken(Connection connectionPdD,String tokenPolicy, String tokenClientId)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4315.         return getServizioApplicativoByCredenzialiToken(connectionPdD, tokenPolicy, tokenClientId, null);
  4316.     }
  4317.     public ServizioApplicativo getServizioApplicativoByCredenzialiToken(Connection connectionPdD,String tokenPolicy, String tokenClientId,
  4318.             List<String> tipiSoggetto)throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4319.         // Raccolta dati
  4320.         if(tokenPolicy == null)
  4321.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (tokenPolicy)");      
  4322.         if(tokenClientId == null)
  4323.             throw new DriverConfigurazioneException("[getServizioApplicativo]: Parametro non definito (tokenClientId)");    
  4324.        
  4325.         // se e' attiva una cache provo ad utilizzarla
  4326.         String key = null;  
  4327.         if(this.cache!=null){
  4328.             key = this._getKey_getServizioApplicativoByCredenzialiToken(tokenPolicy, tokenClientId,tipiSoggetto);
  4329.             org.openspcoop2.utils.cache.CacheResponse response =
  4330.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4331.             if(response != null){
  4332.                 if(response.getException()!=null){
  4333.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4334.                         throw (DriverConfigurazioneNotFound) response.getException();
  4335.                     else
  4336.                         throw (DriverConfigurazioneException) response.getException();
  4337.                 }else{
  4338.                     return ((ServizioApplicativo) response.getObject());
  4339.                 }
  4340.             }
  4341.         }

  4342.         // Algoritmo CACHE
  4343.         ServizioApplicativo s = null;
  4344.         if(tipiSoggetto!=null) {
  4345.             if(this.cache!=null){
  4346.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiToken",connectionPdD,ConfigurazionePdDType.config,tokenPolicy, tokenClientId, this.isTokenWithHttpsEnabled(), tipiSoggetto);
  4347.             }else{
  4348.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiToken",connectionPdD,ConfigurazionePdDType.config,tokenPolicy, tokenClientId, this.isTokenWithHttpsEnabled(), tipiSoggetto);
  4349.             }
  4350.         }
  4351.         else {
  4352.             if(this.cache!=null){
  4353.                 s = (ServizioApplicativo) this.getObjectCache(key,"getServizioApplicativoByCredenzialiToken",connectionPdD,ConfigurazionePdDType.config,tokenPolicy, tokenClientId, this.isTokenWithHttpsEnabled());
  4354.             }else{
  4355.                 s = (ServizioApplicativo) this.getObject("getServizioApplicativoByCredenzialiToken",connectionPdD,ConfigurazionePdDType.config,tokenPolicy, tokenClientId, this.isTokenWithHttpsEnabled());
  4356.             }
  4357.         }

  4358.         if(s!=null)
  4359.             return s;
  4360.         else
  4361.             throw new DriverConfigurazioneNotFound("Servizio Applicativo non trovato");
  4362.     }
  4363.    
  4364.     public static String getKey_getConnettoriConsegnaNotifichePrioritarie(String queue){
  4365.         String key = "getConnettoriConsegnaNotifichePrioritarie";
  4366.         if(queue!=null) {
  4367.             key = key +"_"+queue;
  4368.         }
  4369.         return key;
  4370.     }
  4371.     @SuppressWarnings("unchecked")
  4372.     public List<IDConnettore> getConnettoriConsegnaNotifichePrioritarie(Connection connectionPdD, String queue) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4373.         // se e' attiva una cache provo ad utilizzarla
  4374.         String key = null;  
  4375.         if(this.cache!=null){
  4376.             key = getKey_getConnettoriConsegnaNotifichePrioritarie(queue);
  4377.             org.openspcoop2.utils.cache.CacheResponse response =
  4378.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4379.             if(response != null){
  4380.                 if(response.getException()!=null){
  4381.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4382.                         throw (DriverConfigurazioneNotFound) response.getException();
  4383.                     else
  4384.                         throw (DriverConfigurazioneException) response.getException();
  4385.                 }else{
  4386.                     return ((List<IDConnettore>) response.getObject());
  4387.                 }
  4388.             }
  4389.         }

  4390.         // Algoritmo CACHE
  4391.         List<IDConnettore> l = null;
  4392.         if(this.cache!=null){
  4393.             l = (List<IDConnettore>) this.getObjectCache(key,"getConnettoriConsegnaNotifichePrioritarie",connectionPdD,ConfigurazionePdDType.config,queue);
  4394.         }else{
  4395.             l = (List<IDConnettore>) this.getObject("getConnettoriConsegnaNotifichePrioritarie",connectionPdD,ConfigurazionePdDType.config,queue);
  4396.         }

  4397.         if(l!=null)
  4398.             return l;
  4399.         else
  4400.             throw new DriverConfigurazioneNotFound("Connettori non trovati");
  4401.     }
  4402.     public void resetConnettoriConsegnaNotifichePrioritarie(Connection connectionPdD, String queue) throws DriverConfigurazioneException{
  4403.         org.openspcoop2.core.config.driver.IDriverConfigurazioneGet driver = getDriver(connectionPdD);
  4404.         if((driver instanceof DriverConfigurazioneDB)){
  4405.             DriverConfigurazioneDB driverDB = (DriverConfigurazioneDB) driver;
  4406.             driverDB.resetConnettoriConsegnaNotifichePrioritarie(queue);
  4407.         }
  4408.     }
  4409.    

  4410.    


  4411.    
  4412.     // CONFIGURAZIONE

  4413.     private String _getKey_getRoutingTable(){
  4414.         return "getRoutingTable";
  4415.     }
  4416.     public RoutingTable getRoutingTable(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4417.         // Se e' attiva una configurazione statica, la utilizzo.
  4418.         if(this.configurazioneDinamica==false){
  4419.             if(ConfigurazionePdD.routingTable!=null)
  4420.                 return ConfigurazionePdD.routingTable;
  4421.         }

  4422.         // se e' attiva una cache provo ad utilizzarla
  4423.         String key = null;  
  4424.         if(this.cache!=null){
  4425.             key = this._getKey_getRoutingTable();
  4426.             org.openspcoop2.utils.cache.CacheResponse response =
  4427.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4428.             if(response != null){
  4429.                 if(response.getException()!=null){
  4430.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4431.                         throw (DriverConfigurazioneNotFound) response.getException();
  4432.                     else
  4433.                         throw (DriverConfigurazioneException) response.getException();
  4434.                 }else{
  4435.                     return ((RoutingTable) response.getObject());
  4436.                 }
  4437.             }
  4438.         }

  4439.         // Algoritmo CACHE
  4440.         RoutingTable r = null;
  4441.         if(this.cache!=null){
  4442.             r = (RoutingTable) this.getObjectCache(key,"getRoutingTable",connectionPdD,ConfigurazionePdDType.config);
  4443.         }else{
  4444.             r = (RoutingTable) this.getObject("getRoutingTable",connectionPdD,ConfigurazionePdDType.config);
  4445.         }

  4446.         if(r!=null){
  4447.             // Se e' attiva una configurazione statica, la utilizzo.
  4448.             if(this.configurazioneDinamica==false){
  4449.                 ConfigurazionePdD.routingTable= r;
  4450.             }
  4451.             return r;
  4452.         }
  4453.         else{
  4454.             throw new DriverConfigurazioneNotFound("[getRoutingTable] RoutingTable non trovata");
  4455.         }
  4456.     }

  4457.     private static final String METHOD_GET_ACCESSO_DATI_REGISTRO = "getAccessoRegistro";
  4458.     private String getKeyMethodGetAccessoRegistro(){
  4459.         return METHOD_GET_ACCESSO_DATI_REGISTRO;
  4460.     }
  4461.     public AccessoRegistro getAccessoRegistro(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4462.         // Se e' attiva una configurazione statica, la utilizzo.
  4463.         if(!this.configurazioneDinamica &&
  4464.             ConfigurazionePdD.accessoRegistro!=null) {
  4465.             return ConfigurazionePdD.accessoRegistro;
  4466.         }

  4467.         // se e' attiva una cache provo ad utilizzarla
  4468.         String key = null;  
  4469.         if(this.cache!=null){
  4470.             key = getKeyMethodGetAccessoRegistro();
  4471.             org.openspcoop2.utils.cache.CacheResponse response =
  4472.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4473.             if(response != null){
  4474.                 if(response.getException()!=null){
  4475.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4476.                         throw (DriverConfigurazioneNotFound) response.getException();
  4477.                     else
  4478.                         throw (DriverConfigurazioneException) response.getException();
  4479.                 }else{
  4480.                     return ((AccessoRegistro) response.getObject());
  4481.                 }
  4482.             }
  4483.         }

  4484.         // Algoritmo CACHE
  4485.         AccessoRegistro ar = null;
  4486.         if(this.cache!=null){
  4487.             ar = (AccessoRegistro) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_REGISTRO,connectionPdD,ConfigurazionePdDType.config);
  4488.         }else{
  4489.             ar = (AccessoRegistro) this.getObject(METHOD_GET_ACCESSO_DATI_REGISTRO,connectionPdD,ConfigurazionePdDType.config);
  4490.         }

  4491.         if(ar!=null){
  4492.             // Se e' attiva una configurazione statica, la utilizzo.
  4493.             if(!this.configurazioneDinamica){
  4494.                 ConfigurazionePdD.setAccessoRegistro(ar);
  4495.             }
  4496.             return ar;
  4497.         }
  4498.         else{
  4499.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_REGISTRO+"] Configurazione di accesso ai registri non trovata");
  4500.         }
  4501.     }

  4502.     private static final String METHOD_GET_ACCESSO_DATI_CONFIGURAZIONE = "getAccessoConfigurazione";
  4503.     private String getKeyMethodGetAccessoConfigurazione(){
  4504.         return METHOD_GET_ACCESSO_DATI_CONFIGURAZIONE;
  4505.     }
  4506.     public AccessoConfigurazione getAccessoConfigurazione(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4507.         // Se e' attiva una configurazione statica, la utilizzo.
  4508.         if(!this.configurazioneDinamica &&
  4509.             ConfigurazionePdD.accessoConfigurazione!=null) {
  4510.             return ConfigurazionePdD.accessoConfigurazione;
  4511.         }

  4512.         // se e' attiva una cache provo ad utilizzarla
  4513.         String key = null;  
  4514.         if(this.cache!=null){
  4515.             key = this.getKeyMethodGetAccessoConfigurazione();
  4516.             org.openspcoop2.utils.cache.CacheResponse response =
  4517.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4518.             if(response != null){
  4519.                 if(response.getException()!=null){
  4520.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4521.                         throw (DriverConfigurazioneNotFound) response.getException();
  4522.                     else
  4523.                         throw (DriverConfigurazioneException) response.getException();
  4524.                 }else{
  4525.                     return ((AccessoConfigurazione) response.getObject());
  4526.                 }
  4527.             }
  4528.         }

  4529.         // Algoritmo CACHE
  4530.         AccessoConfigurazione object = null;
  4531.         if(this.cache!=null){
  4532.             object = (AccessoConfigurazione) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_CONFIGURAZIONE,connectionPdD,ConfigurazionePdDType.config);
  4533.         }else{
  4534.             object = (AccessoConfigurazione) this.getObject(METHOD_GET_ACCESSO_DATI_CONFIGURAZIONE,connectionPdD,ConfigurazionePdDType.config);
  4535.         }

  4536.         if(object!=null){
  4537.             // Se e' attiva una configurazione statica, la utilizzo.
  4538.             if(!this.configurazioneDinamica){
  4539.                 ConfigurazionePdD.setAccessoConfigurazione(object);
  4540.             }
  4541.             return object;
  4542.         }
  4543.         else{
  4544.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_CONFIGURAZIONE+"] Configurazione di accesso alla configurazione non trovata");
  4545.         }
  4546.     }

  4547.     private static final String METHOD_GET_ACCESSO_DATI_AUTORIZZAZIONE = "getAccessoDatiAutorizzazione";
  4548.     private String getKeyMethodGetAccessoDatiAutorizzazione(){
  4549.         return METHOD_GET_ACCESSO_DATI_AUTORIZZAZIONE;
  4550.     }
  4551.     public AccessoDatiAutorizzazione getAccessoDatiAutorizzazione(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4552.         // Se e' attiva una configurazione statica, la utilizzo.
  4553.         if(!this.configurazioneDinamica &&
  4554.             ConfigurazionePdD.accessoDatiAutorizzazione!=null) {
  4555.             return ConfigurazionePdD.accessoDatiAutorizzazione;
  4556.         }

  4557.         // se e' attiva una cache provo ad utilizzarla
  4558.         String key = null;  
  4559.         if(this.cache!=null){
  4560.             key = this.getKeyMethodGetAccessoDatiAutorizzazione();
  4561.             org.openspcoop2.utils.cache.CacheResponse response =
  4562.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4563.             if(response != null){
  4564.                 if(response.getException()!=null){
  4565.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4566.                         throw (DriverConfigurazioneNotFound) response.getException();
  4567.                     else
  4568.                         throw (DriverConfigurazioneException) response.getException();
  4569.                 }else{
  4570.                     return ((AccessoDatiAutorizzazione) response.getObject());
  4571.                 }
  4572.             }
  4573.         }

  4574.         // Algoritmo CACHE
  4575.         AccessoDatiAutorizzazione object = null;
  4576.         if(this.cache!=null){
  4577.             object = (AccessoDatiAutorizzazione) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_AUTORIZZAZIONE,connectionPdD,ConfigurazionePdDType.config);
  4578.         }else{
  4579.             object = (AccessoDatiAutorizzazione) this.getObject(METHOD_GET_ACCESSO_DATI_AUTORIZZAZIONE,connectionPdD,ConfigurazionePdDType.config);
  4580.         }

  4581.         if(object!=null){
  4582.             // Se e' attiva una configurazione statica, la utilizzo.
  4583.             if(!this.configurazioneDinamica){
  4584.                 ConfigurazionePdD.setAccessoDatiAutorizzazione(object);
  4585.             }
  4586.             return object;
  4587.         }
  4588.         else{
  4589.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_AUTORIZZAZIONE+"] Configurazione di accesso ai dati di autorizzazione non trovata");
  4590.         }
  4591.     }
  4592.    
  4593.     private static final String METHOD_GET_ACCESSO_DATI_AUTENTICAZIONE = "getAccessoDatiAutenticazione";
  4594.     private String getMethodGetAccessoDatiAutenticazione(){
  4595.         return METHOD_GET_ACCESSO_DATI_AUTENTICAZIONE;
  4596.     }
  4597.     public AccessoDatiAutenticazione getAccessoDatiAutenticazione(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4598.        
  4599.         // Se e' attiva una configurazione statica, la utilizzo.
  4600.         if(!this.configurazioneDinamica &&
  4601.             ConfigurazionePdD.accessoDatiAutenticazione!=null) {
  4602.             return ConfigurazionePdD.accessoDatiAutenticazione;
  4603.         }
  4604.        
  4605.         // se e' attiva una cache provo ad utilizzarla
  4606.         String key = null;  
  4607.         if(this.cache!=null){
  4608.             key = getMethodGetAccessoDatiAutenticazione();
  4609.             org.openspcoop2.utils.cache.CacheResponse response =
  4610.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4611.             if(response != null){
  4612.                 if(response.getException()!=null){
  4613.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4614.                         throw (DriverConfigurazioneNotFound) response.getException();
  4615.                     else
  4616.                         throw (DriverConfigurazioneException) response.getException();
  4617.                 }else{
  4618.                     return ((AccessoDatiAutenticazione) response.getObject());
  4619.                 }
  4620.             }
  4621.         }
  4622.            
  4623.         // Algoritmo CACHE
  4624.         AccessoDatiAutenticazione object = null;
  4625.         if(this.cache!=null){
  4626.             object = (AccessoDatiAutenticazione) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_AUTENTICAZIONE,connectionPdD,ConfigurazionePdDType.config);
  4627.         }else{
  4628.             object = (AccessoDatiAutenticazione) this.getObject(METHOD_GET_ACCESSO_DATI_AUTENTICAZIONE,connectionPdD,ConfigurazionePdDType.config);
  4629.         }
  4630.        
  4631.         if(object!=null){
  4632.             // Se e' attiva una configurazione statica, la utilizzo.
  4633.             if(!this.configurazioneDinamica){
  4634.                 ConfigurazionePdD.setAccessoDatiAutenticazione(object);
  4635.             }
  4636.             return object;
  4637.         }
  4638.         else{
  4639.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_AUTENTICAZIONE+"] Configurazione di accesso ai dati di autenticazione non trovata");
  4640.         }
  4641.     }
  4642.    
  4643.    
  4644.     private static final String METHOD_GET_ACCESSO_DATI_GESTIONE_TOKEN = "getAccessoDatiGestioneToken";
  4645.     private String getKeyMethodGetAccessoDatiGestioneToken(){
  4646.         return METHOD_GET_ACCESSO_DATI_GESTIONE_TOKEN;
  4647.     }
  4648.     public AccessoDatiGestioneToken getAccessoDatiGestioneToken(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4649.        
  4650.         // Se e' attiva una configurazione statica, la utilizzo.
  4651.         if(!this.configurazioneDinamica &&
  4652.             ConfigurazionePdD.accessoDatiGestioneToken!=null) {
  4653.             return ConfigurazionePdD.accessoDatiGestioneToken;
  4654.         }
  4655.        
  4656.         // se e' attiva una cache provo ad utilizzarla
  4657.         String key = null;  
  4658.         if(this.cache!=null){
  4659.             key = getKeyMethodGetAccessoDatiGestioneToken();
  4660.             org.openspcoop2.utils.cache.CacheResponse response =
  4661.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4662.             if(response != null){
  4663.                 if(response.getException()!=null){
  4664.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4665.                         throw (DriverConfigurazioneNotFound) response.getException();
  4666.                     else
  4667.                         throw (DriverConfigurazioneException) response.getException();
  4668.                 }else{
  4669.                     return ((AccessoDatiGestioneToken) response.getObject());
  4670.                 }
  4671.             }
  4672.         }
  4673.            
  4674.         // Algoritmo CACHE
  4675.         AccessoDatiGestioneToken object = null;
  4676.         if(this.cache!=null){
  4677.             object = (AccessoDatiGestioneToken) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_GESTIONE_TOKEN,connectionPdD,ConfigurazionePdDType.config);
  4678.         }else{
  4679.             object = (AccessoDatiGestioneToken) this.getObject(METHOD_GET_ACCESSO_DATI_GESTIONE_TOKEN,connectionPdD,ConfigurazionePdDType.config);
  4680.         }
  4681.        
  4682.         if(object!=null){
  4683.             // Se e' attiva una configurazione statica, la utilizzo.
  4684.             if(!this.configurazioneDinamica){
  4685.                 ConfigurazionePdD.setAccessoDatiGestioneToken(object);
  4686.             }
  4687.             return object;
  4688.         }
  4689.         else{
  4690.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_GESTIONE_TOKEN+"] Configurazione di accesso ai dati di gestione token non trovata");
  4691.         }
  4692.     }
  4693.    
  4694.    
  4695.    
  4696.     private static final String METHOD_GET_ACCESSO_DATI_ATTRIBUTE_AUTHORITY = "getAccessoDatiAttributeAuthority";
  4697.     private String getKeyMethodGetAccessoDatiAttributeAuthority(){
  4698.         return METHOD_GET_ACCESSO_DATI_ATTRIBUTE_AUTHORITY;
  4699.     }
  4700.     public AccessoDatiAttributeAuthority getAccessoDatiAttributeAuthority(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4701.        
  4702.         // Se e' attiva una configurazione statica, la utilizzo.
  4703.         if(!this.configurazioneDinamica &&
  4704.             ConfigurazionePdD.accessoDatiAttributeAuthority!=null) {
  4705.             return ConfigurazionePdD.accessoDatiAttributeAuthority;
  4706.         }
  4707.        
  4708.         // se e' attiva una cache provo ad utilizzarla
  4709.         String key = null;  
  4710.         if(this.cache!=null){
  4711.             key = getKeyMethodGetAccessoDatiAttributeAuthority();
  4712.             org.openspcoop2.utils.cache.CacheResponse response =
  4713.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4714.             if(response != null){
  4715.                 if(response.getException()!=null){
  4716.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4717.                         throw (DriverConfigurazioneNotFound) response.getException();
  4718.                     else
  4719.                         throw (DriverConfigurazioneException) response.getException();
  4720.                 }else{
  4721.                     return ((AccessoDatiAttributeAuthority) response.getObject());
  4722.                 }
  4723.             }
  4724.         }
  4725.            
  4726.         // Algoritmo CACHE
  4727.         AccessoDatiAttributeAuthority object = null;
  4728.         if(this.cache!=null){
  4729.             object = (AccessoDatiAttributeAuthority) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_ATTRIBUTE_AUTHORITY,connectionPdD,ConfigurazionePdDType.config);
  4730.         }else{
  4731.             object = (AccessoDatiAttributeAuthority) this.getObject(METHOD_GET_ACCESSO_DATI_ATTRIBUTE_AUTHORITY,connectionPdD,ConfigurazionePdDType.config);
  4732.         }
  4733.        
  4734.         if(object!=null){
  4735.             // Se e' attiva una configurazione statica, la utilizzo.
  4736.             if(!this.configurazioneDinamica){
  4737.                 ConfigurazionePdD.setAccessoDatiAttributeAuthority(object);
  4738.             }
  4739.             return object;
  4740.         }
  4741.         else{
  4742.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_ATTRIBUTE_AUTHORITY+"] Configurazione di accesso ai dati recuperati tramite attribute authority non trovata");
  4743.         }
  4744.     }

  4745.    
  4746.     private static final String METHOD_GET_ACCESSO_DATI_KEYSTORE = "getAccessoDatiKeystore";
  4747.     private String getKeyMethodGetAccessoDatiKeystore(){
  4748.         return METHOD_GET_ACCESSO_DATI_KEYSTORE;
  4749.     }
  4750.     public AccessoDatiKeystore getAccessoDatiKeystore(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4751.        
  4752.         // Se e' attiva una configurazione statica, la utilizzo.
  4753.         if(!this.configurazioneDinamica &&
  4754.             ConfigurazionePdD.accessoDatiKeystore!=null) {
  4755.             return ConfigurazionePdD.accessoDatiKeystore;
  4756.         }
  4757.        
  4758.         // se e' attiva una cache provo ad utilizzarla
  4759.         String key = null;  
  4760.         if(this.cache!=null){
  4761.             key = getKeyMethodGetAccessoDatiKeystore();
  4762.             org.openspcoop2.utils.cache.CacheResponse response =
  4763.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4764.             if(response != null){
  4765.                 if(response.getException()!=null){
  4766.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4767.                         throw (DriverConfigurazioneNotFound) response.getException();
  4768.                     else
  4769.                         throw (DriverConfigurazioneException) response.getException();
  4770.                 }else{
  4771.                     return ((AccessoDatiKeystore) response.getObject());
  4772.                 }
  4773.             }
  4774.         }
  4775.            
  4776.         // Algoritmo CACHE
  4777.         AccessoDatiKeystore object = null;
  4778.         if(this.cache!=null){
  4779.             object = (AccessoDatiKeystore) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_KEYSTORE,connectionPdD,ConfigurazionePdDType.config);
  4780.         }else{
  4781.             object = (AccessoDatiKeystore) this.getObject(METHOD_GET_ACCESSO_DATI_KEYSTORE,connectionPdD,ConfigurazionePdDType.config);
  4782.         }
  4783.        
  4784.         if(object!=null){
  4785.             // Se e' attiva una configurazione statica, la utilizzo.
  4786.             if(!this.configurazioneDinamica){
  4787.                 ConfigurazionePdD.setAccessoDatiKeystore(object);
  4788.             }
  4789.             return object;
  4790.         }
  4791.         else{
  4792.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_KEYSTORE+"] Configurazione di accesso ai dati di gestione keystore non trovata");
  4793.         }
  4794.     }
  4795.    
  4796.    
  4797.     private static final String METHOD_GET_ACCESSO_DATI_RICHIESTE = "getAccessoDatiRichieste";
  4798.     private String getKeyMethodGetAccessoDatiRichieste(){
  4799.         return METHOD_GET_ACCESSO_DATI_RICHIESTE;
  4800.     }
  4801.     public AccessoDatiRichieste getAccessoDatiRichieste(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4802.        
  4803.         // Se e' attiva una configurazione statica, la utilizzo.
  4804.         if(!this.configurazioneDinamica &&
  4805.             ConfigurazionePdD.accessoDatiRichieste!=null) {
  4806.             return ConfigurazionePdD.accessoDatiRichieste;
  4807.         }
  4808.        
  4809.         // se e' attiva una cache provo ad utilizzarla
  4810.         String key = null;  
  4811.         if(this.cache!=null){
  4812.             key = getKeyMethodGetAccessoDatiRichieste();
  4813.             org.openspcoop2.utils.cache.CacheResponse response =
  4814.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4815.             if(response != null){
  4816.                 if(response.getException()!=null){
  4817.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4818.                         throw (DriverConfigurazioneNotFound) response.getException();
  4819.                     else
  4820.                         throw (DriverConfigurazioneException) response.getException();
  4821.                 }else{
  4822.                     return ((AccessoDatiRichieste) response.getObject());
  4823.                 }
  4824.             }
  4825.         }
  4826.            
  4827.         // Algoritmo CACHE
  4828.         AccessoDatiRichieste object = null;
  4829.         if(this.cache!=null){
  4830.             object = (AccessoDatiRichieste) this.getObjectCache(key,METHOD_GET_ACCESSO_DATI_RICHIESTE,connectionPdD,ConfigurazionePdDType.config);
  4831.         }else{
  4832.             object = (AccessoDatiRichieste) this.getObject(METHOD_GET_ACCESSO_DATI_RICHIESTE,connectionPdD,ConfigurazionePdDType.config);
  4833.         }
  4834.        
  4835.         if(object!=null){
  4836.             // Se e' attiva una configurazione statica, la utilizzo.
  4837.             if(!this.configurazioneDinamica){
  4838.                 ConfigurazionePdD.setAccessoDatiRichieste(object);
  4839.             }
  4840.             return object;
  4841.         }
  4842.         else{
  4843.             throw new DriverConfigurazioneNotFound("["+METHOD_GET_ACCESSO_DATI_RICHIESTE+"] Configurazione di accesso ai dati di gestione delle richieste non trovata");
  4844.         }
  4845.     }



  4846.     public GestioneErrore getGestioneErroreComponenteCooperazione(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4847.         return this.getGestioneErrore(connectionPdD,true);
  4848.     }

  4849.     public GestioneErrore getGestioneErroreComponenteIntegrazione(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4850.         return this.getGestioneErrore(connectionPdD,false);
  4851.     }

  4852.     private String _getKey_getGestioneErrore(boolean cooperazione){
  4853.         String key = "getGestioneErrore";
  4854.         if(cooperazione){
  4855.             key = key + "ComponenteCooperazione";
  4856.         }else{
  4857.             key = key + "ComponenteIntegrazione";
  4858.         }
  4859.         return key;
  4860.     }
  4861.     private GestioneErrore getGestioneErrore(Connection connectionPdD,boolean cooperazione) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4862.         // Se e' attiva una configurazione statica, la utilizzo.
  4863.         if(this.configurazioneDinamica==false){
  4864.             if(cooperazione){
  4865.                 if(ConfigurazionePdD.gestioneErroreComponenteCooperazione!=null)
  4866.                     return ConfigurazionePdD.gestioneErroreComponenteCooperazione;
  4867.             }else{
  4868.                 if(ConfigurazionePdD.gestioneErroreComponenteIntegrazione!=null)
  4869.                     return ConfigurazionePdD.gestioneErroreComponenteIntegrazione;
  4870.             }
  4871.         }

  4872.         // se e' attiva una cache provo ad utilizzarla
  4873.         String key = null;  
  4874.         if(this.cache!=null){
  4875.             key = this._getKey_getGestioneErrore(cooperazione);
  4876.             org.openspcoop2.utils.cache.CacheResponse response =
  4877.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4878.             if(response != null){
  4879.                 if(response.getException()!=null){
  4880.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4881.                         throw (DriverConfigurazioneNotFound) response.getException();
  4882.                     else
  4883.                         throw (DriverConfigurazioneException) response.getException();
  4884.                 }else{
  4885.                     return ((GestioneErrore) response.getObject());
  4886.                 }
  4887.             }
  4888.         }

  4889.         // Algoritmo CACHE
  4890.         GestioneErrore ge = null;
  4891.         String nomeMetodo = "getGestioneErrore";
  4892.         if(cooperazione){
  4893.             nomeMetodo = nomeMetodo + "ComponenteCooperazione";
  4894.         }else{
  4895.             nomeMetodo = nomeMetodo + "ComponenteIntegrazione";
  4896.         }
  4897.         if(this.cache!=null){
  4898.             try{
  4899.                 ge = (GestioneErrore) this.getObjectCache(key,nomeMetodo,connectionPdD,ConfigurazionePdDType.config);
  4900.             }catch(DriverConfigurazioneException e){
  4901.                 String erroreCooperazione= "Configurazione, Algoritmo di Cache fallito: Metodo (getGestioneErroreComponenteCooperazione) ha ritornato un valore null";
  4902.                 String erroreIntegrazione= "Configurazione, Algoritmo di Cache fallito: Metodo (getGestioneErroreComponenteIntegrazione) ha ritornato un valore null";
  4903.                 if(e.getMessage()!=null
  4904.                         && !erroreCooperazione.equals(e.getMessage())
  4905.                         && !erroreIntegrazione.equals(e.getMessage())){
  4906.                     throw e;
  4907.                 }
  4908.             }
  4909.         }else{
  4910.             ge = (GestioneErrore) this.getObject(nomeMetodo,connectionPdD,ConfigurazionePdDType.config);
  4911.         }

  4912.         if(ge!=null){
  4913.             // Se e' attiva una configurazione statica, la utilizzo.
  4914.             if(this.configurazioneDinamica==false){
  4915.                 if(cooperazione)
  4916.                     ConfigurazionePdD.gestioneErroreComponenteCooperazione = ge;
  4917.                 else
  4918.                     ConfigurazionePdD.gestioneErroreComponenteIntegrazione = ge;
  4919.             }
  4920.             return ge;
  4921.         }
  4922.         else{
  4923.             throw new DriverConfigurazioneNotFound("[getGestioneErrore] GestioneErrore non trovato");
  4924.         }
  4925.     }


  4926.     private String _getKey_getConfigurazioneGenerale(){
  4927.         return "getConfigurazioneGenerale";
  4928.     }
  4929.     public Configurazione getConfigurazioneGenerale(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4930.         // Se e' attiva una configurazione statica, la utilizzo.
  4931.         if(this.configurazioneDinamica==false){
  4932.             if(ConfigurazionePdD.configurazioneGeneralePdD!=null){
  4933.                 return ConfigurazionePdD.configurazioneGeneralePdD;
  4934.             }
  4935.         }

  4936.         // se e' attiva una cache provo ad utilizzarla
  4937.         String key = null;  
  4938.         if(this.cache!=null){
  4939.             key = this._getKey_getConfigurazioneGenerale();
  4940.             org.openspcoop2.utils.cache.CacheResponse response =
  4941.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4942.             if(response != null){
  4943.                 if(response.getException()!=null){
  4944.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4945.                         throw (DriverConfigurazioneNotFound) response.getException();
  4946.                     else
  4947.                         throw (DriverConfigurazioneException) response.getException();
  4948.                 }else{
  4949.                     return ((Configurazione) response.getObject());
  4950.                 }
  4951.             }
  4952.         }

  4953.         // Algoritmo CACHE
  4954.         Configurazione c = null;
  4955.         if(this.cache!=null){
  4956.             c = (Configurazione) this.getObjectCache(key,"getConfigurazioneGenerale",connectionPdD,ConfigurazionePdDType.config);
  4957.         }else{
  4958.             c = (Configurazione) this.getObject("getConfigurazioneGenerale",connectionPdD,ConfigurazionePdDType.config);
  4959.         }

  4960.         if(c!=null){
  4961.             // Se e' attiva una configurazione statica, la utilizzo.
  4962.             if(this.configurazioneDinamica==false){
  4963.                 ConfigurazionePdD.configurazioneGeneralePdD= c;
  4964.             }
  4965.             return c;
  4966.         }
  4967.         else{
  4968.             throw new DriverConfigurazioneNotFound("[getConfigurazioneGenerale] Configurazione Generale non trovata");
  4969.         }
  4970.     }


  4971.     public StatoServiziPdd getStatoServiziPdD() throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4972.         return this.driverConfigurazionePdD.getStatoServiziPdD();
  4973.     }
  4974.     public void updateStatoServiziPdD(StatoServiziPdd servizi) throws DriverConfigurazioneException{
  4975.         if(this.driverConfigurazionePdD instanceof DriverConfigurazioneDB){
  4976.             ((DriverConfigurazioneDB)this.driverConfigurazionePdD).updateStatoServiziPdD(servizi);
  4977.         }
  4978.     }
  4979.    
  4980.     public List<String> getEncryptedSystemPropertiesPdD() throws DriverConfigurazioneException{
  4981.         return this.driverConfigurazionePdD.getEncryptedSystemPropertiesPdD();
  4982.     }
  4983.     public SystemProperties getSystemPropertiesPdD(boolean forceDisableBYOKUse) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  4984.         if(forceDisableBYOKUse && this.driverConfigurazionePdD instanceof DriverConfigurazioneDB) {
  4985.             return ((DriverConfigurazioneDB)this.driverConfigurazionePdD).getSystemPropertiesPdDWithoutBIOK();
  4986.         }
  4987.         return this.driverConfigurazionePdD.getSystemPropertiesPdD();
  4988.     }
  4989.     public void updateSystemPropertiesPdD(SystemProperties systemProperties) throws DriverConfigurazioneException{
  4990.         if(this.driverConfigurazionePdD instanceof DriverConfigurazioneDB){
  4991.             ((DriverConfigurazioneDB)this.driverConfigurazionePdD).updateSystemPropertiesPdD(systemProperties);
  4992.         }
  4993.     }

  4994.     private String _getKey_getSystemPropertiesPdDCached(){
  4995.         String key = "getSystemPropertiesPdD";
  4996.         return key;
  4997.     }
  4998.     public SystemProperties getSystemPropertiesPdDCached(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  4999.         // se e' attiva una cache provo ad utilizzarla
  5000.         String key = null;  
  5001.         if(this.cache!=null){
  5002.             key = this._getKey_getSystemPropertiesPdDCached();
  5003.             org.openspcoop2.utils.cache.CacheResponse response =
  5004.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5005.             if(response != null){
  5006.                 if(response.getException()!=null){
  5007.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5008.                         throw (DriverConfigurazioneNotFound) response.getException();
  5009.                     else
  5010.                         throw (DriverConfigurazioneException) response.getException();
  5011.                 }else{
  5012.                     return ((SystemProperties) response.getObject());
  5013.                 }
  5014.             }
  5015.         }

  5016.         // Algoritmo CACHE
  5017.         SystemProperties sp = null;
  5018.         if(this.cache!=null){
  5019.             try{
  5020.                 sp = (SystemProperties) this.getObjectCache(key,"getSystemPropertiesPdD",connectionPdD,ConfigurazionePdDType.config);
  5021.             }catch(DriverConfigurazioneException e){
  5022.                 throw e;
  5023.             }
  5024.         }else{
  5025.             sp = (SystemProperties) this.getObject("getSystemPropertiesPdD",connectionPdD,ConfigurazionePdDType.config);
  5026.         }

  5027.         if(sp!=null){
  5028.             return sp;
  5029.         }
  5030.         else{
  5031.             throw new DriverConfigurazioneNotFound("[getSystemPropertiesPdD] GestioneErrore non trovato");
  5032.         }
  5033.     }
  5034.    
  5035.    
  5036.     protected static String _getKey_getGenericProperties(String tipologia, String nome){
  5037.         String key = "getGenericProperties";
  5038.         key = key + "_"+tipologia;
  5039.         key = key + "_"+nome;
  5040.         return key;
  5041.     }
  5042.     public GenericProperties getGenericProperties(Connection connectionPdD,String tipologia, String nome) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5043.         return  getGenericProperties(connectionPdD, false, tipologia, nome);
  5044.     }
  5045.     public GenericProperties getGenericProperties(Connection connectionPdD,boolean forceNoCache, String tipologia, String nome) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5046.         // se e' attiva una cache provo ad utilizzarla
  5047.         String key = null;  
  5048.         if(!forceNoCache && this.cache!=null){
  5049.             key = _getKey_getGenericProperties(tipologia, nome);
  5050.             org.openspcoop2.utils.cache.CacheResponse response =
  5051.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5052.             if(response != null){
  5053.                 if(response.getException()!=null){
  5054.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5055.                         throw (DriverConfigurazioneNotFound) response.getException();
  5056.                     else
  5057.                         throw (DriverConfigurazioneException) response.getException();
  5058.                 }else{
  5059.                     return ((GenericProperties) response.getObject());
  5060.                 }
  5061.             }
  5062.         }

  5063.         // Algoritmo CACHE
  5064.         GenericProperties gp = null;
  5065.         if(!forceNoCache && this.cache!=null){
  5066.             try{
  5067.                 gp = (GenericProperties) this.getObjectCache(key,"getGenericProperties",connectionPdD,ConfigurazionePdDType.config, tipologia, nome);
  5068.             }catch(DriverConfigurazioneException e){
  5069.                 throw e;
  5070.             }
  5071.         }else{
  5072.             gp = (GenericProperties) this.getObject("getGenericProperties",connectionPdD,ConfigurazionePdDType.config, tipologia, nome);
  5073.         }

  5074.         if(gp!=null){
  5075.             return gp;
  5076.         }
  5077.         else{
  5078.             throw new DriverConfigurazioneNotFound("[getGenericProperties] GestioneErrore non trovato");
  5079.         }
  5080.     }
  5081.    
  5082.     protected static String _getKey_getGenericProperties(String tipologia){
  5083.         String key = "getGenericPropertiesList";
  5084.         key = key + "_"+tipologia;
  5085.         return key;
  5086.     }
  5087.     public List<GenericProperties> getGenericProperties(Connection connectionPdD,String tipologia) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5088.         return  getGenericProperties(connectionPdD, false, tipologia);
  5089.     }
  5090.     @SuppressWarnings("unchecked")
  5091.     public List<GenericProperties> getGenericProperties(Connection connectionPdD,boolean forceNoCache, String tipologia) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5092.         // se e' attiva una cache provo ad utilizzarla
  5093.         String key = null;  
  5094.         if(!forceNoCache && this.cache!=null){
  5095.             key = _getKey_getGenericProperties(tipologia);
  5096.             org.openspcoop2.utils.cache.CacheResponse response =
  5097.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5098.             if(response != null){
  5099.                 if(response.getException()!=null){
  5100.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5101.                         throw (DriverConfigurazioneNotFound) response.getException();
  5102.                     else
  5103.                         throw (DriverConfigurazioneException) response.getException();
  5104.                 }else{
  5105.                     return ((List<GenericProperties>) response.getObject());
  5106.                 }
  5107.             }
  5108.         }

  5109.         // Algoritmo CACHE
  5110.         List<GenericProperties> gp = null;
  5111.         if(!forceNoCache && this.cache!=null){
  5112.             try{
  5113.                 gp = (List<GenericProperties>) this.getObjectCache(key,"getGenericProperties",connectionPdD,ConfigurazionePdDType.config, tipologia);
  5114.             }catch(DriverConfigurazioneException e){
  5115.                 throw e;
  5116.             }
  5117.         }else{
  5118.             gp = (List<GenericProperties>) this.getObject("getGenericProperties",connectionPdD,ConfigurazionePdDType.config, tipologia);
  5119.         }

  5120.         if(gp!=null){
  5121.             return gp;
  5122.         }
  5123.         else{
  5124.             throw new DriverConfigurazioneNotFound("[getGenericProperties] GestioneErrore non trovato");
  5125.         }
  5126.     }
  5127.    

  5128.     private String _getKey_getConfigurazioneWithOnlyExtendedInfo(){
  5129.         return "getConfigurazioneWithOnlyExtendedInfo";
  5130.     }
  5131.     public Configurazione getConfigurazioneWithOnlyExtendedInfo(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5132.         // se e' attiva una cache provo ad utilizzarla
  5133.         String key = null;  
  5134.         if(this.cache!=null){
  5135.             key = this._getKey_getConfigurazioneWithOnlyExtendedInfo();
  5136.             org.openspcoop2.utils.cache.CacheResponse response =
  5137.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5138.             if(response != null){
  5139.                 if(response.getException()!=null){
  5140.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5141.                         throw (DriverConfigurazioneNotFound) response.getException();
  5142.                     else
  5143.                         throw (DriverConfigurazioneException) response.getException();
  5144.                 }else{
  5145.                     return ((Configurazione) response.getObject());
  5146.                 }
  5147.             }
  5148.         }

  5149.         // Algoritmo CACHE
  5150.         Configurazione c = null;
  5151.         if(this.cache!=null){
  5152.             c = (Configurazione) this.getObjectCache(key,"getConfigurazioneWithOnlyExtendedInfo",connectionPdD,ConfigurazionePdDType.config);
  5153.         }else{
  5154.             c = (Configurazione) this.getObject("getConfigurazioneWithOnlyExtendedInfo",connectionPdD,ConfigurazionePdDType.config);
  5155.         }

  5156.         if(c!=null){
  5157.             return c;
  5158.         }
  5159.         else{
  5160.             throw new DriverConfigurazioneNotFound("[getConfigurazioneWithOnlyExtendedInfo] Configurazione Generale non trovata");
  5161.         }
  5162.     }

  5163.     public static final String prefixKey_getSingleExtendedInfoConfigurazione = "getSingleExtendedInfoConfigurazione_";

  5164.     public Object getSingleExtendedInfoConfigurazione(String id, Connection connectionPdD) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{

  5165.         // se e' attiva una cache provo ad utilizzarla
  5166.         String key = null;  
  5167.         if(this.cache!=null){
  5168.             key = prefixKey_getSingleExtendedInfoConfigurazione+id;
  5169.             org.openspcoop2.utils.cache.CacheResponse response =
  5170.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5171.             if(response != null){
  5172.                 if(response.getException()!=null){
  5173.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5174.                         throw (DriverConfigurazioneNotFound) response.getException();
  5175.                     else
  5176.                         throw (DriverConfigurazioneException) response.getException();
  5177.                 }else{
  5178.                     return response.getObject();
  5179.                 }
  5180.             }
  5181.         }

  5182.         // Algoritmo CACHE
  5183.         Object c = null;
  5184.         Configurazione configurazioneGenerale = this.getConfigurazioneGenerale(connectionPdD);
  5185.         if(this.cache!=null){
  5186.             c = this.getObjectCache(key,"getConfigurazioneExtended",connectionPdD,ConfigurazionePdDType.config, configurazioneGenerale, id);
  5187.         }else{
  5188.             c = this.getObject("getConfigurazioneExtended",connectionPdD,ConfigurazionePdDType.config, configurazioneGenerale, id);
  5189.         }

  5190.         if(c!=null){
  5191.             return c;
  5192.         }
  5193.         else{
  5194.             throw new DriverConfigurazioneNotFound("[getSingleExtendedInfoConfigurazione] Configurazione Generale non trovata");
  5195.         }

  5196.     }

  5197.     private static org.openspcoop2.utils.Semaphore semaphore_getTemplateTrasformazione = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_TemplateTrasformazioneConfig");
  5198.     protected static String getKey_getTemplate(TemplateSource source, String identificativo){
  5199.         return "configurazioneGW_getTemplate_"+source.name()+"_"+identificativo;
  5200.     }
  5201.    
  5202.     public Template getTemplatePolicyNegoziazioneRequest(Connection connectionPdD, String policyName, byte[] template,
  5203.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5204.         return _getTemplate(connectionPdD, "getTemplatePolicyNegoziazioneRequest", TemplateSource.POLICY_NEGOZIAZIONE_REQUEST, policyName, template,
  5205.                 requestInfo);
  5206.     }
  5207.    
  5208.     public Template getTemplateAttributeAuthorityRequest(Connection connectionPdD, String attributeAuthorityName, byte[] template,
  5209.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5210.         return _getTemplate(connectionPdD, "getTemplateAttributeAuthorityRequest", TemplateSource.ATTRIBUTE_AUTHORITY_REQUEST, attributeAuthorityName, template,
  5211.                 requestInfo);
  5212.     }
  5213.    
  5214.     private Template _getTemplate(Connection connectionPdD, String nomeMetodo, TemplateSource templateSource, String identificativo, byte[] templateBytes,
  5215.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5216.                
  5217.         String key = getKey_getTemplate(templateSource, identificativo);
  5218.            
  5219.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  5220.         if(useRequestInfo) {
  5221.             Object o = requestInfo.getRequestConfig().getTemplate(key);
  5222.             if(o!=null && o instanceof Template) {
  5223.                 return (Template) o;
  5224.             }
  5225.         }
  5226.            
  5227.         Template template = _getTemplate(connectionPdD, nomeMetodo, templateSource, identificativo, templateBytes, key);
  5228.         if(useRequestInfo && requestInfo!=null) {
  5229.             requestInfo.getRequestConfig().addTemplate(key, template,
  5230.                     requestInfo.getIdTransazione());
  5231.         }
  5232.         return template;
  5233.     }
  5234.     private Template _getTemplate(Connection connectionPdD, String nomeMetodo, TemplateSource templateSource, String identificativo, byte[] templateBytes,
  5235.             String key) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5236.        
  5237.         // se e' attiva una cache provo ad utilizzarla
  5238.         if(this.cache!=null) {
  5239.             org.openspcoop2.utils.cache.CacheResponse response =
  5240.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5241.             if(response != null){
  5242.                 if(response.getException()!=null){
  5243.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5244.                         throw (DriverConfigurazioneNotFound) response.getException();
  5245.                     else
  5246.                         throw (DriverConfigurazioneException) response.getException();
  5247.                 }else{
  5248.                     Template template = (Template) response.getObject();
  5249.                     if(template!=null){
  5250.                         return template;
  5251.                     }
  5252.                 }
  5253.             }
  5254.         }

  5255.         Template template = null;
  5256.        
  5257.         SemaphoreLock lock = semaphore_getTemplateTrasformazione.acquireThrowRuntime(nomeMetodo);
  5258.         try {
  5259.            
  5260.             if(this.cache!=null) {
  5261.                 org.openspcoop2.utils.cache.CacheResponse response =
  5262.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5263.                 if(response != null){
  5264.                     if(response.getException()!=null){
  5265.                         if(notFoundClassName.equals(response.getException().getClass().getName()))
  5266.                             throw (DriverConfigurazioneNotFound) response.getException();
  5267.                         else
  5268.                             throw (DriverConfigurazioneException) response.getException();
  5269.                     }else{
  5270.                         template = (Template) response.getObject();
  5271.                         if(template!=null){
  5272.                             return template;
  5273.                         }
  5274.                     }
  5275.                 }
  5276.             }
  5277.            
  5278.             template = new Template(key, templateBytes);
  5279.            
  5280.             // Aggiungo la risposta in cache (se esiste una cache)  
  5281.             // Se ho una eccezione aggiungo in cache solo una not found
  5282.             if( this.cache!=null ){    
  5283.                 this.logInfo("Aggiungo oggetto ["+key+"] in cache");
  5284.                 try{    
  5285.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  5286.                     responseCache.setObject((java.io.Serializable)template);
  5287.                     this.cache.put(key,responseCache);
  5288.                 }catch(UtilsException e){
  5289.                     this.logError("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  5290.                 }
  5291.             }
  5292.            
  5293.         }finally {
  5294.             semaphore_getTemplateTrasformazione.release(lock, nomeMetodo);
  5295.         }

  5296.         return template;

  5297.     }  
  5298.    
  5299.     public Template getTemplateIntegrazione(Connection connectionPdD,File file,
  5300.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5301.         return _getTemplate(connectionPdD, "getTemplateIntegrazione", TemplateSource.INTEGRAZIONE, file,
  5302.                 requestInfo);
  5303.     }
  5304.     private Template _getTemplate(Connection connectionPdD,String nomeMetodo, TemplateSource templateSource, File file,
  5305.             RequestInfo requestInfo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5306.                
  5307.         String key = getKey_getTemplate(templateSource, file.getAbsolutePath());
  5308.                
  5309.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  5310.         if(useRequestInfo) {
  5311.             Object o = requestInfo.getRequestConfig().getTemplate(key);
  5312.             if(o!=null && o instanceof Template) {
  5313.                 return (Template) o;
  5314.             }
  5315.         }
  5316.                
  5317.         Template template = _getTemplate(connectionPdD, nomeMetodo, templateSource, file, key);
  5318.         if(useRequestInfo && requestInfo!=null) {
  5319.             requestInfo.getRequestConfig().addTemplate(key, template,
  5320.                     requestInfo.getIdTransazione());
  5321.         }
  5322.         return template;
  5323.     }
  5324.     private Template _getTemplate(Connection connectionPdD,String nomeMetodo, TemplateSource templateSource, File file,
  5325.             String key) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5326.        
  5327.         // se e' attiva una cache provo ad utilizzarla
  5328.         if(this.cache!=null) {
  5329.             org.openspcoop2.utils.cache.CacheResponse response =
  5330.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5331.             if(response != null){
  5332.                 if(response.getException()!=null){
  5333.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5334.                         throw (DriverConfigurazioneNotFound) response.getException();
  5335.                     else
  5336.                         throw (DriverConfigurazioneException) response.getException();
  5337.                 }else{
  5338.                     Template template = (Template) response.getObject();
  5339.                     if(template!=null){
  5340.                         return template;
  5341.                     }
  5342.                 }
  5343.             }
  5344.         }

  5345.         Template template = null;
  5346.        
  5347.         SemaphoreLock lock = semaphore_getTemplateTrasformazione.acquireThrowRuntime(nomeMetodo);
  5348.         try {
  5349.            
  5350.             if(this.cache!=null) {
  5351.                 org.openspcoop2.utils.cache.CacheResponse response =
  5352.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5353.                 if(response != null){
  5354.                     if(response.getException()!=null){
  5355.                         if(notFoundClassName.equals(response.getException().getClass().getName()))
  5356.                             throw (DriverConfigurazioneNotFound) response.getException();
  5357.                         else
  5358.                             throw (DriverConfigurazioneException) response.getException();
  5359.                     }else{
  5360.                         template = (Template) response.getObject();
  5361.                         if(template!=null){
  5362.                             return template;
  5363.                         }
  5364.                     }
  5365.                 }
  5366.             }
  5367.            
  5368.             ContentFile cf = getContentFileEngine(file);
  5369.             if(cf.isExists()) {
  5370.                 template = new Template(key, cf.getContent());
  5371.             }
  5372.             else {
  5373.                 throw new DriverConfigurazioneException("File '"+file.getAbsolutePath()+"' cannot exists");
  5374.             }
  5375.            
  5376.             // Aggiungo la risposta in cache (se esiste una cache)  
  5377.             // Se ho una eccezione aggiungo in cache solo una not found
  5378.             if( this.cache!=null ){    
  5379.                 this.logInfo("Aggiungo oggetto ["+key+"] in cache");
  5380.                 try{    
  5381.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  5382.                     responseCache.setObject((java.io.Serializable)template);
  5383.                     this.cache.put(key,responseCache);
  5384.                 }catch(UtilsException e){
  5385.                     this.logError("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  5386.                 }
  5387.             }
  5388.            
  5389.         }finally {
  5390.             semaphore_getTemplateTrasformazione.release(lock, nomeMetodo);
  5391.         }

  5392.         return template;

  5393.     }
  5394.    
  5395.    
  5396.    
  5397.    
  5398.     /* ********  R I C E R C A  I D   E L E M E N T I   P R I M I T I V I  ******** */
  5399.    
  5400.     protected static String _toKey_getAllIdPorteDelegate_method(){
  5401.         return "getAllIdPorteDelegate";
  5402.     }
  5403.     @SuppressWarnings("unchecked")
  5404.     public List<IDPortaDelegata> getAllIdPorteDelegate(FiltroRicercaPorteDelegate filtroRicerca,Connection connectionPdD) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  5405.         return (List<IDPortaDelegata>) _getAllIdEngine(connectionPdD, filtroRicerca, _toKey_getAllIdPorteDelegate_method());
  5406.     }
  5407.    
  5408.     protected static String _toKey_getAllIdPorteApplicative_method(){
  5409.         return "getAllIdPorteApplicative";
  5410.     }
  5411.     @SuppressWarnings("unchecked")
  5412.     public List<IDPortaApplicativa> getAllIdPorteApplicative(FiltroRicercaPorteApplicative filtroRicerca,Connection connectionPdD) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  5413.         return (List<IDPortaApplicativa>) _getAllIdEngine(connectionPdD, filtroRicerca, _toKey_getAllIdPorteApplicative_method());
  5414.     }
  5415.    
  5416.     protected static String _toKey_getAllIdServiziApplicativi_method(){
  5417.         return "getAllIdServiziApplicativi";
  5418.     }
  5419.     @SuppressWarnings("unchecked")
  5420.     public List<IDServizioApplicativo> getAllIdServiziApplicativi(FiltroRicercaServiziApplicativi filtroRicerca,Connection connectionPdD) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  5421.         return (List<IDServizioApplicativo>) _getAllIdEngine(connectionPdD, filtroRicerca, _toKey_getAllIdServiziApplicativi_method());
  5422.     }
  5423.    
  5424.     private List<?> _getAllIdEngine(Connection connectionPdD,Object filtroRicerca,String nomeMetodo) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  5425.        
  5426.         // Raccolta dati
  5427.         if(filtroRicerca == null)
  5428.             throw new DriverConfigurazioneException("["+nomeMetodo+"]: Parametro non definito");    

  5429.         // se e' attiva una cache provo ad utilizzarla
  5430.         String key = null;  
  5431.         if(this.cache!=null){
  5432.             key = nomeMetodo+"_" + filtroRicerca.toString();  
  5433.             org.openspcoop2.utils.cache.CacheResponse response =
  5434.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5435.             if(response != null){
  5436.                 if(response.getException()!=null){
  5437.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5438.                         throw (DriverConfigurazioneNotFound) response.getException();
  5439.                     else
  5440.                         throw (DriverConfigurazioneException) response.getException();
  5441.                 }else{
  5442.                     return ((List<?>) response.getObject());
  5443.                 }
  5444.             }
  5445.         }

  5446.         // Algoritmo CACHE
  5447.         List<?> list = null;
  5448.         if(this.cache!=null){
  5449.             list = (List<?>) this.getObjectCache(key,nomeMetodo,connectionPdD,ConfigurazionePdDType.config,filtroRicerca);
  5450.         }else{
  5451.             list = (List<?>) this.getObject(nomeMetodo,connectionPdD,ConfigurazionePdDType.config,filtroRicerca);
  5452.         }

  5453.         if(list!=null)
  5454.             return list;
  5455.         else
  5456.             throw new DriverConfigurazioneException("["+nomeMetodo+"] Elementi non trovati");
  5457.     }
  5458.    
  5459.    
  5460.    
  5461.    
  5462.    
  5463.    
  5464.     /* ******** CONTROLLO TRAFFICO ******** */
  5465.    
  5466.     private String _getKey_ConfigurazioneControlloTraffico(){
  5467.         return "ConfigurazioneControlloTraffico";
  5468.     }
  5469.     public ConfigurazioneGenerale getConfigurazioneControlloTraffico(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5470.         // se e' attiva una cache provo ad utilizzarla
  5471.         String key = null;  
  5472.         if(this.cache!=null){
  5473.             key = this._getKey_ConfigurazioneControlloTraffico();
  5474.             org.openspcoop2.utils.cache.CacheResponse response =
  5475.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5476.             if(response != null){
  5477.                 if(response.getException()!=null){
  5478.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5479.                         throw (DriverConfigurazioneNotFound) response.getException();
  5480.                     else
  5481.                         throw (DriverConfigurazioneException) response.getException();
  5482.                 }else{
  5483.                     return ((ConfigurazioneGenerale) response.getObject());
  5484.                 }
  5485.             }
  5486.         }

  5487.         // Algoritmo CACHE
  5488.         ConfigurazioneGenerale conf = null;
  5489.         if(this.cache!=null){
  5490.             conf = (ConfigurazioneGenerale) this.getObjectCache(key,"getConfigurazioneControlloTraffico",connectionPdD, ConfigurazionePdDType.controlloTraffico);
  5491.         }else{
  5492.             conf = (ConfigurazioneGenerale) this.getObject("getConfigurazioneControlloTraffico",connectionPdD, ConfigurazionePdDType.controlloTraffico);
  5493.         }

  5494.         if(conf!=null)
  5495.             return conf;
  5496.         else
  5497.             throw new DriverConfigurazioneNotFound("[getConfigurazioneControlloTraffico] Configurazione non trovata");
  5498.     }
  5499.    
  5500.    
  5501.     private String _getKey_getConfigurazionePolicyRateLimitingGlobali(){
  5502.         return "ConfigurazionePolicyRateLimitingGlobali";
  5503.     }
  5504.     public PolicyConfiguration getConfigurazionePolicyRateLimitingGlobali(Connection connectionPdD) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5505.         // se e' attiva una cache provo ad utilizzarla
  5506.         String key = null;  
  5507.         if(this.cache!=null){
  5508.             key = this._getKey_getConfigurazionePolicyRateLimitingGlobali();
  5509.             org.openspcoop2.utils.cache.CacheResponse response =
  5510.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5511.             if(response != null){
  5512.                 if(response.getException()!=null){
  5513.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5514.                         throw (DriverConfigurazioneNotFound) response.getException();
  5515.                     else
  5516.                         throw (DriverConfigurazioneException) response.getException();
  5517.                 }else{
  5518.                     return ((PolicyConfiguration) response.getObject());
  5519.                 }
  5520.             }
  5521.         }

  5522.         // Algoritmo CACHE
  5523.         PolicyConfiguration c = null;
  5524.         if(this.cache!=null){
  5525.             c = (PolicyConfiguration) this.getObjectCache(key,"getConfigurazionePolicyRateLimitingGlobali",connectionPdD,ConfigurazionePdDType.controlloTraffico);
  5526.         }else{
  5527.             c = (PolicyConfiguration) this.getObject("getConfigurazionePolicyRateLimitingGlobali",connectionPdD,ConfigurazionePdDType.controlloTraffico);
  5528.         }

  5529.         if(c!=null){
  5530.             return c;
  5531.         }
  5532.         else{
  5533.             throw new DriverConfigurazioneNotFound("[getConfigurazionePolicyRateLimitingGlobali] Configurazione Generale non trovata");
  5534.         }
  5535.     }
  5536.    
  5537.     private static final String METHOD_ELENCO_ID_POLICY_ATTIVE_API = "getElencoIdPolicyAttiveAPI";
  5538.     public static String getKeyMethodElencoIdPolicyAttiveAPI(TipoPdD tipoPdD, String nomePorta){ // usato anche per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5539.         return METHOD_ELENCO_ID_POLICY_ATTIVE_API+"_"+tipoPdD.getTipo()+"_"+nomePorta;
  5540.     }
  5541.     private static final String METHOD_ELENCO_ID_POLICY_ATTIVE_GLOBALI = "getElencoIdPolicyAttiveGlobali";
  5542.     public static String getKeyMethodElencoIdPolicyAttiveGlobali(){ // usato anche per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5543.         return METHOD_ELENCO_ID_POLICY_ATTIVE_GLOBALI;
  5544.     }
  5545.     private static final String SUFFIX_METHOD_DIMENSIONE_MESSAGGIO = "DimensioneMessaggio";
  5546.     private static final String METHOD_ELENCO_ID_POLICY_ATTIVE_API_DIMENSIONE_MESSAGGIO = METHOD_ELENCO_ID_POLICY_ATTIVE_API+SUFFIX_METHOD_DIMENSIONE_MESSAGGIO;
  5547.     public static String getKeyMethodElencoIdPolicyAttiveAPIDimensioneMessaggio(TipoPdD tipoPdD, String nomePorta){ // usato anche per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5548.         return METHOD_ELENCO_ID_POLICY_ATTIVE_API_DIMENSIONE_MESSAGGIO+"_"+tipoPdD.getTipo()+"_"+nomePorta;
  5549.     }
  5550.     private static final String METHOD_ELENCO_ID_POLICY_ATTIVE_GLOBALI_DIMENSIONE_MESSAGGIO = METHOD_ELENCO_ID_POLICY_ATTIVE_GLOBALI+SUFFIX_METHOD_DIMENSIONE_MESSAGGIO;
  5551.     public static String getKeyMethodElencoIdPolicyAttiveGlobaliDimensioneMessaggio(){ // usato anche per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5552.         return METHOD_ELENCO_ID_POLICY_ATTIVE_GLOBALI_DIMENSIONE_MESSAGGIO;
  5553.     }
  5554.     public Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> getElencoIdPolicyAttiveAPI(Connection connectionPdD, boolean useCache, TipoPdD tipoPdD, String nomePorta) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5555.         return this._getElencoIdPolicyAttive(connectionPdD, useCache, tipoPdD, nomePorta, true,
  5556.                 false);
  5557.     }
  5558.     public Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> getElencoIdPolicyAttiveGlobali(Connection connectionPdD, boolean useCache) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5559.         return this._getElencoIdPolicyAttive(connectionPdD, useCache, null, null, false,
  5560.                 false);
  5561.     }
  5562.     public Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> getElencoIdPolicyAttiveAPIDimensioneMessaggio(Connection connectionPdD, boolean useCache, TipoPdD tipoPdD, String nomePorta) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5563.         return this._getElencoIdPolicyAttive(connectionPdD, useCache, tipoPdD, nomePorta, true,
  5564.                 true);
  5565.     }
  5566.     public Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> getElencoIdPolicyAttiveGlobaliDimensioneMessaggio(Connection connectionPdD, boolean useCache) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  5567.         return this._getElencoIdPolicyAttive(connectionPdD, useCache, null, null, false,
  5568.                 true);
  5569.     }
  5570.     @SuppressWarnings("unchecked")
  5571.     private Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> _getElencoIdPolicyAttive(Connection connectionPdD, boolean useCache,
  5572.             TipoPdD tipoPdD, String nomePorta, boolean api,
  5573.             boolean policyDimensioneMessaggio) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5574.         String prefix = "";
  5575.         if(policyDimensioneMessaggio) {
  5576.             prefix = " [DimensioneMessaggio]";
  5577.         }
  5578.        
  5579.         if(api) {
  5580.             if(tipoPdD==null) {
  5581.                 throw new DriverConfigurazioneException("Tipo PdD non fornito; richiesto per una policy API"+prefix);
  5582.             }
  5583.             if(nomePorta==null) {
  5584.                 throw new DriverConfigurazioneException("Nome Porta non fornito; richiesto per una policy API"+prefix);
  5585.             }
  5586.         }
  5587.        
  5588.         // se e' attiva una cache provo ad utilizzarla
  5589.         String key = null;  
  5590.         if(this.cache!=null && useCache){
  5591.             if(api) {
  5592.                 if(policyDimensioneMessaggio) {
  5593.                     key = getKeyMethodElencoIdPolicyAttiveAPIDimensioneMessaggio(tipoPdD, nomePorta);
  5594.                 }
  5595.                 else {
  5596.                     key = getKeyMethodElencoIdPolicyAttiveAPI(tipoPdD, nomePorta);
  5597.                 }
  5598.             }
  5599.             else {
  5600.                 if(policyDimensioneMessaggio) {
  5601.                     key = getKeyMethodElencoIdPolicyAttiveGlobaliDimensioneMessaggio();
  5602.                 }
  5603.                 else {
  5604.                     key = getKeyMethodElencoIdPolicyAttiveGlobali();
  5605.                 }
  5606.             }
  5607.             org.openspcoop2.utils.cache.CacheResponse response =
  5608.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5609.             if(response != null){
  5610.                 if(response.getException()!=null){
  5611.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5612.                         throw (DriverConfigurazioneNotFound) response.getException();
  5613.                     else
  5614.                         throw (DriverConfigurazioneException) response.getException();
  5615.                 }else{
  5616.                     return ((Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive>) response.getObject());
  5617.                 }
  5618.             }
  5619.         }

  5620.         // Algoritmo CACHE
  5621.         String nomeMetodo = api? METHOD_ELENCO_ID_POLICY_ATTIVE_API : METHOD_ELENCO_ID_POLICY_ATTIVE_GLOBALI;
  5622.         if(policyDimensioneMessaggio) {
  5623.             nomeMetodo = nomeMetodo + SUFFIX_METHOD_DIMENSIONE_MESSAGGIO;
  5624.         }
  5625.         Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive> elenco = null;
  5626.         if(this.cache!=null  && useCache){
  5627.             if(api) {
  5628.                 elenco = (Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive>) this.getObjectCache(key,nomeMetodo,connectionPdD, ConfigurazionePdDType.controlloTraffico, tipoPdD, nomePorta);
  5629.             }
  5630.             else {
  5631.                 elenco = (Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive>) this.getObjectCache(key,nomeMetodo,connectionPdD, ConfigurazionePdDType.controlloTraffico);
  5632.             }
  5633.         }else{
  5634.             if(api) {
  5635.                 elenco = (Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive>) this.getObject(nomeMetodo,connectionPdD, ConfigurazionePdDType.controlloTraffico, tipoPdD, nomePorta);
  5636.             }
  5637.             else {
  5638.                 elenco = (Map<TipoRisorsaPolicyAttiva, ElencoIdPolicyAttive>) this.getObject(nomeMetodo,connectionPdD, ConfigurazionePdDType.controlloTraffico);
  5639.             }
  5640.         }

  5641.         if(elenco!=null)
  5642.             return elenco;
  5643.         else
  5644.             throw new DriverConfigurazioneNotFound("["+nomeMetodo+"] Policy non trovate");
  5645.     }
  5646.    
  5647.    
  5648.     protected static String _toKey_AttivazionePolicyPrefix() {
  5649.         return "AttivazionePolicy_";
  5650.     }
  5651.     public static String _getKey_AttivazionePolicy(String id){ // usato anche per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5652.         return _toKey_AttivazionePolicyPrefix()+id;
  5653.     }
  5654.     public AttivazionePolicy getAttivazionePolicy(Connection connectionPdD, boolean useCache, String id) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5655.         // se e' attiva una cache provo ad utilizzarla
  5656.         String key = null;  
  5657.         if(this.cache!=null && useCache){
  5658.             key = _getKey_AttivazionePolicy(id);
  5659.             org.openspcoop2.utils.cache.CacheResponse response =
  5660.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5661.             if(response != null){
  5662.                 if(response.getException()!=null){
  5663.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5664.                         throw (DriverConfigurazioneNotFound) response.getException();
  5665.                     else
  5666.                         throw (DriverConfigurazioneException) response.getException();
  5667.                 }else{
  5668.                     return ((AttivazionePolicy) response.getObject());
  5669.                 }
  5670.             }
  5671.         }

  5672.         // Algoritmo CACHE
  5673.         AttivazionePolicy policy = null;
  5674.         if(this.cache!=null  && useCache){
  5675.             policy = (AttivazionePolicy) this.getObjectCache(key,"getAttivazionePolicy",connectionPdD, ConfigurazionePdDType.controlloTraffico, id);
  5676.         }else{
  5677.             policy = (AttivazionePolicy) this.getObject("getAttivazionePolicy",connectionPdD, ConfigurazionePdDType.controlloTraffico, id);
  5678.         }

  5679.         if(policy!=null)
  5680.             return policy;
  5681.         else
  5682.             throw new DriverConfigurazioneNotFound("[getAttivazionePolicy] Policy non trovata");
  5683.     }
  5684.    
  5685.    
  5686.     public static String _getKey_ElencoIdPolicy(){ // utilizzabile per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5687.         return "ElencoIdPolicy";
  5688.     }
  5689.     public ElencoIdPolicy getElencoIdPolicy(Connection connectionPdD, boolean useCache) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5690.         // se e' attiva una cache provo ad utilizzarla
  5691.         String key = null;  
  5692.         if(this.cache!=null && useCache){
  5693.             key = _getKey_ElencoIdPolicy();
  5694.             org.openspcoop2.utils.cache.CacheResponse response =
  5695.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5696.             if(response != null){
  5697.                 if(response.getException()!=null){
  5698.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5699.                         throw (DriverConfigurazioneNotFound) response.getException();
  5700.                     else
  5701.                         throw (DriverConfigurazioneException) response.getException();
  5702.                 }else{
  5703.                     return ((ElencoIdPolicy) response.getObject());
  5704.                 }
  5705.             }
  5706.         }

  5707.         // Algoritmo CACHE
  5708.         ElencoIdPolicy elenco = null;
  5709.         if(this.cache!=null  && useCache){
  5710.             elenco = (ElencoIdPolicy) this.getObjectCache(key,"getElencoIdPolicy",connectionPdD, ConfigurazionePdDType.controlloTraffico);
  5711.         }else{
  5712.             elenco = (ElencoIdPolicy) this.getObject("getElencoIdPolicy",connectionPdD, ConfigurazionePdDType.controlloTraffico);
  5713.         }

  5714.         if(elenco!=null)
  5715.             return elenco;
  5716.         else
  5717.             throw new DriverConfigurazioneNotFound("[getElencoIdPolicy] Policy non trovate");
  5718.     }
  5719.    
  5720.    
  5721.     public static String _getKey_ConfigurazionePolicy(String id){ // utilizzabile per resettare la cache puntualmente via jmx, tramite la govwayConsole
  5722.         return "ConfigurazionePolicy_"+id;
  5723.     }
  5724.     public ConfigurazionePolicy getConfigurazionePolicy(Connection connectionPdD, boolean useCache, String id) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5725.         // se e' attiva una cache provo ad utilizzarla
  5726.         String key = null;  
  5727.         if(this.cache!=null && useCache){
  5728.             key = _getKey_AttivazionePolicy(id);
  5729.             org.openspcoop2.utils.cache.CacheResponse response =
  5730.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5731.             if(response != null){
  5732.                 if(response.getException()!=null){
  5733.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5734.                         throw (DriverConfigurazioneNotFound) response.getException();
  5735.                     else
  5736.                         throw (DriverConfigurazioneException) response.getException();
  5737.                 }else{
  5738.                     return ((ConfigurazionePolicy) response.getObject());
  5739.                 }
  5740.             }
  5741.         }

  5742.         // Algoritmo CACHE
  5743.         ConfigurazionePolicy policy = null;
  5744.         if(this.cache!=null  && useCache){
  5745.             policy = (ConfigurazionePolicy) this.getObjectCache(key,"getConfigurazionePolicy",connectionPdD, ConfigurazionePdDType.controlloTraffico, id);
  5746.         }else{
  5747.             policy = (ConfigurazionePolicy) this.getObject("getConfigurazionePolicy",connectionPdD, ConfigurazionePdDType.controlloTraffico, id);
  5748.         }

  5749.         if(policy!=null)
  5750.             return policy;
  5751.         else
  5752.             throw new DriverConfigurazioneNotFound("[getConfigurazionePolicy] Policy non trovata");
  5753.     }
  5754.    
  5755.    
  5756.    
  5757.    
  5758.    
  5759.    
  5760.     /* ******** PLUGINS ******** */
  5761.    
  5762.     public IRegistroPluginsReader getRegistroPluginsReader() {
  5763.         return this.configurazionePdD_registroPlugins;
  5764.     }
  5765.    
  5766.     public static String _getKey_PluginClassName(String tipoPlugin, String tipo){
  5767.         return "PluginClassName_"+tipoPlugin+"#"+tipo;
  5768.     }
  5769.     public String getPluginClassName(Connection connectionPdD, String tipoPlugin, String tipo) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5770.         // se e' attiva una cache provo ad utilizzarla
  5771.         String key = null;  
  5772.         if(this.cache!=null){
  5773.             key = _getKey_PluginClassName(tipoPlugin, tipo);
  5774.             org.openspcoop2.utils.cache.CacheResponse response =
  5775.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5776.             if(response != null){
  5777.                 if(response.getException()!=null){
  5778.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5779.                         throw (DriverConfigurazioneNotFound) response.getException();
  5780.                     else
  5781.                         throw (DriverConfigurazioneException) response.getException();
  5782.                 }else{
  5783.                     return ((String) response.getObject());
  5784.                 }
  5785.             }
  5786.         }

  5787.         // Algoritmo CACHE
  5788.         String className = null;
  5789.         if(this.cache!=null){
  5790.             className = (String) this.getObjectCache(key,"getPluginClassName",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, tipo);
  5791.         }else{
  5792.             className = (String) this.getObject("getPluginClassName",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, tipo);
  5793.         }

  5794.         if(className!=null)
  5795.             return className;
  5796.         else
  5797.             throw new DriverConfigurazioneNotFound("[getPluginClassName] plugin non trovato");
  5798.     }
  5799.    
  5800.    
  5801.     public static String _getKey_PluginClassNameByFilter(String tipoPlugin, String tipo, NameValue ... filtri){
  5802.         StringBuilder sb = new StringBuilder();
  5803.         sb.append("PluginClassNameByFilter_"+tipoPlugin+"#"+tipo);
  5804.        
  5805.         if(filtri!=null && filtri.length>0) {
  5806.             for (int i = 0; i < filtri.length; i++) {
  5807.                 NameValue filtro = filtri[i];
  5808.                 sb.append(".F").append(i).append("_").append(filtro.getName()).append("=").append(filtro.getValue());
  5809.             }
  5810.         }
  5811.        
  5812.         return sb.toString();
  5813.     }
  5814.     public String getPluginClassNameByFilter(Connection connectionPdD, String tipoPlugin, String tipo, NameValue ... filtri) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5815.         // se e' attiva una cache provo ad utilizzarla
  5816.         String key = null;  
  5817.         if(this.cache!=null){
  5818.             key = _getKey_PluginClassNameByFilter(tipoPlugin, tipo, filtri);
  5819.             org.openspcoop2.utils.cache.CacheResponse response =
  5820.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5821.             if(response != null){
  5822.                 if(response.getException()!=null){
  5823.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5824.                         throw (DriverConfigurazioneNotFound) response.getException();
  5825.                     else
  5826.                         throw (DriverConfigurazioneException) response.getException();
  5827.                 }else{
  5828.                     return ((String) response.getObject());
  5829.                 }
  5830.             }
  5831.         }

  5832.         // Algoritmo CACHE
  5833.         String className = null;
  5834.         if(this.cache!=null){
  5835.             className = (String) this.getObjectCache(key,"getPluginClassNameByFilter",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, tipo, filtri);
  5836.         }else{
  5837.             className = (String) this.getObject("getPluginClassNameByFilter",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, tipo, filtri);
  5838.         }

  5839.         if(className!=null)
  5840.             return className;
  5841.         else
  5842.             throw new DriverConfigurazioneNotFound("[getPluginClassNameByFilter] plugin non trovato");
  5843.     }
  5844.    
  5845.     public static String _getKey_PluginTipo(String tipoPlugin, String className){
  5846.         return "PluginTipo_"+tipoPlugin+"#"+className;
  5847.     }
  5848.     public String getPluginTipo(Connection connectionPdD, String tipoPlugin, String className) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5849.         // se e' attiva una cache provo ad utilizzarla
  5850.         String key = null;  
  5851.         if(this.cache!=null){
  5852.             key = _getKey_PluginTipo(tipoPlugin, className);
  5853.             org.openspcoop2.utils.cache.CacheResponse response =
  5854.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5855.             if(response != null){
  5856.                 if(response.getException()!=null){
  5857.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5858.                         throw (DriverConfigurazioneNotFound) response.getException();
  5859.                     else
  5860.                         throw (DriverConfigurazioneException) response.getException();
  5861.                 }else{
  5862.                     return ((String) response.getObject());
  5863.                 }
  5864.             }
  5865.         }

  5866.         // Algoritmo CACHE
  5867.         String tipo = null;
  5868.         if(this.cache!=null){
  5869.             tipo = (String) this.getObjectCache(key,"getPluginTipo",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, className);
  5870.         }else{
  5871.             tipo = (String) this.getObject("getPluginTipo",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, className);
  5872.         }

  5873.         if(tipo!=null)
  5874.             return tipo;
  5875.         else
  5876.             throw new DriverConfigurazioneNotFound("[getPluginTipo] plugin non trovato");
  5877.     }
  5878.    
  5879.    
  5880.     public static String _getKey_PluginTipoByFilter(String tipoPlugin, String className, NameValue ... filtri){
  5881.         StringBuilder sb = new StringBuilder();
  5882.         sb.append("PluginTipoByFilter_"+tipoPlugin+"#"+className);
  5883.        
  5884.         if(filtri!=null && filtri.length>0) {
  5885.             for (int i = 0; i < filtri.length; i++) {
  5886.                 NameValue filtro = filtri[i];
  5887.                 sb.append(".F").append(i).append("_").append(filtro.getName()).append("=").append(filtro.getValue());
  5888.             }
  5889.         }
  5890.        
  5891.         return sb.toString();
  5892.     }
  5893.     public String getPluginTipoByFilter(Connection connectionPdD, String tipoPlugin, String className, NameValue ... filtri) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{

  5894.         // se e' attiva una cache provo ad utilizzarla
  5895.         String key = null;  
  5896.         if(this.cache!=null){
  5897.             key = _getKey_PluginTipoByFilter(tipoPlugin, className, filtri);
  5898.             org.openspcoop2.utils.cache.CacheResponse response =
  5899.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5900.             if(response != null){
  5901.                 if(response.getException()!=null){
  5902.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5903.                         throw (DriverConfigurazioneNotFound) response.getException();
  5904.                     else
  5905.                         throw (DriverConfigurazioneException) response.getException();
  5906.                 }else{
  5907.                     return ((String) response.getObject());
  5908.                 }
  5909.             }
  5910.         }

  5911.         // Algoritmo CACHE
  5912.         String tipo = null;
  5913.         if(this.cache!=null){
  5914.             tipo = (String) this.getObjectCache(key,"getPluginTipoByFilter",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, className, filtri);
  5915.         }else{
  5916.             tipo = (String) this.getObject("getPluginTipoByFilter",connectionPdD, ConfigurazionePdDType.plugins, tipoPlugin, className, filtri);
  5917.         }

  5918.         if(tipo!=null)
  5919.             return tipo;
  5920.         else
  5921.             throw new DriverConfigurazioneNotFound("[getPluginTipoByFilter] plugin non trovato");
  5922.     }
  5923.    
  5924.    
  5925.    
  5926.    
  5927.    
  5928.     /* ******** ALLARMI ******** */
  5929.    
  5930.     private String _getKey_getAllarme(String nomeAllarme){
  5931.         return "allarme_"+nomeAllarme;
  5932.     }
  5933.     public Allarme getAllarme(Connection connectionPdD, String nomeAllarme, boolean searchInCache) throws DriverConfigurazioneException,DriverConfigurazioneNotFound {
  5934.    
  5935.         if(nomeAllarme==null) {
  5936.             throw new DriverConfigurazioneException("Nome allarme non fornito");
  5937.         }
  5938.        
  5939.         // se e' attiva una cache provo ad utilizzarla
  5940.         String key = null;  
  5941.         if(searchInCache && this.cache!=null){
  5942.             key = this._getKey_getAllarme(nomeAllarme);
  5943.             org.openspcoop2.utils.cache.CacheResponse response =
  5944.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5945.             if(response != null){
  5946.                 if(response.getException()!=null){
  5947.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5948.                         throw (DriverConfigurazioneNotFound) response.getException();
  5949.                     else
  5950.                         throw (DriverConfigurazioneException) response.getException();
  5951.                 }else{
  5952.                     return (Allarme) response.getObject();
  5953.                 }
  5954.             }
  5955.         }

  5956.         // Algoritmo CACHE
  5957.         Allarme allarme = null;
  5958.         if(searchInCache && this.cache!=null){
  5959.             allarme = (Allarme) this.getObjectCache(key,"getAllarme",connectionPdD, ConfigurazionePdDType.allarmi, nomeAllarme);
  5960.         }else{
  5961.             allarme = (Allarme) this.getObject("getAllarme",connectionPdD, ConfigurazionePdDType.allarmi, nomeAllarme);
  5962.         }

  5963.         if(allarme!=null)
  5964.             return allarme;
  5965.         else
  5966.             throw new DriverConfigurazioneNotFound("[getAllarme] Allarme '"+nomeAllarme+"' non trovato");
  5967.        
  5968.     }
  5969.    
  5970.     private String _getKey_searchAllarmi(FiltroRicercaAllarmi filtroRicerca){
  5971.         return "searchAllarmi_"+filtroRicerca.toString("_");
  5972.     }
  5973.     @SuppressWarnings("unchecked")
  5974.     public List<Allarme> searchAllarmi(Connection connectionPdD, FiltroRicercaAllarmi filtroRicerca, boolean searchInCache) throws DriverConfigurazioneException,DriverConfigurazioneNotFound {
  5975.    
  5976.         if(filtroRicerca==null) {
  5977.             throw new DriverConfigurazioneException("Filtro ricerca non fornito");
  5978.         }
  5979.        
  5980.         // se e' attiva una cache provo ad utilizzarla
  5981.         String key = null;  
  5982.         if(searchInCache && this.cache!=null){
  5983.             key = this._getKey_searchAllarmi(filtroRicerca);
  5984.             org.openspcoop2.utils.cache.CacheResponse response =
  5985.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  5986.             if(response != null){
  5987.                 if(response.getException()!=null){
  5988.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  5989.                         throw (DriverConfigurazioneNotFound) response.getException();
  5990.                     else
  5991.                         throw (DriverConfigurazioneException) response.getException();
  5992.                 }else{
  5993.                     return ((List<Allarme>) response.getObject());
  5994.                 }
  5995.             }
  5996.         }

  5997.         // Algoritmo CACHE
  5998.         List<Allarme> list = null;
  5999.         if(searchInCache && this.cache!=null){
  6000.             list = (List<Allarme>) this.getObjectCache(key,"searchAllarmi",connectionPdD, ConfigurazionePdDType.allarmi, filtroRicerca);
  6001.         }else{
  6002.             list = (List<Allarme>) this.getObject("searchAllarmi",connectionPdD, ConfigurazionePdDType.allarmi, filtroRicerca);
  6003.         }

  6004.         if(list!=null && !list.isEmpty())
  6005.             return list;
  6006.         else
  6007.             throw new DriverConfigurazioneNotFound("[searchAllarmi] Allarmi non trovati");
  6008.        
  6009.     }
  6010.    
  6011.     @SuppressWarnings("unchecked")
  6012.     public List<IAlarm> instanceAllarmi(Connection connectionPdD, List<Allarme> listAllarmi) throws DriverConfigurazioneException {
  6013.         try {
  6014.             return (List<IAlarm>) this.getObject("instanceAllarmi",connectionPdD, ConfigurazionePdDType.allarmi, listAllarmi);
  6015.         }catch(DriverConfigurazioneNotFound e) {
  6016.             throw new DriverConfigurazioneException(e.getMessage(), e);
  6017.         }
  6018.     }
  6019.    
  6020.     public void changeStatus(Connection connectionPdD, IAlarm alarm, AlarmStatus nuovoStatoAllarme) throws DriverConfigurazioneException {
  6021.         try {
  6022.             this.getObject("changeStatus",connectionPdD, ConfigurazionePdDType.allarmi, alarm, nuovoStatoAllarme);
  6023.         }catch(DriverConfigurazioneNotFound e) {
  6024.             throw new DriverConfigurazioneException(e.getMessage(), e);
  6025.         }
  6026.     }
  6027.    
  6028.    
  6029.    
  6030.    
  6031.     /* ******** MAPPING ******** */
  6032.    
  6033.     public static String _getKey_MappingErogazionePortaApplicativaList(IDServizio idServizio, boolean includiAzione){
  6034.         return "MappingErogazionePA_"+idServizio.toString(includiAzione);
  6035.     }
  6036.     @SuppressWarnings("unchecked")
  6037.     public List<MappingErogazionePortaApplicativa> getMappingErogazionePortaApplicativaList(IDServizio idServizio,Connection connectionPdD) throws DriverConfigurazioneException{
  6038.        
  6039.         // se e' attiva una cache provo ad utilizzarla
  6040.         String key = null;  
  6041.         if(this.cache!=null){
  6042.             key = _getKey_MappingErogazionePortaApplicativaList(idServizio, true);
  6043.             org.openspcoop2.utils.cache.CacheResponse response =
  6044.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  6045.             if(response != null){
  6046.                 if(response.getException()!=null){
  6047.                     throw (DriverConfigurazioneException) response.getException();
  6048.                 }else{
  6049.                     return ((List<MappingErogazionePortaApplicativa>) response.getObject());
  6050.                 }
  6051.             }
  6052.         }

  6053.         // Algoritmo CACHE
  6054.         List<MappingErogazionePortaApplicativa> list = null;
  6055.         if(this.cache!=null){
  6056.             list = this.getMappingErogazionePortaApplicativaListCache(key, connectionPdD, idServizio);
  6057.         }else{
  6058.             list = _getMappingErogazionePortaApplicativaList(idServizio, connectionPdD);
  6059.         }

  6060.         return list;
  6061.     }
  6062.     private static org.openspcoop2.utils.Semaphore semaphore_getMappingErogazionePortaApplicativaListCache = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_MappingErogazionePortaApplicativa");
  6063.     @SuppressWarnings("unchecked")
  6064.     public List<MappingErogazionePortaApplicativa> getMappingErogazionePortaApplicativaListCache(String keyCache,
  6065.             Connection connectionPdD,
  6066.             IDServizio idServizio) throws DriverConfigurazioneException{

  6067.         SemaphoreLock lock = semaphore_getMappingErogazionePortaApplicativaListCache.acquireThrowRuntime("getMappingErogazionePortaApplicativaListCache");
  6068.         List<MappingErogazionePortaApplicativa> obj = null;
  6069.         try{

  6070.             //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  6071.             //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));

  6072.             String methodName = "getMappingErogazionePortaApplicativaList";
  6073.            
  6074.             // Raccolta dati
  6075.             if(keyCache == null)
  6076.                 throw new DriverConfigurazioneException("["+methodName+"]: KeyCache non definita");

  6077.             // se e' attiva una cache provo ad utilizzarla
  6078.             if(this.cache!=null){
  6079.                 org.openspcoop2.utils.cache.CacheResponse response =
  6080.                         (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  6081.                 if(response != null){
  6082.                     if(response.getObject()!=null){
  6083.                         this.logDebug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6084.                         return (List<MappingErogazionePortaApplicativa>) response.getObject();
  6085.                     }else if(response.getException()!=null){
  6086.                         this.logDebug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6087.                         throw (Exception) response.getException();
  6088.                     }else{
  6089.                         this.logError("In cache non e' presente ne un oggetto ne un'eccezione.");
  6090.                     }
  6091.                 }
  6092.             }

  6093.             // Effettuo le query nella mia gerarchia di registri.
  6094.             this.logDebug("oggetto con chiave ["+keyCache+"] (methodo:"+methodName+") ricerco nella configurazione...");
  6095.             obj = _getMappingErogazionePortaApplicativaList(idServizio, connectionPdD);

  6096.             // Aggiungo la risposta in cache (se esiste una cache)  
  6097.             // Se ho una eccezione aggiungo in cache solo una not found
  6098.             if( this.cache!=null ){    
  6099.                 if(obj!=null){
  6100.                     this.logInfo("Aggiungo oggetto ["+keyCache+"] in cache");
  6101.                 }else{
  6102.                     throw new Exception("Metodo ("+methodName+") ha ritornato un valore null");
  6103.                 }
  6104.                 try{    
  6105.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  6106.                     responseCache.setObject((java.io.Serializable)obj);
  6107.                     this.cache.put(keyCache,responseCache);
  6108.                 }catch(UtilsException e){
  6109.                     this.logError("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  6110.                 }
  6111.             }

  6112.         }catch(DriverConfigurazioneException e){
  6113.             throw e;
  6114.         }catch(Exception e){
  6115.             throw new DriverConfigurazioneException("Configurazione, Algoritmo di Cache fallito: "+e.getMessage(),e);
  6116.         }finally {
  6117.             semaphore_getMappingErogazionePortaApplicativaListCache.release(lock, "getMappingErogazionePortaApplicativaListCache");
  6118.         }

  6119.         return obj;
  6120.     }
  6121.    
  6122.     public List<MappingErogazionePortaApplicativa> _getMappingErogazionePortaApplicativaList(IDServizio idServizio,Connection connectionPdD) throws DriverConfigurazioneException{
  6123.        
  6124.         if(!(this.driverConfigurazionePdD instanceof DriverConfigurazioneDB)) {
  6125.             return new ArrayList<>();
  6126.         }
  6127.        
  6128.         Connection con = connectionPdD;
  6129.         boolean release = false;
  6130.         DriverConfigurazioneDB driver = (DriverConfigurazioneDB) this.driverConfigurazionePdD;
  6131.         try {
  6132.             if(con==null) {
  6133.                 con = driver.getConnection("getMappingErogazionePortaApplicativaList");
  6134.                 release = true;
  6135.             }
  6136.             return DBMappingUtils.mappingErogazionePortaApplicativaList(con, this.tipoDatabase, idServizio, false);
  6137.         }catch(Exception e){
  6138.             throw new DriverConfigurazioneException(e.getMessage(),e);
  6139.         }
  6140.         finally {
  6141.             if(release) {
  6142.                 driver.releaseConnection(con);
  6143.             }
  6144.         }
  6145.     }
  6146.    
  6147.    
  6148.    
  6149.     public static String _getKey_MappingFruizionePortaDelegataList(IDSoggetto idFruitore, IDServizio idServizio, boolean includiAzione){
  6150.         return "MappingFruizionePD_"+idFruitore.toString()+"_"+idServizio.toString(includiAzione);
  6151.     }
  6152.     @SuppressWarnings("unchecked")
  6153.     public List<MappingFruizionePortaDelegata> getMappingFruizionePortaDelegataList(IDSoggetto idFruitore, IDServizio idServizio,Connection connectionPdD) throws DriverConfigurazioneException{
  6154.        
  6155.         // se e' attiva una cache provo ad utilizzarla
  6156.         String key = null;  
  6157.         if(this.cache!=null){
  6158.             key = _getKey_MappingFruizionePortaDelegataList(idFruitore, idServizio, true);
  6159.             org.openspcoop2.utils.cache.CacheResponse response =
  6160.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  6161.             if(response != null){
  6162.                 if(response.getException()!=null){
  6163.                     throw (DriverConfigurazioneException) response.getException();
  6164.                 }else{
  6165.                     return ((List<MappingFruizionePortaDelegata>) response.getObject());
  6166.                 }
  6167.             }
  6168.         }

  6169.         // Algoritmo CACHE
  6170.         List<MappingFruizionePortaDelegata> list = null;
  6171.         if(this.cache!=null){
  6172.             list = this.getMappingFruizionePortaDelegataListCache(key, connectionPdD, idFruitore, idServizio);
  6173.         }else{
  6174.             list = _getMappingFruizionePortaDelegataList(idFruitore, idServizio, connectionPdD);
  6175.         }

  6176.         return list;
  6177.        
  6178.     }
  6179.     private static org.openspcoop2.utils.Semaphore semaphore_getMappingFruizionePortaDelegataListCache = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_MappingFruizionePortaDelegata");
  6180.     @SuppressWarnings("unchecked")
  6181.     public List<MappingFruizionePortaDelegata> getMappingFruizionePortaDelegataListCache(String keyCache,
  6182.             Connection connectionPdD,
  6183.             IDSoggetto idFruitore, IDServizio idServizio) throws DriverConfigurazioneException{

  6184.         SemaphoreLock lock = semaphore_getMappingFruizionePortaDelegataListCache.acquireThrowRuntime("getMappingFruizionePortaDelegataListCache");
  6185.         List<MappingFruizionePortaDelegata> obj = null;
  6186.         try{

  6187.             //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  6188.             //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));

  6189.             String methodName = "getMappingFruizionePortaDelegataList";
  6190.            
  6191.             // Raccolta dati
  6192.             if(keyCache == null)
  6193.                 throw new DriverConfigurazioneException("["+methodName+"]: KeyCache non definita");

  6194.             // se e' attiva una cache provo ad utilizzarla
  6195.             if(this.cache!=null){
  6196.                 org.openspcoop2.utils.cache.CacheResponse response =
  6197.                         (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  6198.                 if(response != null){
  6199.                     if(response.getObject()!=null){
  6200.                         this.logDebug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6201.                         return (List<MappingFruizionePortaDelegata>) response.getObject();
  6202.                     }else if(response.getException()!=null){
  6203.                         this.logDebug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6204.                         throw (Exception) response.getException();
  6205.                     }else{
  6206.                         this.logError("In cache non e' presente ne un oggetto ne un'eccezione.");
  6207.                     }
  6208.                 }
  6209.             }

  6210.             // Effettuo le query nella mia gerarchia di registri.
  6211.             this.logDebug("oggetto con chiave ["+keyCache+"] (methodo:"+methodName+") ricerco nella configurazione...");
  6212.             obj = _getMappingFruizionePortaDelegataList(idFruitore, idServizio, connectionPdD);

  6213.             // Aggiungo la risposta in cache (se esiste una cache)  
  6214.             // Se ho una eccezione aggiungo in cache solo una not found
  6215.             if( this.cache!=null ){    
  6216.                 if(obj!=null){
  6217.                     this.logInfo("Aggiungo oggetto ["+keyCache+"] in cache");
  6218.                 }else{
  6219.                     throw new Exception("Metodo ("+methodName+") ha ritornato un valore null");
  6220.                 }
  6221.                 try{    
  6222.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  6223.                     responseCache.setObject((java.io.Serializable)obj);
  6224.                     this.cache.put(keyCache,responseCache);
  6225.                 }catch(UtilsException e){
  6226.                     this.logError("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  6227.                 }
  6228.             }

  6229.         }catch(DriverConfigurazioneException e){
  6230.             throw e;
  6231.         }catch(Exception e){
  6232.             throw new DriverConfigurazioneException("Configurazione, Algoritmo di Cache fallito: "+e.getMessage(),e);
  6233.         }finally {
  6234.             semaphore_getMappingFruizionePortaDelegataListCache.release(lock, "getMappingFruizionePortaDelegataListCache");
  6235.         }

  6236.         return obj;
  6237.     }
  6238.    
  6239.     public List<MappingFruizionePortaDelegata> _getMappingFruizionePortaDelegataList(IDSoggetto idFruitore, IDServizio idServizio,Connection connectionPdD) throws DriverConfigurazioneException{
  6240.        
  6241.         if(!(this.driverConfigurazionePdD instanceof DriverConfigurazioneDB)) {
  6242.             return new ArrayList<>();
  6243.         }
  6244.        
  6245.         Connection con = connectionPdD;
  6246.         boolean release = false;
  6247.         DriverConfigurazioneDB driver = (DriverConfigurazioneDB) this.driverConfigurazionePdD;
  6248.         try {
  6249.             if(con==null) {
  6250.                 con = driver.getConnection("getMappingFruizionePortaDelegataList");
  6251.                 release = true;
  6252.             }
  6253.             return DBMappingUtils.mappingFruizionePortaDelegataList(con, this.tipoDatabase, idFruitore, idServizio, false);
  6254.         }catch(Exception e){
  6255.             throw new DriverConfigurazioneException(e.getMessage(),e);
  6256.         }
  6257.         finally {
  6258.             if(release) {
  6259.                 driver.releaseConnection(con);
  6260.             }
  6261.         }
  6262.     }
  6263.    
  6264.    
  6265.    
  6266.    
  6267.     /* ******** FORWARD PROXY ******** */
  6268.        
  6269.     public static String _getKey_isForwardProxyEnabled(){
  6270.         String key = "isForwardProxyEnabled";
  6271.         return key;
  6272.     }
  6273.    
  6274.     public boolean isForwardProxyEnabled() {
  6275.         try {
  6276.             return this._isForwardProxyEnabled();
  6277.         }catch(Exception e) {
  6278.             this.logError("isForwardProxyEnabled error: "+e.getMessage(),e); // non dovrebbe mai succedere
  6279.             return false;
  6280.         }
  6281.     }
  6282.     public boolean _isForwardProxyEnabled() throws DriverConfigurazioneException{
  6283.            
  6284.         // se e' attiva una cache provo ad utilizzarla
  6285.         String key = null;  
  6286.         if(this.cache!=null){
  6287.             key = _getKey_isForwardProxyEnabled();
  6288.             org.openspcoop2.utils.cache.CacheResponse response =
  6289.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  6290.             if(response != null){
  6291.                 if(response.getException()!=null){
  6292.                     throw (DriverConfigurazioneException) response.getException();
  6293.                 }else{
  6294.                     return (Boolean) response.getObject();
  6295.                 }
  6296.             }
  6297.         }

  6298.         // Algoritmo CACHE
  6299.         boolean v = false;
  6300.         if(this.cache!=null){
  6301.             v = isForwardProxyEnabledCache(key);
  6302.         }else{
  6303.             v = isForwardProxyEnabledEngine();
  6304.         }

  6305.         return v;
  6306.        
  6307.     }
  6308.    
  6309.     private static org.openspcoop2.utils.Semaphore semaphore_isForwardProxyEnabledCache = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_ForwardProxy");
  6310.     private boolean isForwardProxyEnabledCache(String keyCache) throws DriverConfigurazioneException{

  6311.         SemaphoreLock lock = semaphore_isForwardProxyEnabledCache.acquireThrowRuntime("isForwardProxyEnabledCache");
  6312.         boolean obj = false;
  6313.         try{

  6314.             //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  6315.             //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));

  6316.             String methodName = "isForwardProxyEnabledCache";
  6317.            
  6318.             // Raccolta dati
  6319.             if(keyCache == null)
  6320.                 throw new DriverConfigurazioneException("["+methodName+"]: KeyCache non definita");

  6321.             // se e' attiva una cache provo ad utilizzarla
  6322.             if(this.cache!=null){
  6323.                 org.openspcoop2.utils.cache.CacheResponse response =
  6324.                         (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  6325.                 if(response != null){
  6326.                     if(response.getObject()!=null){
  6327.                         this.logDebug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6328.                         return (Boolean) response.getObject();
  6329.                     }else if(response.getException()!=null){
  6330.                         this.logDebug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6331.                         throw (Exception) response.getException();
  6332.                     }else{
  6333.                         this.logError("In cache non e' presente ne un oggetto ne un'eccezione.");
  6334.                     }
  6335.                 }
  6336.             }

  6337.             // Effettuo le query nella mia gerarchia di registri.
  6338.             this.logDebug("oggetto con chiave ["+keyCache+"] (methodo:"+methodName+") ricerco nella configurazione...");
  6339.             obj = isForwardProxyEnabledEngine();

  6340.             // Aggiungo la risposta in cache (se esiste una cache)  
  6341.             // Se ho una eccezione aggiungo in cache solo una not found
  6342.             if( this.cache!=null ){    
  6343.                 this.logInfo("Aggiungo oggetto ["+keyCache+"] in cache");
  6344.                 try{    
  6345.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  6346.                     Boolean v = obj;
  6347.                     responseCache.setObject((java.io.Serializable)v);
  6348.                     this.cache.put(keyCache,responseCache);
  6349.                 }catch(UtilsException e){
  6350.                     this.logError("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  6351.                 }
  6352.             }

  6353.         }catch(DriverConfigurazioneException e){
  6354.             throw e;
  6355.         }catch(Exception e){
  6356.             throw new DriverConfigurazioneException("Configurazione, Algoritmo di Cache fallito: "+e.getMessage(),e);
  6357.         }finally {
  6358.             semaphore_isForwardProxyEnabledCache.release(lock, "isForwardProxyEnabledCache");
  6359.         }

  6360.         return obj;
  6361.     }
  6362.    
  6363.     private boolean isForwardProxyEnabledEngine() throws DriverConfigurazioneException{
  6364.        
  6365.         try {
  6366.             return ForwardProxy.isProxyEnabled();
  6367.         }catch(Exception e){
  6368.             throw new DriverConfigurazioneException(e.getMessage(),e);
  6369.         }
  6370.        
  6371.     }
  6372.    
  6373.    
  6374.    
  6375.    
  6376.     public ForwardProxy getForwardProxyConfigFruizione(IDSoggetto dominio, IDServizio idServizio, IDGenericProperties policy, RequestInfo requestInfo) throws DriverConfigurazioneException{
  6377.         return getForwardProxyConfig(true, dominio, idServizio, policy, requestInfo);
  6378.     }
  6379.     public ForwardProxy getForwardProxyConfigErogazione(IDSoggetto dominio, IDServizio idServizio, IDGenericProperties policy, RequestInfo requestInfo) throws DriverConfigurazioneException{
  6380.         return getForwardProxyConfig(false, dominio, idServizio, policy, requestInfo);
  6381.     }
  6382.    
  6383.     protected static String PREFIX_FORWARD_PROXY = "ForwardProxy_";
  6384.     protected static String _toKey_ForwardProxyConfigPrefix(boolean fruizione) {
  6385.         return PREFIX_FORWARD_PROXY+(fruizione?"Fruizione":"Erogazione");
  6386.     }
  6387.     protected static String _toKey_ForwardProxyConfigSuffix(IDServizio idServizio) {
  6388.         return idServizio.toString(false);
  6389.     }
  6390.     public static String _toKey_ForwardProxyConfigSuffix(IDGenericProperties policy) {
  6391.         return "policy_"+policy.getTipologia()+"_"+policy.getNome();
  6392.     }
  6393.     public static String _getKey_ForwardProxyConfig(boolean fruizione, IDSoggetto dominio, IDServizio idServizio, IDGenericProperties policy){
  6394.         String key = _toKey_ForwardProxyConfigPrefix(fruizione);
  6395.         key = key +"_"+dominio.toString();
  6396.         key = key +"_"+_toKey_ForwardProxyConfigSuffix(idServizio);
  6397.         if(policy!=null) {
  6398.             key = key +"_"+_toKey_ForwardProxyConfigSuffix(policy);
  6399.         }
  6400.         return key;
  6401.     }
  6402.     private ForwardProxy getForwardProxyConfig(boolean fruizione, IDSoggetto dominio, IDServizio idServizio, IDGenericProperties policy, RequestInfo requestInfo) throws DriverConfigurazioneException{
  6403.        
  6404.         // se e' attiva una cache provo ad utilizzarla
  6405.         String key = null;  
  6406.         if(this.cache!=null){
  6407.             key = _getKey_ForwardProxyConfig(fruizione, dominio, idServizio, policy);
  6408.             org.openspcoop2.utils.cache.CacheResponse response =
  6409.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  6410.             if(response != null){
  6411.                 if(response.getException()!=null){
  6412.                     throw (DriverConfigurazioneException) response.getException();
  6413.                 }else{
  6414.                     return (ForwardProxy) response.getObject();
  6415.                 }
  6416.             }
  6417.         }

  6418.         // Algoritmo CACHE
  6419.         ForwardProxy config = null;
  6420.         if(this.cache!=null){
  6421.             config = getForwardProxyConfigCache(key, fruizione, dominio, idServizio, policy, requestInfo);
  6422.         }else{
  6423.             config = getForwardProxyConfigEngine(fruizione, dominio, idServizio, policy, requestInfo);
  6424.         }

  6425.         return config;
  6426.        
  6427.     }
  6428.    
  6429.     private static org.openspcoop2.utils.Semaphore semaphore_getForwardProxyConfigCache = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_ForwardProxyConfig");
  6430.     private ForwardProxy getForwardProxyConfigCache(String keyCache,boolean fruizione, IDSoggetto dominio, IDServizio idServizio, IDGenericProperties policy, RequestInfo requestInfo) throws DriverConfigurazioneException{

  6431.         SemaphoreLock lock = semaphore_getForwardProxyConfigCache.acquireThrowRuntime("getForwardProxyConfigCache");
  6432.         ForwardProxy obj = null;
  6433.         try{

  6434.             //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  6435.             //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));

  6436.             String methodName = "getForwardProxyConfigCache";
  6437.            
  6438.             // Raccolta dati
  6439.             if(keyCache == null)
  6440.                 throw new DriverConfigurazioneException("["+methodName+"]: KeyCache non definita");

  6441.             // se e' attiva una cache provo ad utilizzarla
  6442.             if(this.cache!=null){
  6443.                 org.openspcoop2.utils.cache.CacheResponse response =
  6444.                         (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  6445.                 if(response != null){
  6446.                     if(response.getObject()!=null){
  6447.                         this.logDebug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6448.                         return (ForwardProxy) response.getObject();
  6449.                     }else if(response.getException()!=null){
  6450.                         this.logDebug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6451.                         throw (Exception) response.getException();
  6452.                     }else{
  6453.                         this.logError("In cache non e' presente ne un oggetto ne un'eccezione.");
  6454.                     }
  6455.                 }
  6456.             }

  6457.             // Effettuo le query nella mia gerarchia di registri.
  6458.             this.logDebug("oggetto con chiave ["+keyCache+"] (methodo:"+methodName+") ricerco nella configurazione...");
  6459.             obj = getForwardProxyConfigEngine(fruizione, dominio, idServizio, policy, requestInfo);

  6460.             // Aggiungo la risposta in cache (se esiste una cache)  
  6461.             // Se ho una eccezione aggiungo in cache solo una not found
  6462.             if( this.cache!=null ){    
  6463.                 if(obj!=null){
  6464.                     this.logInfo("Aggiungo oggetto ["+keyCache+"] in cache");
  6465.                 }else{
  6466.                     throw new Exception("Metodo ("+methodName+") ha ritornato un valore null");
  6467.                 }
  6468.                 try{    
  6469.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  6470.                     responseCache.setObject((java.io.Serializable)obj);
  6471.                     this.cache.put(keyCache,responseCache);
  6472.                 }catch(UtilsException e){
  6473.                     this.logError("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  6474.                 }
  6475.             }

  6476.         }catch(DriverConfigurazioneException e){
  6477.             throw e;
  6478.         }catch(Exception e){
  6479.             throw new DriverConfigurazioneException("Configurazione, Algoritmo di Cache fallito: "+e.getMessage(),e);
  6480.         }finally {
  6481.             semaphore_getForwardProxyConfigCache.release(lock, "getForwardProxyConfigCache");
  6482.         }

  6483.         return obj;
  6484.     }
  6485.    
  6486.     private ForwardProxy getForwardProxyConfigEngine(boolean fruizione, IDSoggetto dominio, IDServizio idServizio, IDGenericProperties policy, RequestInfo requestInfo) throws DriverConfigurazioneException{
  6487.        
  6488.         try {
  6489.             return ForwardProxy.getProxyConfigurazione(fruizione, dominio, idServizio, policy, requestInfo);
  6490.         }catch(Exception e){
  6491.             throw new DriverConfigurazioneException(e.getMessage(),e);
  6492.         }
  6493.        
  6494.     }
  6495.    
  6496.    
  6497.    
  6498.    
  6499.    
  6500.    
  6501.     /* ********  GENERIC FILE  ******** */

  6502.     public static String _getKey_ContentFile(File file){
  6503.         String key = "ContentFile_"+file.getAbsolutePath();
  6504.         return key;
  6505.     }
  6506.    
  6507.     public ContentFile getContentFile(File file) throws DriverConfigurazioneException{
  6508.            
  6509.         // se e' attiva una cache provo ad utilizzarla
  6510.         String key = null;  
  6511.         if(this.cache!=null){
  6512.             key = _getKey_ContentFile(file);
  6513.             org.openspcoop2.utils.cache.CacheResponse response =
  6514.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  6515.             if(response != null){
  6516.                 if(response.getException()!=null){
  6517.                     throw (DriverConfigurazioneException) response.getException();
  6518.                 }else{
  6519.                     return (ContentFile) response.getObject();
  6520.                 }
  6521.             }
  6522.         }

  6523.         // Algoritmo CACHE
  6524.         ContentFile content = null;
  6525.         if(this.cache!=null){
  6526.             content = getContentFileCache(key, file);
  6527.         }else{
  6528.             content = getContentFileEngine(file);
  6529.         }

  6530.         return content;
  6531.        
  6532.     }
  6533.    
  6534.     private static org.openspcoop2.utils.Semaphore semaphore_getContentFileCache = new org.openspcoop2.utils.Semaphore("ConfigurazionePdD_ContentFile");
  6535.     private ContentFile getContentFileCache(String keyCache, File file) throws DriverConfigurazioneException{

  6536.         SemaphoreLock lock = semaphore_getContentFileCache.acquireThrowRuntime("getContentFileCache");
  6537.         ContentFile obj = null;
  6538.         try{

  6539.             //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  6540.             //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));

  6541.             String methodName = "getContentFileCache";
  6542.            
  6543.             // Raccolta dati
  6544.             if(keyCache == null)
  6545.                 throw new DriverConfigurazioneException("["+methodName+"]: KeyCache non definita");

  6546.             // se e' attiva una cache provo ad utilizzarla
  6547.             if(this.cache!=null){
  6548.                 org.openspcoop2.utils.cache.CacheResponse response =
  6549.                         (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  6550.                 if(response != null){
  6551.                     if(response.getObject()!=null){
  6552.                         this.logDebug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6553.                         return (ContentFile) response.getObject();
  6554.                     }else if(response.getException()!=null){
  6555.                         this.logDebug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (methodo:"+methodName+") in cache.");
  6556.                         throw (Exception) response.getException();
  6557.                     }else{
  6558.                         this.logError("In cache non e' presente ne un oggetto ne un'eccezione.");
  6559.                     }
  6560.                 }
  6561.             }

  6562.             // Effettuo le query nella mia gerarchia di registri.
  6563.             this.logDebug("oggetto con chiave ["+keyCache+"] (methodo:"+methodName+") ricerco nella configurazione...");
  6564.             obj = getContentFileEngine(file);

  6565.             // Aggiungo la risposta in cache (se esiste una cache)  
  6566.             // Se ho una eccezione aggiungo in cache solo una not found
  6567.             if( this.cache!=null ){    
  6568.                 //if(obj!=null){
  6569.                 this.logInfo("Aggiungo oggetto ["+keyCache+"] in cache");
  6570.                 //}else{
  6571.                 //  throw new Exception("Metodo ("+methodName+") ha ritornato un valore null");
  6572.                 //}
  6573.                 try{    
  6574.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  6575.                     responseCache.setObject((java.io.Serializable)obj);
  6576.                     this.cache.put(keyCache,responseCache);
  6577.                 }catch(UtilsException e){
  6578.                     this.logError("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  6579.                 }
  6580.             }

  6581.         }catch(DriverConfigurazioneException e){
  6582.             throw e;
  6583.         }catch(Exception e){
  6584.             throw new DriverConfigurazioneException("Configurazione, Algoritmo di Cache fallito: "+e.getMessage(),e);
  6585.         }finally {
  6586.             semaphore_getContentFileCache.release(lock, "getContentFileCache");
  6587.         }

  6588.         return obj;
  6589.     }
  6590.    
  6591.     private ContentFile getContentFileEngine(File file) throws DriverConfigurazioneException{
  6592.        
  6593.         try {
  6594.             ContentFile cf = new ContentFile();
  6595.            
  6596.             if(file.exists()) {
  6597.                 cf.setExists(true);
  6598.                 if(!file.canRead()) {
  6599.                     throw new Exception("File '"+file.getAbsolutePath()+"' cannot read");
  6600.                 }
  6601.                 if(!file.isFile()) {
  6602.                     throw new Exception("File '"+file.getAbsolutePath()+"' is not file");
  6603.                 }
  6604.                 cf.setContent(FileSystemUtilities.readBytesFromFile(file));
  6605.             }
  6606.             else {
  6607.                 cf.setExists(false);    
  6608.             }
  6609.             return cf;

  6610.         }catch(Exception e){
  6611.             throw new DriverConfigurazioneException(e.getMessage(),e);
  6612.         }
  6613.        
  6614.     }
  6615. }