SPCoopImbustamento.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */



  20. package org.openspcoop2.protocol.spcoop.builder;

  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;
  23. import java.util.Iterator;
  24. import java.util.List;

  25. import javax.activation.DataHandler;
  26. import javax.xml.namespace.QName;
  27. import javax.xml.soap.AttachmentPart;
  28. import javax.xml.soap.SOAPElement;
  29. import javax.xml.soap.SOAPHeader;
  30. import javax.xml.soap.SOAPHeaderElement;

  31. import org.openspcoop2.core.id.IDSoggetto;
  32. import org.openspcoop2.message.OpenSPCoop2Message;
  33. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  34. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  35. import org.openspcoop2.message.constants.MessageRole;
  36. import org.openspcoop2.message.constants.MessageType;
  37. import org.openspcoop2.message.soap.SoapUtils;
  38. import org.openspcoop2.message.soap.TunnelSoapUtils;
  39. import org.openspcoop2.pdd.config.DynamicClusterManager;
  40. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  41. import org.openspcoop2.protocol.sdk.Busta;
  42. import org.openspcoop2.protocol.sdk.ConfigurazionePdD;
  43. import org.openspcoop2.protocol.sdk.Eccezione;
  44. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  45. import org.openspcoop2.protocol.sdk.ProtocolException;
  46. import org.openspcoop2.protocol.sdk.Riscontro;
  47. import org.openspcoop2.protocol.sdk.Trasmissione;
  48. import org.openspcoop2.protocol.sdk.builder.ProprietaManifestAttachments;
  49. import org.openspcoop2.protocol.sdk.config.IProtocolManager;
  50. import org.openspcoop2.protocol.sdk.config.ITraduttore;
  51. import org.openspcoop2.protocol.sdk.constants.Inoltro;
  52. import org.openspcoop2.protocol.sdk.constants.LivelloRilevanza;
  53. import org.openspcoop2.protocol.sdk.constants.ProfiloDiCollaborazione;
  54. import org.openspcoop2.protocol.sdk.constants.RuoloMessaggio;
  55. import org.openspcoop2.protocol.sdk.constants.TipoOraRegistrazione;
  56. import org.openspcoop2.protocol.sdk.state.IState;
  57. import org.openspcoop2.protocol.sdk.validator.ProprietaValidazione;
  58. import org.openspcoop2.protocol.spcoop.SPCoopBustaRawContent;
  59. import org.openspcoop2.protocol.spcoop.config.SPCoopProperties;
  60. import org.openspcoop2.protocol.spcoop.constants.SPCoopCostanti;
  61. import org.openspcoop2.protocol.spcoop.utils.SPCoopUtils;
  62. import org.openspcoop2.protocol.spcoop.validator.SPCoopValidazioneSemantica;
  63. import org.openspcoop2.protocol.spcoop.validator.SPCoopValidazioneSintattica;
  64. import org.openspcoop2.protocol.utils.IDSerialGenerator;
  65. import org.openspcoop2.utils.Utilities;
  66. import org.openspcoop2.utils.date.DateManager;
  67. import org.openspcoop2.utils.date.DateUtils;
  68. import org.openspcoop2.utils.dch.InputStreamDataSource;
  69. import org.openspcoop2.utils.dch.MailcapActivationReader;
  70. import org.openspcoop2.utils.id.serial.IDSerialGeneratorParameter;
  71. import org.openspcoop2.utils.id.serial.IDSerialGeneratorType;
  72. import org.openspcoop2.utils.transport.http.HttpConstants;
  73. import org.slf4j.Logger;
  74. import org.w3c.dom.Node;


  75. /**
  76.  * Classe utilizzata per costruire una Busta eGov, o parti di essa.
  77.  *
  78.  *
  79.  * @author Poli Andrea (apoli@link.it)
  80.  * @author Tronci Fabio (tronci@link.it)
  81.  * @author Lorenzo Nardi (nardi@link.it)
  82.  * @author $Author$
  83.  * @version $Rev$, $Date$
  84.  */

  85. public class SPCoopImbustamento {
  86.    
  87.     private IProtocolFactory<SOAPHeaderElement> factory;
  88.     private Logger log;
  89.     private SPCoopProperties spcoopProperties = null;
  90.     //private List<String> tipiSoggetti = null;
  91.     //private List<String> tipiServizi = null;
  92.     private SPCoopValidazioneSemantica validazioneSemantica = null;
  93.     private SPCoopValidazioneSintattica validazioneSintattica = null;
  94.     @SuppressWarnings("unused")
  95.     private ITraduttore traduttore = null;
  96.     private IProtocolManager protocolManager = null;
  97.     private IState state;

  98.     public SPCoopImbustamento(IProtocolFactory<SOAPHeaderElement> factory, IState state) throws ProtocolException{
  99.         this.factory = factory;
  100.         this.log = factory.getLogger();
  101.         this.spcoopProperties = SPCoopProperties.getInstance(this.log);
  102.        
  103.         //this.tipiSoggetti = this.factory.createProtocolConfiguration().getTipiSoggetti();
  104.         //this.tipiServizi = this.factory.createProtocolConfiguration().getTipiServizi(ServiceBinding.SOAP);
  105.        
  106.         this.state = state;
  107.        
  108.         this.validazioneSemantica = (SPCoopValidazioneSemantica) this.factory.createValidazioneSemantica(this.state);
  109.         this.validazioneSintattica = (SPCoopValidazioneSintattica) this.factory.createValidazioneSintattica(this.state);
  110.        
  111.         this.traduttore = this.factory.createTraduttore();
  112.        
  113.         this.protocolManager = this.factory.createProtocolManager();
  114.     }
  115.    
  116.     public IProtocolFactory<SOAPHeaderElement> getProtocolFactory() {
  117.         return this.factory;
  118.     }  
  119.    
  120.    
  121.     /** MAX_SERIALE */
  122.     protected static int maxSeriale = 0;
  123.     /** LunghezzaPrefisso */
  124.     private static int prefixLenght = 0;

  125.     // Usato in qualsiasi tipo di identificativo
  126.     private void initSerialCounter(int prefixSeriale, int cifre){
  127.         if(SPCoopImbustamento.maxSeriale==0){
  128.             _initSerialCounter(prefixSeriale, cifre);
  129.         }
  130.     }
  131.     private static synchronized void _initSerialCounter(int prefixSeriale, int cifre){
  132.         // Imposto il MAX_SERIAL_VALUE
  133.         if(SPCoopImbustamento.maxSeriale==0){
  134.             if(prefixSeriale==-1){
  135.                 SPCoopImbustamento.maxSeriale = SPCoopCostanti.MAX_VALUE_ID_EGOV_COUNTER;
  136.                 SPCoopImbustamento.prefixLenght = 0;
  137.             }else if(prefixSeriale<10 &&
  138.                     cifre<2){ // altrimenti devo sempre aggiungere uno 0 davanti
  139.                 SPCoopImbustamento.maxSeriale = SPCoopCostanti.MAX_VALUE_ID_EGOV_COUNTER_PREFIX_1;
  140.                 SPCoopImbustamento.prefixLenght = 1;
  141.             }else{
  142.                 SPCoopImbustamento.maxSeriale = SPCoopCostanti.MAX_VALUE_ID_EGOV_COUNTER_PREFIX_2;
  143.                 SPCoopImbustamento.prefixLenght = 2;
  144.             }
  145.         }
  146.     }
  147.    
  148.    
  149.     /* ********  Metodi per la costruzione di parti della busta SPCoop  ******** */
  150.    
  151.     /**
  152.      * Metodo che si occupa di costruire una stringa formata da un identificativo
  153.      * conforme alla specifica eGov.
  154.      * L'identificativo e' formato da :
  155.      * codAmministrazione_codPortaDominio_num.progressivo_data_ora
  156.      * <p>
  157.      * Il codice Amministrazione e' preso da <var>destinatario</var>.
  158.      * Il codice della Porta di Dominio e' preso da <var>idPD</var>.
  159.      * Le altre informazioni sono costruite dal metodo, che si occupa
  160.      * di assemblarle in una unica stringa e di ritornarla.
  161.      *
  162.      * @param idSoggetto identificativo del soggetto
  163.      * @param idTransazione identificativo della transazione
  164.      * @param ruoloMessaggio Indicazione se si tratta della richiesta
  165.      * @return un oggetto String contenente l'identificativo secondo specifica eGov.
  166.      *
  167.      */
  168.     public String buildID(IDSoggetto idSoggetto, String idTransazione, RuoloMessaggio ruoloMessaggio) throws ProtocolException {

  169.        
  170.         String idPD = idSoggetto.getCodicePorta();
  171.         String codAmm = idSoggetto.getNome();
  172.        
  173.         if(idPD == null || codAmm == null){
  174.             this.log.error("Creazione ID eGov non riuscita: alcuni parametri di creazione null idPD["+idPD+"] codAmm["+codAmm+"]");
  175.             throw new ProtocolException("Creazione ID eGov non riuscita: alcuni parametri di creazione null idPD["+idPD+"] codAmm["+codAmm+"]");
  176.         }
  177.        
  178.         Integer prefix = null;
  179.         DynamicClusterManager dynamicClusterManager = null;
  180.         OpenSPCoop2Properties openSPCoop2Properties = OpenSPCoop2Properties.getInstance();
  181.         if(openSPCoop2Properties.isClusterDinamico()) {
  182.             try {
  183.                 dynamicClusterManager = DynamicClusterManager.getInstance();
  184.                 prefix = dynamicClusterManager.getIdentificativoNumerico();
  185.             }catch(Exception e) {
  186.                 throw new ProtocolException("Creazione ID eGov non riuscita; identificativo numerico del cluster dinamico non ottenibile: "+e.getMessage(), e);
  187.             }
  188.         }
  189.         else {
  190.             String prefixS =openSPCoop2Properties.getClusterIdNumerico();
  191.             if(prefixS!=null) {
  192.                 prefix = Integer.valueOf(prefixS);
  193.             }
  194.         }
  195.        
  196.         int cifre = -1;
  197.         if(prefix!=null) {
  198.             if(openSPCoop2Properties.isClusterDinamico()) {
  199.                 try {
  200.                     cifre = openSPCoop2Properties.getClusterDinamicoIdNumericoCifre(dynamicClusterManager.isRateLimitingGestioneCluster());
  201.                 }catch(Exception e) {
  202.                     String msg = "Comprensione numero cifre per id non riuscita (DynamicClusterManager-RL:"+dynamicClusterManager.isRateLimitingGestioneCluster()+"): "+e.getMessage();
  203.                     this.log.debug(msg);
  204.                     cifre = (prefix.intValue()+"").length();
  205.                 }
  206.             }
  207.             else {
  208.                 try {
  209.                     cifre = openSPCoop2Properties.getClusterDinamicoIdNumericoCifre(false);
  210.                 }catch(Exception e) {
  211.                     String msg = "Comprensione numero cifre per id non riuscita: "+e.getMessage();
  212.                     this.log.debug(msg);
  213.                     cifre = (prefix.intValue()+"").length();
  214.                 }
  215.             }
  216.         }
  217.        
  218.         initSerialCounter(prefix==null ? -1 : prefix, cifre);

  219.         IDSerialGenerator serialGenerator = null;
  220.         IDSerialGeneratorParameter serialGeneratorParameter = null;
  221.         if( SPCoopCostanti.IDENTIFICATIVO_EGOV_SERIALE_STATIC.equals(this.spcoopProperties.getTipoSeriale_IdentificativoBusta())==false ){
  222.            
  223.             ConfigurazionePdD config = this.factory.getConfigurazionePdD();
  224.            
  225.             serialGenerator = new IDSerialGenerator(config.getLog(),this.state,config.getTipoDatabase());
  226.            
  227.             serialGeneratorParameter = new IDSerialGeneratorParameter(this.factory.getProtocol());
  228.             serialGeneratorParameter.setSerializableTimeWaitMs(config.getAttesaAttivaJDBC());
  229.             serialGeneratorParameter.setSerializableNextIntervalTimeMs(config.getCheckIntervalJDBC());
  230.             serialGeneratorParameter.setTipo(IDSerialGeneratorType.NUMERIC);
  231.             serialGeneratorParameter.setMaxValue(Long.valueOf(SPCoopImbustamento.maxSeriale));
  232.             serialGeneratorParameter.setWrap(true);
  233.         }
  234.        
  235.         try{
  236.        
  237.             long counter = -1;
  238.            
  239.             Date now=DateManager.getDate();
  240.             // Date nel formato yyyy-MM-dd_hh:mm
  241.             SimpleDateFormat dateformat = DateUtils.getSimpleDateFormatMinute();
  242.             String dataIdentificativo = dateformat.format(now);
  243.            
  244.            
  245.             StringBuilder bf = new StringBuilder();
  246.             bf.append(codAmm);
  247.             bf.append('_');
  248.             bf.append(idPD);
  249.             bf.append('_');
  250.    
  251.             if ( SPCoopCostanti.IDENTIFICATIVO_EGOV_SERIALE_MYSQL.equals(this.spcoopProperties.getTipoSeriale_IdentificativoBusta()) ) {

  252.                 if(serialGeneratorParameter!=null) {
  253.                     serialGeneratorParameter.setTipo(IDSerialGeneratorType.MYSQL);
  254.                 }
  255.                
  256.                 if(serialGenerator==null) {
  257.                     throw new Exception("SerialGenerator undefined");
  258.                 }
  259.                
  260.                 counter = serialGenerator.buildIDAsNumber(serialGeneratorParameter);
  261.    
  262.             } else if(SPCoopCostanti.IDENTIFICATIVO_EGOV_SERIALE_STATIC.equals(this.spcoopProperties.getTipoSeriale_IdentificativoBusta())
  263.                     ||
  264.                     SPCoopCostanti.IDENTIFICATIVO_EGOV_SERIALE_DYNAMIC.equals(this.spcoopProperties.getTipoSeriale_IdentificativoBusta())){
  265.    
  266.                 counter = SPCoopStaticCounter.getNextSerialCounter(now, dataIdentificativo, codAmm, idPD);
  267.                    
  268.             } else {
  269.    
  270.                 if(serialGenerator==null) {
  271.                     throw new Exception("SerialGenerator undefined");
  272.                 }
  273.                
  274.                 counter = serialGenerator.buildIDAsNumber(serialGeneratorParameter);
  275.    
  276.             }
  277.    
  278.             if(prefix!=null){
  279.                 int paddingPrefix = SPCoopImbustamento.prefixLenght - (prefix.intValue()+"").length();
  280.                 int iP=0;
  281.                 for(;iP<paddingPrefix;iP++)
  282.                     bf.append('0');
  283.                 bf.append(prefix.intValue());
  284.             }
  285.            
  286.             String c = Long.toString(counter);
  287.             int padding= SPCoopCostanti.CIFRE_SERIALI_ID_EGOV - SPCoopImbustamento.prefixLenght - c.length();
  288.             int i=0;
  289.             for(;i<padding;i++)
  290.                 bf.append('0');
  291.             bf.append(c);
  292.        
  293.             bf.append('_');
  294.    
  295.             bf.append(dataIdentificativo);
  296.    
  297.             return bf.toString();
  298.        
  299.         }catch (Exception e){
  300.             throw new ProtocolException(e.getMessage(),e);
  301.         }

  302.     }

















  303.     /* ----------------  Metodi per la costruzione di una busta eGov  -------------------- */

  304.     /**
  305.      * Metodo che si occupa di costruire un elemento SOAPElement
  306.      * contenente l'elemento 'Intestazione' definito nella specifica eGov
  307.      * 'http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/'.
  308.      * <p>
  309.      * Gli elementi eGov da creare, all'interno dell'header 'Intestazione' sono prelevati
  310.      * dall'oggetto <var>eGov</var> di tipo {@link Busta}.
  311.      *
  312.      * @param eGov contiene le funzionalita' eGov da inserire nell'header.
  313.      * @return il SOAPElement 'eGov_IT:Intestazione'  se la costruzione ha successo, null altrimenti.
  314.      *
  315.      */
  316.     public SOAPHeaderElement build_eGovHeader(OpenSPCoop2Message msg, Busta eGov) throws ProtocolException{
  317.         return build_eGovHeader(msg,eGov, true, false);
  318.     }
  319.     public SOAPHeaderElement build_eGovHeader(OpenSPCoop2Message msg,Busta eGov,boolean verificaPresenzaElementiObbligatori) throws ProtocolException{
  320.         return build_eGovHeader(msg,eGov, verificaPresenzaElementiObbligatori, false);
  321.     }
  322.     public SOAPHeaderElement build_eGovHeader(OpenSPCoop2Message msg,Busta eGov,boolean verificaPresenzaElementiObbligatori,boolean forzaValidazioneXSDElementiDisabilitata) throws ProtocolException{
  323.         try{

  324.             OpenSPCoop2SoapMessage soapMsg = null;
  325.             if(msg==null){
  326.                 OpenSPCoop2MessageFactory mf = OpenSPCoop2MessageFactory.getDefaultMessageFactory();
  327.                 soapMsg = mf.createEmptyMessage(MessageType.SOAP_11,MessageRole.NONE).castAsSoap();
  328.             }
  329.             else{
  330.                 soapMsg = msg.castAsSoap();
  331.             }
  332.                
  333.                
  334.             SOAPHeader hdr = soapMsg.getSOAPHeader();
  335.             if(hdr==null){
  336.                 hdr = soapMsg.getSOAPPart().getEnvelope().addHeader();
  337.             }
  338.             QName name = new QName(SPCoopCostanti.NAMESPACE_EGOV, "Intestazione",SPCoopCostanti.PREFIX_EGOV);
  339.             SOAPHeaderElement eGovHeader = soapMsg.newSOAPHeaderElement(hdr, name);
  340.                        
  341.            
  342.            
  343.             eGovHeader.setActor(SPCoopCostanti.ACTOR_EGOV);
  344.             eGovHeader.setMustUnderstand(true);
  345.             if(this.spcoopProperties.isAddPrefixSOAPENV()) {
  346.                 eGovHeader.addNamespaceDeclaration("SOAP_ENV","http://schemas.xmlsoap.org/soap/envelope/");
  347.             }

  348.             // Costruzione IntestazioneMessaggio
  349.             SOAPElement eGovIntestazioneMsg = eGovHeader.addChildElement("IntestazioneMessaggio",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  350.             // Mittente
  351.             if(verificaPresenzaElementiObbligatori){
  352.                 if(eGov.getMittente()==null){
  353.                     throw new ProtocolException("Mittente e' un elemento obbligatorio, e non e' stato definito");
  354.                 }
  355.                 if(eGov.getTipoMittente()==null){
  356.                     throw new ProtocolException("TipoMittente e' un attributo obbligatorio, e non e' stato definito");
  357.                 }
  358.             }
  359.             SOAPElement eGovMitt = eGovIntestazioneMsg.addChildElement("Mittente",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  360.             SOAPElement eGovIDParteMitt = eGovMitt.addChildElement("IdentificativoParte",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  361.             if(eGov.getMittente()!=null){
  362.                 eGovIDParteMitt.setValue(eGov.getMittente());
  363.             }
  364.             if(eGov.getTipoMittente()!=null){
  365.                 String tipoMittenteProtocollo = null;
  366.                 try {
  367.                     tipoMittenteProtocollo = this.traduttore.toProtocolOrganizationType(eGov.getTipoMittente());
  368.                 }catch(Exception e) {
  369.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  370.                         throw e;
  371.                     }
  372.                     else {
  373.                         tipoMittenteProtocollo = eGov.getTipoMittente(); // per serializzare errori
  374.                         this.log.warn("Produco busta con un tipo mittente non corretto: '"+tipoMittenteProtocollo+"'");
  375.                     }
  376.                 }
  377.                 eGovIDParteMitt.setAttribute("tipo",tipoMittenteProtocollo);
  378.             }
  379.             if(eGov.getIndirizzoMittente() != null){
  380.                 eGovIDParteMitt.setAttribute("indirizzoTelematico",eGov.getIndirizzoMittente());
  381.             }


  382.             // Destinatario
  383.             if(verificaPresenzaElementiObbligatori){
  384.                 if(eGov.getDestinatario()==null){
  385.                     throw new ProtocolException("Destinatario e' un elemento obbligatorio, e non e' stato definito");
  386.                 }
  387.                 if(eGov.getTipoDestinatario()==null){
  388.                     throw new ProtocolException("TipoDestinatario e' un attributo obbligatorio, e non e' stato definito");
  389.                 }
  390.             }
  391.             SOAPElement eGovDest = eGovIntestazioneMsg.addChildElement("Destinatario",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  392.             SOAPElement eGovIDParteDest = eGovDest.addChildElement("IdentificativoParte",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  393.             if(eGov.getDestinatario()!=null){
  394.                 eGovIDParteDest.setValue(eGov.getDestinatario());
  395.             }
  396.             if(eGov.getTipoDestinatario()!=null){
  397.                 String tipoDestinatarioProtocollo = null;
  398.                 try {
  399.                     tipoDestinatarioProtocollo = this.traduttore.toProtocolOrganizationType(eGov.getTipoDestinatario());
  400.                 }catch(Exception e) {
  401.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  402.                         throw e;
  403.                     }
  404.                     else {
  405.                         tipoDestinatarioProtocollo = eGov.getTipoDestinatario(); // per serializzare errori
  406.                         this.log.warn("Produco busta con un tipo destinatario non corretto: '"+tipoDestinatarioProtocollo+"'");
  407.                     }
  408.                 }
  409.                 eGovIDParteDest.setAttribute("tipo",tipoDestinatarioProtocollo);
  410.             }
  411.             if(eGov.getIndirizzoDestinatario() != null){
  412.                 eGovIDParteDest.setAttribute("indirizzoTelematico",eGov.getIndirizzoDestinatario());
  413.             }

  414.             // Profilo di Collaborazione
  415.             if(eGov.getProfiloDiCollaborazione() != null){
  416.                
  417.                 boolean generazioneElemento = true;
  418.                 if(!forzaValidazioneXSDElementiDisabilitata){
  419.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  420.                         if( !(
  421.                                 ProfiloDiCollaborazione.ONEWAY.equals(eGov.getProfiloDiCollaborazione()) ||
  422.                                 ProfiloDiCollaborazione.SINCRONO.equals(eGov.getProfiloDiCollaborazione()) ||
  423.                                 ProfiloDiCollaborazione.ASINCRONO_SIMMETRICO.equals(eGov.getProfiloDiCollaborazione()) ||
  424.                                 ProfiloDiCollaborazione.ASINCRONO_ASIMMETRICO.equals(eGov.getProfiloDiCollaborazione())
  425.                             )
  426.                         ){
  427.                             generazioneElemento = false;
  428.                         }
  429.                     }          
  430.                 }          
  431.                
  432.                 if(generazioneElemento){
  433.                    
  434.                     SOAPElement eGovProfCollaborazione = eGovIntestazioneMsg.addChildElement("ProfiloCollaborazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  435.                     switch (eGov.getProfiloDiCollaborazione()) {
  436.                     case ONEWAY:
  437.                         eGovProfCollaborazione.setValue(SPCoopCostanti.PROFILO_COLLABORAZIONE_ONEWAY);
  438.                         break;
  439.                     case SINCRONO:
  440.                         eGovProfCollaborazione.setValue(SPCoopCostanti.PROFILO_COLLABORAZIONE_SINCRONO);
  441.                         break;
  442.                     case ASINCRONO_SIMMETRICO:
  443.                         eGovProfCollaborazione.setValue(SPCoopCostanti.PROFILO_COLLABORAZIONE_ASINCRONO_SIMMETRICO);
  444.                         break;
  445.                     case ASINCRONO_ASIMMETRICO:
  446.                         eGovProfCollaborazione.setValue(SPCoopCostanti.PROFILO_COLLABORAZIONE_ASINCRONO_ASIMMETRICO);
  447.                         break;
  448.                     default:
  449.                         eGovProfCollaborazione.setValue(eGov.getProfiloDiCollaborazioneValue());
  450.                         break;
  451.                     }
  452.                    
  453.                     if(eGov.getServizioCorrelato() != null){
  454.                         eGovProfCollaborazione.setAttribute("servizioCorrelato",eGov.getServizioCorrelato());
  455.                     }
  456.                    
  457.                     if(eGov.getTipoServizioCorrelato() != null){
  458.                        
  459.                         boolean generazioneAttributo = true;
  460.                         if(!forzaValidazioneXSDElementiDisabilitata){
  461.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  462.                                 //generazioneAttributo = this.tipiServizi.contains(eGov.getTipoServizioCorrelato());
  463.                                 try {
  464.                                     this.traduttore.toProtocolServiceType(eGov.getTipoServizioCorrelato());
  465.                                 }catch(Exception e) {
  466.                                     generazioneAttributo = false;
  467.                                 }
  468.                             }
  469.                         }
  470.                         if(generazioneAttributo){
  471.                             eGovProfCollaborazione.setAttribute("tipo",this.traduttore.toProtocolServiceType(eGov.getTipoServizioCorrelato()));
  472.                         }
  473.                     }
  474.                 }
  475.             }      

  476.             // Collaborazione
  477.             if(eGov.getCollaborazione() != null){
  478.                 boolean generazioneElemento = true;
  479.                 if(!forzaValidazioneXSDElementiDisabilitata){
  480.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  481.                         ProprietaValidazione proprietaValidazione = new ProprietaValidazione();
  482.                         proprietaValidazione.setValidazioneIDCompleta(false);
  483.                         generazioneElemento = this.validazioneSemantica.validazioneID(eGov.getCollaborazione(), null,proprietaValidazione);
  484.                     }
  485.                 }
  486.                 if(generazioneElemento){
  487.                     SOAPElement eGovCollaborazione = eGovIntestazioneMsg.addChildElement("Collaborazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  488.                     eGovCollaborazione.setValue(eGov.getCollaborazione());
  489.                 }
  490.             }

  491.             // Servizio
  492.             if(eGov.getServizio() != null){
  493.                 SOAPElement eGovServizio = eGovIntestazioneMsg.addChildElement("Servizio",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  494.                 eGovServizio.setValue(eGov.getServizio());
  495.                 if(eGov.getTipoServizio() != null){
  496.                     String tipoServizio = null;
  497.                     try {
  498.                         tipoServizio = this.traduttore.toProtocolServiceType(eGov.getTipoServizio());
  499.                     }catch(Exception e) {
  500.                         if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  501.                             throw e;
  502.                         }
  503.                         else {
  504.                             tipoServizio = eGov.getTipoServizio(); // per serializzare errori
  505.                             this.log.warn("Produco busta con un tipo servizio non corretto: '"+tipoServizio+"'");
  506.                         }
  507.                     }
  508.                     eGovServizio.setAttribute("tipo",tipoServizio);
  509.                 }
  510.             }

  511.             // Azione
  512.             if(eGov.getAzione() != null){
  513.                 SOAPElement eGovAzione = eGovIntestazioneMsg.addChildElement("Azione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  514.                 eGovAzione.setValue(eGov.getAzione());
  515.             }

  516.             // Messaggio
  517.             SOAPElement eGovMessaggio = eGovIntestazioneMsg.addChildElement("Messaggio",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  518.            
  519.             // Messaggio.Identificatore
  520.             if(eGov.getID() != null){
  521.                 boolean generazioneElemento = true;
  522.                 if(!forzaValidazioneXSDElementiDisabilitata){
  523.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  524.                         generazioneElemento = this.validazioneSemantica.validazioneID_engine(eGov.getID());
  525.                     }
  526.                 }
  527.                 if(generazioneElemento){
  528.                     SOAPElement eGovIDMsg = eGovMessaggio.addChildElement("Identificatore",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  529.                     if(eGov.getID() != null)
  530.                         eGovIDMsg.setValue(eGov.getID());
  531.                 }else{
  532.                     throw new ProtocolException("Identificatore e' un elemento obbligatorio, e il valore non e' utilizzabile rispetto all'xsd ("+eGov.getID()+")");
  533.                 }
  534.             }else{
  535.                 if(verificaPresenzaElementiObbligatori){
  536.                     throw new ProtocolException("Identificatore e' un elemento obbligatorio, e non e' stato definito");
  537.                 }
  538.             }  
  539.            
  540.             // Messaggio.OraRegistrazione
  541.             SOAPElement eGovOraRegistrazione = eGovMessaggio.addChildElement("OraRegistrazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  542.             if(eGov.getOraRegistrazione() == null){
  543.                 if(verificaPresenzaElementiObbligatori){
  544.                     throw new ProtocolException("OraRegistrazione e' un elemento obbligatorio, e non e' stato definito");
  545.                 }
  546.             }
  547.             if(eGov.getOraRegistrazione() != null){
  548.                 eGovOraRegistrazione.setValue(SPCoopUtils.getDate_eGovFormat(eGov.getOraRegistrazione()));
  549.             }
  550.             if(eGov.getTipoOraRegistrazione()!=null){
  551.                 boolean generazioneAttributo = true;
  552.                 if(!forzaValidazioneXSDElementiDisabilitata){
  553.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  554.                         generazioneAttributo = ( TipoOraRegistrazione.LOCALE.equals(eGov.getTipoOraRegistrazione()) || TipoOraRegistrazione.SINCRONIZZATO.equals(eGov.getTipoOraRegistrazione()) );
  555.                     }
  556.                 }
  557.                 if(generazioneAttributo){
  558.                     if(TipoOraRegistrazione.LOCALE.equals(eGov.getTipoOraRegistrazione()))
  559.                         eGovOraRegistrazione.setAttribute("tempo", SPCoopCostanti.TIPO_TEMPO_LOCALE);
  560.                     else if(TipoOraRegistrazione.SINCRONIZZATO.equals(eGov.getTipoOraRegistrazione()))
  561.                         eGovOraRegistrazione.setAttribute("tempo", SPCoopCostanti.TIPO_TEMPO_SPC);
  562.                     else
  563.                         eGovOraRegistrazione.setAttribute("tempo", eGov.getTipoOraRegistrazioneValue());
  564.                 }
  565.                 else{
  566.                     throw new ProtocolException("TipoOraRegistrazione e' un elemento obbligatorio, e il valore non e' utilizzabile rispetto all'xsd ("+eGov.getTipoOraRegistrazioneValue()+")");
  567.                 }
  568.             }
  569.             else{
  570.                 eGovOraRegistrazione.setAttribute("tempo", SPCoopCostanti.TIPO_TEMPO_SPC); // default
  571.             }
  572.            
  573.             // Messaggio.RiferimentoMessaggio
  574.             if(eGov.getRiferimentoMessaggio() != null){
  575.                 boolean generazioneElemento = true;
  576.                 if(!forzaValidazioneXSDElementiDisabilitata){
  577.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  578.                         generazioneElemento = this.validazioneSemantica.validazioneID_engine(eGov.getRiferimentoMessaggio());
  579.                     }
  580.                 }
  581.                 if(generazioneElemento){
  582.                     SOAPElement eGovRifMsg = eGovMessaggio.addChildElement("RiferimentoMessaggio",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  583.                     eGovRifMsg.setValue(eGov.getRiferimentoMessaggio());
  584.                 }
  585.             }
  586.            
  587.             // Messaggio.Scadenza
  588.             if(eGov.getScadenza() != null){
  589.                 SOAPElement eGovScadenza = eGovMessaggio.addChildElement("Scadenza",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  590.                 eGovScadenza.setValue(SPCoopUtils.getDate_eGovFormat(eGov.getScadenza()));
  591.             }

  592.             // Profilo di Trasmissione
  593.             SOAPElement eGovProfTrasmissione = eGovIntestazioneMsg.addChildElement("ProfiloTrasmissione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  594.             if(eGov.getInoltro() != null) {
  595.                 boolean generazioneElemento = true;
  596.                 if(!forzaValidazioneXSDElementiDisabilitata){
  597.                     if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  598.                         generazioneElemento = ( Inoltro.CON_DUPLICATI.equals(eGov.getInoltro()) || Inoltro.SENZA_DUPLICATI.equals(eGov.getInoltro()) );
  599.                     }
  600.                 }
  601.                 if(generazioneElemento){
  602.                     if(Inoltro.CON_DUPLICATI.equals(eGov.getInoltro()))
  603.                         eGovProfTrasmissione.setAttribute("inoltro", SPCoopCostanti.PROFILO_TRASMISSIONE_CON_DUPLICATI);
  604.                     else if(Inoltro.SENZA_DUPLICATI.equals(eGov.getInoltro()))
  605.                         eGovProfTrasmissione.setAttribute("inoltro", SPCoopCostanti.PROFILO_TRASMISSIONE_SENZA_DUPLICATI);
  606.                     else
  607.                         eGovProfTrasmissione.setAttribute("inoltro", eGov.getInoltroValue());
  608.                 }
  609.             }
  610.             String crValue = "false";
  611.             if(eGov.isConfermaRicezione())
  612.                 crValue="true";
  613.             eGovProfTrasmissione.setAttribute("confermaRicezione",crValue);



  614.             // Sequenza
  615.             if(eGov.getSequenza() != -1){
  616.                 SOAPElement eGovSequenza = eGovIntestazioneMsg.addChildElement("Sequenza",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  617.                 StringBuilder bf = new StringBuilder();
  618.                 String sequenza = Long.toString(eGov.getSequenza());
  619.                 int padding= 7 - sequenza.length();
  620.                 int i=0;
  621.                 for(;i<padding;i++)
  622.                     bf.append('0');
  623.                 bf.append(sequenza);
  624.                 eGovSequenza.setAttribute("numeroProgressivo",bf.toString());
  625.             }





  626.             // Costruzione Lista Riscontri
  627.             if(eGov.sizeListaRiscontri() > 0){
  628.                 SOAPElement eGovListaRiscontri = eGovHeader.addChildElement("ListaRiscontri",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  629.                 for(int i=0; i<eGov.sizeListaRiscontri();i++){
  630.                     Riscontro ris = eGov.getRiscontro(i);

  631.                     SOAPElement Riscontro = eGovListaRiscontri.addChildElement("Riscontro",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  632.                     if(ris.getID() != null) {
  633.                         boolean generazioneElemento = true;
  634.                         if(!forzaValidazioneXSDElementiDisabilitata){
  635.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  636.                                 generazioneElemento = this.validazioneSemantica.validazioneID_engine(ris.getID());
  637.                             }
  638.                         }
  639.                         if(generazioneElemento){
  640.                             SOAPElement id = Riscontro.addChildElement("Identificatore",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  641.                             id.setValue(ris.getID());
  642.                         }else{
  643.                             throw new ProtocolException("Identificatore e' un elemento obbligatorio in un Riscontro, e il valore non e' utilizzabile rispetto all'xsd ("+ris.getID()+")");
  644.                         }
  645.                     }
  646.                     else{
  647.                         if(verificaPresenzaElementiObbligatori){
  648.                             throw new ProtocolException("Identificatore e' un elemento obbligatorio in un Riscontro, e non e' stato definito");
  649.                         }
  650.                     }

  651.                     if(ris.getOraRegistrazione() != null) {
  652.                         SOAPElement ora = Riscontro.addChildElement("OraRegistrazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  653.                         ora.setValue(SPCoopUtils.getDate_eGovFormat(ris.getOraRegistrazione()));
  654.                         if(ris.getTipoOraRegistrazione()!=null){
  655.                             boolean generazioneAttributo = true;
  656.                             if(!forzaValidazioneXSDElementiDisabilitata){
  657.                                 if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  658.                                     generazioneAttributo = ( TipoOraRegistrazione.LOCALE.equals(ris.getTipoOraRegistrazione()) || TipoOraRegistrazione.SINCRONIZZATO.equals(ris.getTipoOraRegistrazione()) );
  659.                                 }
  660.                             }
  661.                             if(generazioneAttributo){
  662.                                 if(TipoOraRegistrazione.LOCALE.equals(ris.getTipoOraRegistrazione()))
  663.                                     ora.setAttribute("tempo",SPCoopCostanti.TIPO_TEMPO_LOCALE);
  664.                                 else
  665.                                     ora.setAttribute("tempo",SPCoopCostanti.TIPO_TEMPO_SPC);
  666.                             }
  667.                             else{
  668.                                 throw new ProtocolException("TipoOraRegistrazione e' un attributo obbligatorio in un Riscontro, e il valore non e' utilizzabile rispetto all'xsd ("+ris.getTipoOraRegistrazioneValue(this.factory)+")");
  669.                             }
  670.                         }
  671.                         else{
  672.                             ora.setAttribute("tempo", SPCoopCostanti.TIPO_TEMPO_SPC);
  673.                         }
  674.                     }
  675.                     else{
  676.                         if(verificaPresenzaElementiObbligatori){
  677.                             throw new ProtocolException("OraRegistrazione e' un elemento obbligatorio in un Riscontro, e non e' stato definito");
  678.                         }
  679.                     }

  680.                 }
  681.             }


  682.             // Costruzione Lista Trasmissioni
  683.             if(eGov.sizeListaTrasmissioni() > 0){

  684.                 boolean addFirstElement = false;
  685.                 SOAPElement eGovListaTrasmissioni = null;

  686.                 for(int i=0; i<eGov.sizeListaTrasmissioni();i++){

  687.                     Trasmissione tr = eGov.getTrasmissione(i);

  688.                     if(tr.getOrigine() != null && tr.getTipoOrigine() != null &&
  689.                             tr.getDestinazione() != null && tr.getTipoDestinazione() != null &&
  690.                             tr.getOraRegistrazione() != null && tr.getTempo()!= null){

  691.                         if(addFirstElement==false){
  692.                             eGovListaTrasmissioni = eGovHeader.addChildElement("ListaTrasmissioni",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  693.                             addFirstElement = true;
  694.                         }

  695.                         SOAPElement Trasmissione = eGovListaTrasmissioni.addChildElement("Trasmissione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);

  696.                         SOAPElement orig = Trasmissione.addChildElement("Origine",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  697.                         SOAPElement IDParteOrigine = orig.addChildElement("IdentificativoParte",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  698.                         IDParteOrigine.setValue(tr.getOrigine());
  699.                         String tipoOrigine = null;
  700.                         try {
  701.                             tipoOrigine = this.traduttore.toProtocolOrganizationType(tr.getTipoOrigine());
  702.                         }catch(Exception e) {
  703.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  704.                                 throw e;
  705.                             }
  706.                             else {
  707.                                 tipoOrigine = tr.getTipoOrigine(); // per serializzare errori
  708.                                 this.log.warn("Produco busta con un tipo origine nella lista trasmissione non corretto: '"+tipoOrigine+"'");
  709.                             }
  710.                         }
  711.                         IDParteOrigine.setAttribute("tipo",tipoOrigine);
  712.                         if(tr.getIndirizzoOrigine() != null){
  713.                             IDParteOrigine.setAttribute("indirizzoTelematico",tr.getIndirizzoOrigine());
  714.                         }

  715.                         SOAPElement dest = Trasmissione.addChildElement("Destinazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  716.                         SOAPElement IDParteDest = dest.addChildElement("IdentificativoParte",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  717.                         IDParteDest.setValue(tr.getDestinazione());
  718.                         String tipoDestinazione = null;
  719.                         try {
  720.                             tipoDestinazione = this.traduttore.toProtocolOrganizationType(tr.getTipoDestinazione());
  721.                         }catch(Exception e) {
  722.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  723.                                 throw e;
  724.                             }
  725.                             else {
  726.                                 tipoDestinazione = tr.getTipoDestinazione(); // per serializzare errori
  727.                                 this.log.warn("Produco busta con un tipo destinazione nella lista trasmissione non corretto: '"+tipoDestinazione+"'");
  728.                             }
  729.                         }
  730.                         IDParteDest.setAttribute("tipo",tipoDestinazione);
  731.                         if(tr.getIndirizzoDestinazione() != null){
  732.                             IDParteDest.setAttribute("indirizzoTelematico",tr.getIndirizzoDestinazione());
  733.                         }

  734.                         SOAPElement ora = Trasmissione.addChildElement("OraRegistrazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  735.                         ora.setValue(SPCoopUtils.getDate_eGovFormat(tr.getOraRegistrazione()));
  736.                         boolean generazioneAttributo = true;
  737.                         if(!forzaValidazioneXSDElementiDisabilitata){
  738.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  739.                                 generazioneAttributo = ( TipoOraRegistrazione.LOCALE.equals(tr.getTempo()) || TipoOraRegistrazione.SINCRONIZZATO.equals(tr.getTempo()) );
  740.                             }
  741.                         }
  742.                         if(generazioneAttributo){
  743.                             if(TipoOraRegistrazione.LOCALE.equals(tr.getTempo()))
  744.                                 ora.setAttribute("tempo",SPCoopCostanti.TIPO_TEMPO_LOCALE);
  745.                             else
  746.                                 ora.setAttribute("tempo",SPCoopCostanti.TIPO_TEMPO_SPC);
  747.                         }
  748.                         else{
  749.                             throw new ProtocolException("Tempo e' un attributo obbligatorio in una trasmissione, e il valore non e' utilizzabile rispetto all'xsd ("+tr.getTempoValue(this.factory)+")");
  750.                         }
  751.                     }
  752.                 }
  753.             }


  754.             // Costruzione Lista Eccezioni
  755.             if(eGov.sizeListaEccezioni() > 0){
  756.                 SOAPElement eGovListaEccezioni = eGovHeader.addChildElement("ListaEccezioni",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  757.                 for(int i=0; i<eGov.sizeListaEccezioni();i++){
  758.                     Eccezione ecc = eGov.getEccezione(i);

  759.                     SOAPElement eccezione = eGovListaEccezioni.addChildElement("Eccezione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  760.                     if(ecc.getContestoCodifica() != null) {
  761.                         eccezione.setAttribute("contestoCodifica",ecc.getContestoCodificaValue(this.factory));
  762.                     }
  763.                     else{
  764.                         if(verificaPresenzaElementiObbligatori){
  765.                             throw new ProtocolException("ContestoCodifica e' un attributo obbligatorio in una eccezione, e non e' stato definito");
  766.                         }
  767.                     }

  768.                     if(ecc.getCodiceEccezione() != null) {
  769.                         boolean generazioneAttributo = true;
  770.                         if(!forzaValidazioneXSDElementiDisabilitata){
  771.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  772.                                 generazioneAttributo = this.validazioneSintattica.validazioneCodiceEccezione(ecc.getCodiceEccezione());
  773.                             }
  774.                         }
  775.                         if(generazioneAttributo){
  776.                             eccezione.setAttribute("codiceEccezione",ecc.getCodiceEccezioneValue(this.factory));
  777.                         }
  778.                         else{
  779.                             throw new ProtocolException("CodiceEccezione e' un attributo obbligatorio in una eccezione, e il valore non e' utilizzabile rispetto all'xsd ("+ecc.getCodiceEccezione()+")");
  780.                         }
  781.                     }
  782.                     else{
  783.                         if(verificaPresenzaElementiObbligatori){
  784.                             throw new ProtocolException("CodiceEccezione e' un attributo obbligatorio in una eccezione, e non e' stato definito");
  785.                         }
  786.                     }


  787.                     if(ecc.getRilevanza() != null) {
  788.                         boolean generazioneAttributo = true;
  789.                         if(!forzaValidazioneXSDElementiDisabilitata){
  790.                             if(this.protocolManager.isGenerazioneElementiNonValidabiliRispettoXSD()==false){
  791.                                 generazioneAttributo = ( LivelloRilevanza.DEBUG.equals(ecc.getRilevanza()) ||
  792.                                         LivelloRilevanza.ERROR.equals(ecc.getRilevanza()) ||
  793.                                         LivelloRilevanza.FATAL.equals(ecc.getRilevanza()) ||
  794.                                         LivelloRilevanza.INFO.equals(ecc.getRilevanza()) ||
  795.                                         LivelloRilevanza.WARN.equals(ecc.getRilevanza()) );
  796.                             }
  797.                         }
  798.                         if(generazioneAttributo){
  799.                             eccezione.setAttribute("rilevanza",this.traduttore.toString(ecc.getRilevanza()));
  800.                         }
  801.                         else{
  802.                             throw new ProtocolException("Rilevanza e' un attributo obbligatorio in una eccezione, e il valore non e' utilizzabile rispetto all'xsd ("+ecc.getRilevanza()+")");
  803.                         }
  804.                     }
  805.                     else{
  806.                         if(verificaPresenzaElementiObbligatori){
  807.                             throw new ProtocolException("Rilevanza e' un attributo obbligatorio in una eccezione, e non e' stato definito");
  808.                         }
  809.                     }

  810.                     if(ecc.getDescrizione(this.factory) != null) {
  811.                         eccezione.setAttribute("posizione",ecc.getDescrizione(this.factory));
  812.                     }
  813.                     else{
  814.                         if(verificaPresenzaElementiObbligatori){
  815.                             throw new ProtocolException("Posizione e' un attributo obbligatorio in una eccezione, e non e' stato definito");
  816.                         }
  817.                     }
  818.                    
  819.                 }
  820.             }

  821.             return eGovHeader;      
  822.         } catch(Exception e) {
  823.             this.log.error("Creazione busta eGov non riuscita: "+e.getMessage(),e);
  824.             throw new ProtocolException("Creazione busta eGov non riuscita: "+e.getMessage(),e);
  825.         }  
  826.     }



  827.     private String normalizeIdRefManifest(String contentId) {
  828.         StringBuilder bf = new StringBuilder();
  829.         if(this.spcoopProperties.isGenerateManifestAttachmentsIdWithBrackets()) {
  830.             if(contentId.startsWith("<")==false) {
  831.                 bf.append("<");
  832.             }
  833.             bf.append(contentId);
  834.             if(contentId.endsWith(">")==false) {
  835.                 bf.append(">");
  836.             }
  837.         }
  838.         else {
  839.             int start = 0;
  840.             int end = contentId.length();
  841.             if(contentId.startsWith("<")) {
  842.                 start = 1;
  843.             }
  844.             if(contentId.endsWith(">")) {
  845.                 end = contentId.length()-1;
  846.             }
  847.             bf.append(contentId.substring(start,end));
  848.         }
  849.         return bf.toString();
  850.     }

  851.     /**
  852.      * Metodo che si occupa di costruire un Manifest per gli Attachments
  853.      * definito nella specifica eGov
  854.      * 'http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/'.
  855.      * <p>
  856.      * Gli attachments da linkare, all'interno del Manifesto sono prelevati
  857.      * dall'oggetto <var>msg</var>.
  858.      *
  859.      * @param msg Messaggio su cui creare il manifesto
  860.      * @param ruoloMessaggio Tipo di Busta
  861.      *
  862.      */
  863.     public OpenSPCoop2Message build_eGovManifest(OpenSPCoop2Message msg,RuoloMessaggio ruoloMessaggio,
  864.             ProprietaManifestAttachments proprietaManifestAttachments) throws ProtocolException{
  865.         try{

  866.             // Descrizione
  867.             SOAPElement descrizione = msg.getFactory().createEmptyMessage(MessageType.SOAP_11,MessageRole.NONE).castAsSoap().
  868.                     getSOAPBody().addChildElement(new QName(SPCoopCostanti.NAMESPACE_EGOV, "Descrizione",SPCoopCostanti.PREFIX_EGOV));
  869.            
  870.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();

  871.             // Attachments
  872.             java.util.Iterator<?> iter = soapMsg.getAttachments();
  873.             int attach = 1;
  874.             while( iter.hasNext() ){
  875.                 Utilities.printFreeMemory("Imbustamento - Costruzione manifest att " + attach);
  876.                 AttachmentPart p = (AttachmentPart) iter.next();
  877.                 String contentID = p.getContentId();
  878.                 String contentLocation = p.getContentLocation();
  879.                 //String fileName = p.getAttachmentFile();
  880.                 String contentType = p.getContentType();
  881.                 // Costruzione DescrizioneMessaggio
  882.                 SOAPElement descrizioneMessaggio =  descrizione.addChildElement(SPCoopCostanti.LOCAL_NAME_MANIFEST_EGOV_DESCRIZIONE_MESSAGGIO,
  883.                         SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  884.                 // Costruzione Riferimento
  885.                 SOAPElement riferimento =  descrizioneMessaggio.addChildElement("Riferimento",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  886.                
  887.                 //Name href = sf.createName("href",Costanti.PREFIX_EGOV,Costanti.NAMESPACE_EGOV);
  888.                
  889.                 if(contentID!=null){
  890.                     riferimento.setAttribute("href","cid:"+normalizeIdRefManifest(contentID)); // xsd:anyURI
  891.                 }
  892.                 else{
  893.                     riferimento.setAttribute("href",contentLocation); // xsd:anyURI
  894.                 }

  895.                 //Name role = sf.createName("role",Costanti.PREFIX_EGOV,Costanti.NAMESPACE_EGOV);
  896.                
  897.                 if(attach==1 && proprietaManifestAttachments.isScartaBody()){
  898.                    
  899.                     if(RuoloMessaggio.RICHIESTA.equals(ruoloMessaggio)){
  900.                         riferimento.setAttribute("role",this.spcoopProperties.getRoleRichiestaManifest()); // xsd:string
  901.                     }
  902.                     else{
  903.                         riferimento.setAttribute("role",this.spcoopProperties.getRoleRispostaManifest()); // xsd:string
  904.                     }
  905.                 }
  906.                 else{
  907.                     riferimento.setAttribute("role",this.spcoopProperties.getRoleAllegatoManifest()); // xsd:string
  908.                 }
  909.                 // Obbligatorio il namespace
  910.                
  911.                 // ??? riferimento.setAttribute(Costanti.NAMESPACE_EGOV,"id","attachment"+attach); // xsd:ID
  912.                 QName id = new QName(SPCoopCostanti.NAMESPACE_EGOV,"id",SPCoopCostanti.PREFIX_EGOV);
  913.                 riferimento.addAttribute(id,"attachment"+attach); // xsd:ID
  914.                 // Costruzione Schema
  915.                 SOAPElement schema = riferimento.addChildElement("Schema",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  916.                 schema.setAttribute("posizione",contentType); //xsd:anyURI
  917.                 // Costruzione Titolo
  918.                 SOAPElement titolo = riferimento.addChildElement("Titolo",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  919.                 titolo.setAttribute("Lingua","it"); //xsd:language
  920.                 //if(fileName!=null)
  921.                 //  titolo.setValue(fileName); // xsd:string
  922.                 //else
  923.                 if(attach==1 && proprietaManifestAttachments.isScartaBody()){
  924.                     if(RuoloMessaggio.RICHIESTA.equals(ruoloMessaggio))
  925.                         titolo.setValue(this.spcoopProperties.getRoleRichiestaManifest()); // xsd:string
  926.                     else
  927.                         titolo.setValue(this.spcoopProperties.getRoleRispostaManifest()); // xsd:string
  928.                 }else{
  929.                     titolo.setValue("attachment"+attach); // xsd:string
  930.                 }
  931.                 attach++;
  932.             }
  933.            

  934.             // Body into Attachments
  935.             if(proprietaManifestAttachments.isScartaBody() == false){
  936.                 Utilities.printFreeMemory("Imbustamento - Scarta Body");
  937.                 byte [] body = TunnelSoapUtils.sbustamentoSOAPEnvelope(soapMsg.getFactory(), soapMsg.getSOAPPart().getEnvelope());
  938.                 AttachmentPart ap = null;
  939.                 //ByteArrayInputStream isContent = new ByteArrayInputStream(body);
  940.                 //ap.setContent(isContent,"text/xml; charset=UTF-8");
  941. //                  String xmlBody = new String(body);
  942.                 //xmlBody = StringEscapeUtils.unescapeXml(xmlBody);
  943. //                  Reader stringReader = new StringReader(xmlBody);
  944.                 //Source streamSource = new javax.xml.transform.stream.StreamSource(new java.io.ByteArrayInputStream(body)); FIX: StreamSource instances may only be used once.
  945.                 //System.out.println("BODY IS :["+new String(body)+"] ["+body.length+"]");
  946.                 boolean bodyWithMultiRootElement = false;
  947.                 if(body==null || body.length==0){
  948.                     body = SPCoopCostanti.XML_MANIFEST_EGOV_EMPTY_BODY.getBytes();
  949.                     //System.out.println("PATCH ["+new String(body)+"]");
  950.                 }
  951.                 else{
  952.                     List<Node> listNode = SoapUtils.getNotEmptyChildNodes(soapMsg.getFactory(), soapMsg.getSOAPPart().getEnvelope().getBody(), false);
  953.                     if(listNode!=null && listNode.size()>1){
  954.                         //System.out.println("MULTI ELEMENT: "+listNode.size());
  955.                         bodyWithMultiRootElement = true;
  956.                     }
  957.                 }
  958.                 if(bodyWithMultiRootElement){
  959.                     //System.out.println("OCTECT");
  960.                     InputStreamDataSource isSource = new InputStreamDataSource("ManifestEGov", HttpConstants.CONTENT_TYPE_APPLICATION_OCTET_STREAM, body);
  961.                     ap = soapMsg.createAttachmentPart(new DataHandler(isSource));
  962.                 }else{
  963.                     if(MailcapActivationReader.existsDataContentHandler(HttpConstants.CONTENT_TYPE_TEXT_XML)){
  964.                         ap = soapMsg.createAttachmentPart();
  965.                         soapMsg.updateAttachmentPart(ap, body, HttpConstants.CONTENT_TYPE_TEXT_XML);
  966.                     }
  967.                     else {
  968.                         InputStreamDataSource isSource = new InputStreamDataSource("ManifestEGov", HttpConstants.CONTENT_TYPE_TEXT_XML, body);
  969.                         ap = soapMsg.createAttachmentPart(new DataHandler(isSource));
  970.                     }
  971.                 }
  972.                 ap.setContentId(soapMsg.createContentID(SPCoopCostanti.NAMESPACE_EGOV));
  973.                 //ap.setContentLocation("provaOpenSPCoop"); // Test Sbustamento con ContentLocation
  974.                 soapMsg.addAttachmentPart(ap);
  975.                 //isContent.close();
  976.                 // add OriginalMsg in Manifest
  977.                 // Costruzione DescrizioneMessaggio
  978.                 SOAPElement descrizioneMessaggio = descrizione.addChildElement(SPCoopCostanti.LOCAL_NAME_MANIFEST_EGOV_DESCRIZIONE_MESSAGGIO,
  979.                         SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  980.                 // Costruzione Riferimento
  981.                 SOAPElement riferimento = descrizioneMessaggio.addChildElement("Riferimento",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  982.                 riferimento.setAttribute("href","cid:" + normalizeIdRefManifest(ap.getContentId())); // xsd:anyURI
  983.                 //riferimento.setAttribute("href",ap.getContentLocation()); // xsd:anyURI // Test Sbustamento con ContentLocation
  984.                 if(RuoloMessaggio.RICHIESTA.equals(ruoloMessaggio)){
  985.                     riferimento.setAttribute("role",this.spcoopProperties.getRoleRichiestaManifest()); // xsd:string
  986.                 }
  987.                 else{
  988.                     riferimento.setAttribute("role",this.spcoopProperties.getRoleRispostaManifest()); // xsd:string
  989.                 }
  990.                 // Obbligatorio il namespace
  991.                 //riferimento.setAttribute(Costanti.NAMESPACE_EGOV,"id","attachment"+attach); // xsd:ID
  992.                 QName id = new QName(SPCoopCostanti.NAMESPACE_EGOV,"id",SPCoopCostanti.PREFIX_EGOV);
  993.                 riferimento.addAttribute(id,"attachment"+attach); // xsd:ID
  994.                 // Costruzione Schema
  995.                 SOAPElement schema = riferimento.addChildElement("Schema",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  996.                 schema.setAttribute("posizione",ap.getContentType()); //xsd:anyURI
  997.                 // Costruzione Titolo
  998.                 SOAPElement titolo = riferimento.addChildElement("Titolo",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  999.                 titolo.setAttribute("Lingua","it"); //xsd:language
  1000.                 if(RuoloMessaggio.RICHIESTA.equals(ruoloMessaggio))
  1001.                     titolo.setValue(this.spcoopProperties.getRoleRichiestaManifest()); // xsd:string
  1002.                 else
  1003.                     titolo.setValue(this.spcoopProperties.getRoleRispostaManifest()); // xsd:string

  1004.             }
  1005.             Utilities.printFreeMemory("Imbustamento - Add Manifest in Body");
  1006.             // Add Manifest in Body
  1007.             soapMsg.getSOAPBody().removeContents();
  1008.             soapMsg.getSOAPBody().addChildElement(descrizione);


  1009.             return msg;

  1010.         } catch(Exception e) {
  1011.             this.log.error("Creazione Manifest degli attachments non riuscita: "+e.getMessage(),e);
  1012.             throw new ProtocolException("Creazione Manifest degli attachments non riuscita: "+e.getMessage(),e);
  1013.         }  
  1014.     }


  1015.     public void imbustamentoEGov(OpenSPCoop2Message msg,Busta busta,ProprietaManifestAttachments proprietaManifestAttachments) throws ProtocolException{    
  1016.         this.imbustamentoEGov(msg, busta, RuoloMessaggio.RISPOSTA, proprietaManifestAttachments);
  1017.     }


  1018.     public SOAPHeaderElement imbustamentoEGov(OpenSPCoop2Message msg,Busta busta,
  1019.             RuoloMessaggio ruoloMessaggio,
  1020.             ProprietaManifestAttachments proprietaManifestAttachments) throws ProtocolException{    

  1021.         try{
  1022.             // add header eGov
  1023.             Utilities.printFreeMemory("Imbustamento - Creazione header eGov");
  1024.             SOAPHeaderElement headerEGovElement = (SOAPHeaderElement) this.build_eGovHeader(msg, busta);
  1025.             Utilities.printFreeMemory("Imbustamento - imbustamento");
  1026.             this.imbustamentoEGov(msg, headerEGovElement, ruoloMessaggio, proprietaManifestAttachments);
  1027.             return headerEGovElement;
  1028.         }catch(Exception e){
  1029.             this.log.error("ImbustamentoEGov non riuscito: "+e.getMessage(),e);
  1030.             throw new ProtocolException("ImbustamentoEGov non riuscito: "+e.getMessage(),e);
  1031.         }
  1032.     }

  1033.     public SOAPHeaderElement imbustamentoEGov(OpenSPCoop2Message msg, SOAPHeaderElement headerEGovElement,
  1034.             RuoloMessaggio ruoloMessaggio,
  1035.             ProprietaManifestAttachments proprietaManifestAttachments) throws ProtocolException{    

  1036.         try{
  1037.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  1038.            
  1039.             SOAPHeader hdr = soapMsg.getSOAPHeader();
  1040.             if(hdr==null){
  1041.                 hdr = soapMsg.getSOAPPart().getEnvelope().addHeader();
  1042.             }

  1043.             soapMsg.addHeaderElement(hdr, headerEGovElement);
  1044.             Utilities.printFreeMemory("Imbustamento -Header Aggiunto");
  1045.             // Gestione Manifest
  1046.            
  1047.             if (proprietaManifestAttachments!=null && proprietaManifestAttachments.isGestioneManifest() && soapMsg.countAttachments()>0) {
  1048.                 Utilities.printFreeMemory("Imbustamento - Gestione Manifest");
  1049.                 this.build_eGovManifest(msg,ruoloMessaggio,proprietaManifestAttachments);
  1050.             }
  1051.            
  1052.             //System.out.println("MSG:");
  1053.             //msg.writeTo(System.out);
  1054.            
  1055.             return headerEGovElement;
  1056.            
  1057.         }catch(Exception e){
  1058.             this.log.error("ImbustamentoEGov non riuscito: "+e.getMessage(),e);
  1059.             throw new ProtocolException("ImbustamentoEGov non riuscito: "+e.getMessage(),e);
  1060.         }
  1061.     }


  1062.     /**
  1063.      * Metodo che si occupa di costruire un elemento Trasmissione
  1064.      *
  1065.      * @param trasmissione Trasmissione
  1066.      *
  1067.      */
  1068.     public void build_trasmissione(Trasmissione trasmissione,SOAPElement listaTrasmissioni) throws ProtocolException{
  1069.         try{

  1070.             SOAPElement trasmissioneNode = listaTrasmissioni.addChildElement("Trasmissione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);

  1071.             SOAPElement orig = trasmissioneNode.addChildElement("Origine",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  1072.             SOAPElement IDParteOrigine = orig.addChildElement("IdentificativoParte",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  1073.             IDParteOrigine.setValue(trasmissione.getOrigine());
  1074.             IDParteOrigine.setAttribute("tipo",trasmissione.getTipoOrigine());
  1075.             if(trasmissione.getIndirizzoOrigine() != null){
  1076.                 IDParteOrigine.setAttribute("indirizzoTelematico",trasmissione.getIndirizzoOrigine());
  1077.             }

  1078.             SOAPElement dest = trasmissioneNode.addChildElement("Destinazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  1079.             SOAPElement IDParteDest = dest.addChildElement("IdentificativoParte",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  1080.             IDParteDest.setValue(trasmissione.getDestinazione());
  1081.             IDParteDest.setAttribute("tipo",trasmissione.getTipoDestinazione());
  1082.             if(trasmissione.getIndirizzoDestinazione() != null){
  1083.                 IDParteDest.setAttribute("indirizzoTelematico",trasmissione.getIndirizzoDestinazione());
  1084.             }

  1085.             SOAPElement ora = trasmissioneNode.addChildElement("OraRegistrazione",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  1086.             ora.setValue(SPCoopUtils.getDate_eGovFormat(trasmissione.getOraRegistrazione()));
  1087.             if(TipoOraRegistrazione.LOCALE.equals(trasmissione.getTempo()))
  1088.                 ora.setAttribute("tempo",SPCoopCostanti.TIPO_TEMPO_LOCALE);
  1089.             else if(TipoOraRegistrazione.SINCRONIZZATO.equals(trasmissione.getTempo()))
  1090.                 ora.setAttribute("tempo",SPCoopCostanti.TIPO_TEMPO_SPC);
  1091.             else
  1092.                 ora.setAttribute("tempo",trasmissione.getTempoValue(this.factory));

  1093.         } catch(Exception e) {
  1094.             this.log.error("Creazione trasmissione non riuscita: "+e.getMessage(),e);
  1095.             throw new ProtocolException("Creazione trasmissione non riuscita: "+e.getMessage(),e);
  1096.         }  
  1097.     }


  1098.     public SOAPHeaderElement addTrasmissione(OpenSPCoop2Message message,Trasmissione trasmissione,boolean readQualifiedAttribute)throws ProtocolException{
  1099.         SOAPHeaderElement eGovHeaderOLD = null;
  1100.         SOAPHeaderElement eGovHeaderNEW = null;
  1101.         try{
  1102.            
  1103.             SPCoopBustaRawContent bustaElement = this.validazioneSintattica.getHeaderEGov(message.castAsSoap(),readQualifiedAttribute);
  1104.             if(bustaElement==null){
  1105.                 throw new ProtocolException("Header eGov non esistente");
  1106.             }
  1107.             eGovHeaderOLD = bustaElement.getElement();
  1108.             if(eGovHeaderOLD==null){
  1109.                 throw new ProtocolException("Header eGov non esistente");
  1110.             }

  1111.             OpenSPCoop2SoapMessage soapMsg = message.castAsSoap();
  1112.            
  1113.             // Creo nuovo header egov
  1114.             eGovHeaderNEW =
  1115.                     message.getFactory().createEmptyMessage(MessageType.SOAP_11,MessageRole.NONE).castAsSoap().
  1116.                     getSOAPHeader().addHeaderElement(
  1117.                         new QName(eGovHeaderOLD.getNamespaceURI(),eGovHeaderOLD.getLocalName(),eGovHeaderOLD.getPrefix()));
  1118.            
  1119.             eGovHeaderNEW.setActor(eGovHeaderOLD.getActor());
  1120.             eGovHeaderNEW.setMustUnderstand(eGovHeaderOLD.getMustUnderstand());
  1121.             // Aggiungo dichiarazioni di namespaces
  1122.             java.util.Iterator<?> namespaces = eGovHeaderOLD.getNamespacePrefixes();
  1123.             while(namespaces.hasNext()){
  1124.                 String mNamespace = (String) namespaces.next();
  1125.                 eGovHeaderNEW.addNamespaceDeclaration(mNamespace, eGovHeaderOLD.getNamespaceURI(mNamespace));
  1126.             }
  1127.             // Aggiungo attributi presenti nel vecchio nel nuovo
  1128.             java.util.Iterator<?> attributes = eGovHeaderOLD.getAllAttributes();
  1129.             while(attributes.hasNext()){
  1130.                 javax.xml.soap.Name mAttribute = (javax.xml.soap.Name) attributes.next();
  1131.                 eGovHeaderNEW.addAttribute(mAttribute, eGovHeaderOLD.getAttributeValue(mAttribute));
  1132.             }
  1133.             // Aggiungo figli presenti nel vecchio, nel nuovo
  1134.             java.util.Iterator<?> child = eGovHeaderOLD.getChildElements();
  1135.             while(child.hasNext()){
  1136.                 Object oChild = child.next();
  1137.                 if(oChild instanceof SOAPElement){
  1138.                     SOAPElement mChild = (SOAPElement) oChild;
  1139.                     eGovHeaderNEW.addChildElement(mChild);
  1140.                 }
  1141.             }
  1142.             // Cerco eventuale lista trasmissioni
  1143.             child = eGovHeaderNEW.getChildElements();
  1144.             SOAPElement listaTrasmissioni = null;
  1145.             while(child.hasNext()){
  1146.                 SOAPElement mChild = (SOAPElement) child.next();
  1147.                 if("ListaTrasmissioni".equals(mChild.getLocalName())){
  1148.                     listaTrasmissioni = mChild;
  1149.                     break;
  1150.                 }
  1151.             }
  1152.             if(listaTrasmissioni==null){
  1153.                 listaTrasmissioni = eGovHeaderNEW.addChildElement("ListaTrasmissioni",SPCoopCostanti.PREFIX_EGOV,SPCoopCostanti.NAMESPACE_EGOV);
  1154.             }
  1155.             // Aggiungo nuova trasmissione
  1156.             this.build_trasmissione(trasmissione, listaTrasmissioni);


  1157.             // NOTA: ho dovuto effettuare una eliminazione, e una ri-creazione, perche' non e' possibile modificare un HeaderElement
  1158.             // Rimozione header egov
  1159.             soapMsg.getSOAPHeader().removeChild(eGovHeaderOLD);

  1160.             // Imbustamento nuovo header
  1161.             return this.imbustamentoEGov(message, eGovHeaderNEW, RuoloMessaggio.RISPOSTA, null);

  1162.         } catch(Exception e) {
  1163.             this.log.error("addTrasmissione non riuscita: "+e.getMessage(),e);
  1164.             throw new ProtocolException("addTrasmissione non riuscita: "+e.getMessage(),e);
  1165.         }  
  1166.         finally{
  1167.             // *** GB ***
  1168.             if(this.validazioneSintattica!=null){
  1169.                 this.validazioneSintattica.setHeaderSOAP(null);
  1170.             }
  1171.             eGovHeaderOLD = null;
  1172.             eGovHeaderNEW = null;
  1173.             // *** GB ***
  1174.         }
  1175.     }




  1176.    

  1177.     public SOAPHeaderElement imbustamento(OpenSPCoop2Message msg, Busta busta,
  1178.             RuoloMessaggio ruoloMessaggio,
  1179.             ProprietaManifestAttachments proprietaManifestAttachments)
  1180.             throws ProtocolException {
  1181.         if(busta.getProfiloDiCollaborazione() != null) {
  1182.             switch (busta.getProfiloDiCollaborazione()) {
  1183.             case ONEWAY:
  1184.                 busta.setProfiloDiCollaborazione(ProfiloDiCollaborazione.ONEWAY, SPCoopCostanti.PROFILO_COLLABORAZIONE_ONEWAY);
  1185.                 break;
  1186.             case SINCRONO:
  1187.                 busta.setProfiloDiCollaborazione(ProfiloDiCollaborazione.SINCRONO, SPCoopCostanti.PROFILO_COLLABORAZIONE_SINCRONO);
  1188.                 break;
  1189.             case ASINCRONO_ASIMMETRICO:
  1190.                 busta.setProfiloDiCollaborazione(ProfiloDiCollaborazione.ASINCRONO_ASIMMETRICO, SPCoopCostanti.PROFILO_COLLABORAZIONE_ASINCRONO_ASIMMETRICO);
  1191.                 break;
  1192.             case ASINCRONO_SIMMETRICO:
  1193.                 busta.setProfiloDiCollaborazione(ProfiloDiCollaborazione.ASINCRONO_SIMMETRICO, SPCoopCostanti.PROFILO_COLLABORAZIONE_ASINCRONO_SIMMETRICO);
  1194.                 break;
  1195.             case UNKNOWN:
  1196.                 break;
  1197.             }
  1198.         }
  1199.        
  1200.         if(busta.getTipoOraRegistrazione() != null) {
  1201.             switch (busta.getTipoOraRegistrazione()) {
  1202.             case LOCALE:
  1203.                 busta.setTipoOraRegistrazione(TipoOraRegistrazione.LOCALE,SPCoopCostanti.TIPO_TEMPO_LOCALE);
  1204.                 break;
  1205.             case SINCRONIZZATO:
  1206.                 busta.setTipoOraRegistrazione(TipoOraRegistrazione.SINCRONIZZATO,SPCoopCostanti.TIPO_TEMPO_SPC);
  1207.                 break;
  1208.             case UNKNOWN:
  1209.                 break;
  1210.             }
  1211.         }
  1212.        
  1213.         if(busta.getInoltro() != null) {
  1214.             switch (busta.getInoltro()) {
  1215.             case CON_DUPLICATI:
  1216.                 busta.setInoltro(Inoltro.CON_DUPLICATI, SPCoopCostanti.PROFILO_TRASMISSIONE_CON_DUPLICATI);
  1217.                 break;
  1218.             case SENZA_DUPLICATI:
  1219.                 busta.setInoltro(Inoltro.SENZA_DUPLICATI, SPCoopCostanti.PROFILO_TRASMISSIONE_SENZA_DUPLICATI);
  1220.                 break;
  1221.             case UNKNOWN:
  1222.                 break;
  1223.             }
  1224.         }
  1225.        
  1226.         Iterator<Riscontro> riscontri = busta.getListaRiscontri().iterator();
  1227.         while(riscontri.hasNext()){
  1228.             Riscontro riscontro = riscontri.next();
  1229.             if(riscontro.getTipoOraRegistrazione() == null) continue;
  1230.             if(riscontro.getTipoOraRegistrazione().equals(TipoOraRegistrazione.LOCALE))
  1231.                 riscontro.setTipoOraRegistrazioneValue(SPCoopCostanti.TIPO_TEMPO_LOCALE);
  1232.             if(riscontro.getTipoOraRegistrazione().equals(TipoOraRegistrazione.SINCRONIZZATO))
  1233.                 riscontro.setTipoOraRegistrazioneValue(SPCoopCostanti.TIPO_TEMPO_SPC);
  1234.         }
  1235.        
  1236.         Iterator<Trasmissione> trasmissioni = busta.getListaTrasmissioni().iterator();
  1237.         while(trasmissioni.hasNext()){
  1238.             Trasmissione trasmissione = trasmissioni.next();
  1239.             if(trasmissione.getTempo() == null) continue;
  1240.            
  1241.             if(trasmissione.getTempo().equals(TipoOraRegistrazione.LOCALE))
  1242.                 trasmissione.setTempoValue(SPCoopCostanti.TIPO_TEMPO_LOCALE);
  1243.             else  
  1244.                 trasmissione.setTempoValue(SPCoopCostanti.TIPO_TEMPO_SPC);
  1245.              
  1246.         }
  1247.            
  1248.         return this.imbustamentoEGov(msg, busta, ruoloMessaggio, proprietaManifestAttachments);
  1249.     }

  1250.     public SOAPHeaderElement addTrasmissione(OpenSPCoop2Message message,
  1251.             Trasmissione trasmissione) throws ProtocolException {
  1252.         return this.addTrasmissione(message, trasmissione, false);
  1253.     }

  1254. }