Busta.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.sdk;

  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;

  24. import org.openspcoop2.core.id.IDSoggetto;
  25. import org.openspcoop2.core.tracciamento.Data;
  26. import org.openspcoop2.core.tracciamento.Eccezioni;
  27. import org.openspcoop2.core.tracciamento.ProfiloCollaborazione;
  28. import org.openspcoop2.core.tracciamento.ProfiloTrasmissione;
  29. import org.openspcoop2.core.tracciamento.Proprieta;
  30. import org.openspcoop2.core.tracciamento.Protocollo;
  31. import org.openspcoop2.core.tracciamento.Riscontri;
  32. import org.openspcoop2.core.tracciamento.Soggetto;
  33. import org.openspcoop2.core.tracciamento.SoggettoIdentificativo;
  34. import org.openspcoop2.core.tracciamento.TipoData;
  35. import org.openspcoop2.core.tracciamento.Trasmissioni;
  36. import org.openspcoop2.core.tracciamento.constants.TipoInoltro;
  37. import org.openspcoop2.core.tracciamento.constants.TipoProfiloCollaborazione;
  38. import org.openspcoop2.core.tracciamento.constants.TipoTempo;
  39. import org.openspcoop2.protocol.sdk.constants.Inoltro;
  40. import org.openspcoop2.protocol.sdk.constants.LivelloRilevanza;
  41. import org.openspcoop2.protocol.sdk.constants.ProfiloDiCollaborazione;
  42. import org.openspcoop2.protocol.sdk.constants.TipoOraRegistrazione;
  43. import org.openspcoop2.utils.date.DateManager;

  44. /**
  45.  * Classe utilizzata per rappresentare una Busta.
  46.  *
  47.  * @author Poli Andrea (apoli@link.it)
  48.  * @author Nardi Lorenzo
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  */

  52. public class Busta implements java.io.Serializable {

  53.     private static final long serialVersionUID = 1L;

  54.    
  55.     // busta
  56.     private org.openspcoop2.core.tracciamento.Busta busta;
  57.    
  58.  
  59.     // servizio [info-richiedente]
  60.     protected String tipoServizioRichiedenteBustaDiServizio;
  61.     protected String servizioRichiedenteBustaDiServizio;
  62.     protected Integer versioneServizioRichiedenteBustaDiServizio;

  63.     // azione [info-richiedente]
  64.     protected String azioneRichiedenteBustaDiServizio;
  65.    
  66.     // identificativi [info-richiedente]
  67.     protected String riferimentoMsgBustaRichiedenteServizio;
  68.    
  69.     // ListaEccezioni
  70.     protected List<Eccezione> listaEccezioni = new ArrayList<>();
  71.    
  72.     // ListaRiscontri
  73.     protected List<Riscontro> listaRiscontri = new ArrayList<>();
  74.    
  75.     // ListaTrasmissioni
  76.     protected List<Trasmissione> listaTrasmissioni = new ArrayList<>();
  77.    
  78.     public Busta(String protocollo){
  79.        
  80.         this.busta = new org.openspcoop2.core.tracciamento.Busta();
  81.        
  82.         this.setSequenza(-1);
  83.         this.setProtocollo(protocollo);
  84.     }

  85.     public Busta(IProtocolFactory<?> protocolFactory,Servizio infoServizio, IDSoggetto mittente, IDSoggetto destinatario, String id, boolean generateListaTrasmissione) throws ProtocolException {
  86.        
  87.         this.busta = new org.openspcoop2.core.tracciamento.Busta();
  88.        
  89.         this.setSequenza(-1);
  90.        
  91.         if(infoServizio!=null){
  92.             this.setProfiloDiCollaborazione(infoServizio.getProfiloDiCollaborazione());
  93.             if(infoServizio.getProfiloDiCollaborazione()!=null){
  94.                 this.setProfiloDiCollaborazioneValue(protocolFactory.createTraduttore().toString(infoServizio.getProfiloDiCollaborazione()));
  95.             }
  96.             this.setConfermaRicezione(infoServizio.getConfermaRicezione());
  97.             this.setScadenza(infoServizio.getScadenza());
  98.             if(infoServizio.getIDServizio()!=null){
  99.                 this.setTipoServizio(infoServizio.getIDServizio().getTipo());
  100.                 this.setServizio(infoServizio.getIDServizio().getNome());
  101.                 this.setVersioneServizio(infoServizio.getIDServizio().getVersione());
  102.                 this.setAzione(infoServizio.getIDServizio().getAzione());
  103.             }
  104.             this.setTipoServizioCorrelato(infoServizio.getTipoServizioCorrelato());
  105.             this.setServizioCorrelato(infoServizio.getServizioCorrelato());
  106.             if(infoServizio.getInoltro()!=null){
  107.                 this.setInoltro(infoServizio.getInoltro());
  108.                 this.setInoltroValue(protocolFactory.createTraduttore().toString(infoServizio.getInoltro()));
  109.             }
  110.         }
  111.        
  112.         if(mittente!=null){
  113.             this.setTipoMittente(mittente.getTipo());
  114.             this.setMittente(mittente.getNome());
  115.             this.setIdentificativoPortaMittente(mittente.getCodicePorta());
  116.         }
  117.        
  118.         if(destinatario!=null){
  119.             this.setTipoDestinatario(destinatario.getTipo());
  120.             this.setDestinatario(destinatario.getNome());
  121.             this.setIdentificativoPortaDestinatario(destinatario.getCodicePorta());
  122.         }
  123.        
  124.         this.setID(id);
  125.         if(protocolFactory!=null){
  126.             this.setProtocollo(protocolFactory.getProtocol());
  127.         }
  128.        
  129.         if(generateListaTrasmissione){
  130.             // aggiunto lista trasmissione
  131.             if(this.sizeListaTrasmissioni()<=0){
  132.                 Trasmissione trasmissione = new Trasmissione();
  133.                
  134.                 if(this.busta.getMittente()!=null){
  135.                     if(this.busta.getMittente().getIdentificativo()!=null){
  136.                         trasmissione.setTipoOrigine(this.busta.getMittente().getIdentificativo().getTipo());
  137.                         trasmissione.setOrigine(this.busta.getMittente().getIdentificativo().getBase());
  138.                     }
  139.                     trasmissione.setIdentificativoPortaOrigine(this.busta.getMittente().getIdentificativoPorta());
  140.                     trasmissione.setIndirizzoOrigine(this.busta.getMittente().getIndirizzo());
  141.                 }
  142.                
  143.                 if(this.busta.getDestinatario()!=null){
  144.                     if(this.busta.getDestinatario().getIdentificativo()!=null){
  145.                         trasmissione.setTipoDestinazione(this.busta.getDestinatario().getIdentificativo().getTipo());
  146.                         trasmissione.setDestinazione(this.busta.getDestinatario().getIdentificativo().getBase());
  147.                     }
  148.                     trasmissione.setIdentificativoPortaDestinazione(this.busta.getDestinatario().getIdentificativoPorta());
  149.                     trasmissione.setIndirizzoDestinazione(this.busta.getDestinatario().getIndirizzo());
  150.                 }
  151.                
  152.                 this.addTrasmissione(trasmissione);
  153.             }
  154.         }
  155.     }
  156.    
  157.     public Busta(org.openspcoop2.core.tracciamento.Busta busta){
  158.         this.busta = busta;
  159.        
  160.         // eccezioni
  161.         if(busta.getEccezioni()!=null && busta.getEccezioni().sizeEccezioneList()>0){
  162.             for (org.openspcoop2.core.tracciamento.Eccezione eccezione : busta.getEccezioni().getEccezioneList()) {
  163.                 this.addEccezione(new Eccezione(eccezione),false);
  164.             }
  165.         }
  166.        
  167.         // riscontri
  168.         if(busta.getRiscontri()!=null && busta.getRiscontri().sizeRiscontroList()>0){
  169.             for (org.openspcoop2.core.tracciamento.Riscontro riscontro : busta.getRiscontri().getRiscontroList()) {
  170.                 this.addRiscontro(new Riscontro(riscontro),false);
  171.             }
  172.         }
  173.        
  174.         // trasmissioni
  175.         if(busta.getTrasmissioni()!=null && busta.getTrasmissioni().sizeTrasmissioneList()>0){
  176.             for (org.openspcoop2.core.tracciamento.Trasmissione trasmissione : busta.getTrasmissioni().getTrasmissioneList()) {
  177.                 this.addTrasmissione(new Trasmissione(trasmissione),false);
  178.             }
  179.         }
  180.     }

  181.    

  182.    
  183.     // base
  184.    
  185.     public org.openspcoop2.core.tracciamento.Busta getBusta() {
  186.         return this.busta;
  187.     }
  188.     public void setBusta(org.openspcoop2.core.tracciamento.Busta busta) {
  189.         this.busta = busta;
  190.        
  191.         // eccezioni
  192.         if(busta.getEccezioni()!=null && busta.getEccezioni().sizeEccezioneList()>0)
  193.         for (org.openspcoop2.core.tracciamento.Eccezione eccezione : busta.getEccezioni().getEccezioneList()) {
  194.             this.addEccezione(new Eccezione(eccezione),false);
  195.         }
  196.        
  197.         // riscontri
  198.         if(busta.getRiscontri()!=null && busta.getRiscontri().sizeRiscontroList()>0)
  199.         for (org.openspcoop2.core.tracciamento.Riscontro riscontro : busta.getRiscontri().getRiscontroList()) {
  200.             this.addRiscontro(new Riscontro(riscontro),false);
  201.         }
  202.        
  203.         // trasmissioni
  204.         if(busta.getTrasmissioni()!=null && busta.getTrasmissioni().sizeTrasmissioneList()>0)
  205.         for (org.openspcoop2.core.tracciamento.Trasmissione trasmissione : busta.getTrasmissioni().getTrasmissioneList()) {
  206.             this.addTrasmissione(new Trasmissione(trasmissione),false);
  207.         }
  208.     }
  209.    
  210.    
  211.    
  212.     // id  [Wrapper]
  213.    
  214.     public Long getId() {
  215.         return this.busta.getId();
  216.     }
  217.     public void setId(Long id) {
  218.         this.busta.setId(id);
  219.     }
  220.    
  221.    
  222.    
  223.    
  224.    
  225.     // mittente [Wrapper]
  226.        
  227.     public String getMittente() {
  228.         if(this.busta.getMittente()!=null && this.busta.getMittente().getIdentificativo()!=null)
  229.             return this.busta.getMittente().getIdentificativo().getBase();
  230.         else
  231.             return null;
  232.     }
  233.     public void setMittente(String value) {
  234.         if(value!=null){
  235.             if(this.busta.getMittente()==null){
  236.                 this.busta.setMittente(new Soggetto());
  237.             }
  238.             if(this.busta.getMittente().getIdentificativo()==null){
  239.                 this.busta.getMittente().setIdentificativo(new SoggettoIdentificativo());
  240.             }
  241.             this.busta.getMittente().getIdentificativo().setBase(value);
  242.         }
  243.         else{
  244.             if(this.busta.getMittente()!=null){
  245.                 if(this.busta.getMittente().getIdentificativo()!=null){
  246.                     if(this.busta.getMittente().getIdentificativo().getTipo()==null){
  247.                         this.busta.getMittente().setIdentificativo(null);
  248.                     }
  249.                     else{
  250.                         this.busta.getMittente().getIdentificativo().setBase(null);
  251.                     }  
  252.                 }
  253.                 if(this.busta.getMittente().getIdentificativo()==null &&
  254.                         this.busta.getMittente().getIdentificativoPorta()==null &&
  255.                         this.busta.getMittente().getIndirizzo()==null){
  256.                     this.busta.setMittente(null);
  257.                 }
  258.             }
  259.         }
  260.     }
  261.    
  262.     public String getTipoMittente() {
  263.         if(this.busta.getMittente()!=null && this.busta.getMittente().getIdentificativo()!=null)
  264.             return this.busta.getMittente().getIdentificativo().getTipo();
  265.         else
  266.             return null;
  267.     }
  268.     public void setTipoMittente(String value) {
  269.         if(value!=null){
  270.             if(this.busta.getMittente()==null){
  271.                 this.busta.setMittente(new Soggetto());
  272.             }
  273.             if(this.busta.getMittente().getIdentificativo()==null){
  274.                 this.busta.getMittente().setIdentificativo(new SoggettoIdentificativo());
  275.             }
  276.             this.busta.getMittente().getIdentificativo().setTipo(value);
  277.         }
  278.         else{
  279.             if(this.busta.getMittente()!=null){
  280.                 if(this.busta.getMittente().getIdentificativo()!=null){
  281.                     if(this.busta.getMittente().getIdentificativo().getBase()==null){
  282.                         this.busta.getMittente().setIdentificativo(null);
  283.                     }
  284.                     else{
  285.                         this.busta.getMittente().getIdentificativo().setTipo(null);
  286.                     }  
  287.                 }
  288.                 if(this.busta.getMittente().getIdentificativo()==null &&
  289.                         this.busta.getMittente().getIdentificativoPorta()==null &&
  290.                         this.busta.getMittente().getIndirizzo()==null){
  291.                     this.busta.setMittente(null);
  292.                 }
  293.             }
  294.         }
  295.     }

  296.     public String getIdentificativoPortaMittente() {
  297.         if(this.busta.getMittente()!=null)
  298.             return this.busta.getMittente().getIdentificativoPorta();
  299.         else
  300.             return null;
  301.     }

  302.     public void setIdentificativoPortaMittente(String identificativoPortaMittente) {
  303.         if(identificativoPortaMittente!=null){
  304.             if(this.busta.getMittente()==null){
  305.                 this.busta.setMittente(new Soggetto());
  306.             }
  307.             this.busta.getMittente().setIdentificativoPorta(identificativoPortaMittente);
  308.         }
  309.         else{
  310.             if(this.busta.getMittente()!=null){
  311.                 this.busta.getMittente().setIdentificativoPorta(null);
  312.                 if(this.busta.getMittente().getIdentificativo()==null &&
  313.                         this.busta.getMittente().getIdentificativoPorta()==null &&
  314.                         this.busta.getMittente().getIndirizzo()==null){
  315.                     this.busta.setMittente(null);
  316.                 }
  317.             }
  318.         }
  319.     }
  320.    
  321.     public String getIndirizzoMittente() {
  322.         if(this.busta.getMittente()!=null)
  323.             return this.busta.getMittente().getIndirizzo();
  324.         else
  325.             return null;
  326.     }
  327.     public void setIndirizzoMittente(String value) {
  328.         if(value!=null){
  329.             if(this.busta.getMittente()==null){
  330.                 this.busta.setMittente(new Soggetto());
  331.             }
  332.             this.busta.getMittente().setIndirizzo(value);
  333.         }
  334.         else{
  335.             if(this.busta.getMittente()!=null){
  336.                 this.busta.getMittente().setIndirizzo(null);
  337.                 if(this.busta.getMittente().getIdentificativo()==null &&
  338.                         this.busta.getMittente().getIdentificativoPorta()==null &&
  339.                         this.busta.getMittente().getIndirizzo()==null){
  340.                     this.busta.setMittente(null);
  341.                 }
  342.             }
  343.         }
  344.     }
  345.    
  346.    
  347.    
  348.    
  349.     // destinatario [Wrapper]
  350.    
  351.     public String getDestinatario() {
  352.         if(this.busta.getDestinatario()!=null && this.busta.getDestinatario().getIdentificativo()!=null)
  353.             return this.busta.getDestinatario().getIdentificativo().getBase();
  354.         else
  355.             return null;
  356.     }
  357.     public void setDestinatario(String value) {
  358.         if(value!=null){
  359.             if(this.busta.getDestinatario()==null){
  360.                 this.busta.setDestinatario(new Soggetto());
  361.             }
  362.             if(this.busta.getDestinatario().getIdentificativo()==null){
  363.                 this.busta.getDestinatario().setIdentificativo(new SoggettoIdentificativo());
  364.             }
  365.             this.busta.getDestinatario().getIdentificativo().setBase(value);
  366.         }
  367.         else{
  368.             if(this.busta.getDestinatario()!=null){
  369.                 if(this.busta.getDestinatario().getIdentificativo()!=null){
  370.                     if(this.busta.getDestinatario().getIdentificativo().getTipo()==null){
  371.                         this.busta.getDestinatario().setIdentificativo(null);
  372.                     }
  373.                     else{
  374.                         this.busta.getDestinatario().getIdentificativo().setBase(null);
  375.                     }  
  376.                 }
  377.                 if(this.busta.getDestinatario().getIdentificativo()==null &&
  378.                         this.busta.getDestinatario().getIdentificativoPorta()==null &&
  379.                         this.busta.getDestinatario().getIndirizzo()==null){
  380.                     this.busta.setDestinatario(null);
  381.                 }
  382.             }
  383.         }
  384.     }

  385.     public String getTipoDestinatario() {
  386.         if(this.busta.getDestinatario()!=null && this.busta.getDestinatario().getIdentificativo()!=null)
  387.             return this.busta.getDestinatario().getIdentificativo().getTipo();
  388.         else
  389.             return null;
  390.     }
  391.     public void setTipoDestinatario(String value) {
  392.         if(value!=null){
  393.             if(this.busta.getDestinatario()==null){
  394.                 this.busta.setDestinatario(new Soggetto());
  395.             }
  396.             if(this.busta.getDestinatario().getIdentificativo()==null){
  397.                 this.busta.getDestinatario().setIdentificativo(new SoggettoIdentificativo());
  398.             }
  399.             this.busta.getDestinatario().getIdentificativo().setTipo(value);
  400.         }else{
  401.             if(this.busta.getDestinatario()!=null){
  402.                 if(this.busta.getDestinatario().getIdentificativo()!=null){
  403.                     if(this.busta.getDestinatario().getIdentificativo().getBase()==null){
  404.                         this.busta.getDestinatario().setIdentificativo(null);
  405.                     }
  406.                     else{
  407.                         this.busta.getDestinatario().getIdentificativo().setTipo(null);
  408.                     }  
  409.                 }
  410.                 if(this.busta.getDestinatario().getIdentificativo()==null &&
  411.                         this.busta.getDestinatario().getIdentificativoPorta()==null &&
  412.                         this.busta.getDestinatario().getIndirizzo()==null){
  413.                     this.busta.setDestinatario(null);
  414.                 }
  415.             }
  416.         }
  417.     }
  418.    
  419.     public String getIdentificativoPortaDestinatario() {
  420.         if(this.busta.getDestinatario()!=null)
  421.             return this.busta.getDestinatario().getIdentificativoPorta();
  422.         else
  423.             return null;
  424.     }

  425.     public void setIdentificativoPortaDestinatario(
  426.             String identificativoPortaDestinatario) {
  427.         if(identificativoPortaDestinatario!=null){
  428.             if(this.busta.getDestinatario()==null){
  429.                 this.busta.setDestinatario(new Soggetto());
  430.             }
  431.             this.busta.getDestinatario().setIdentificativoPorta(identificativoPortaDestinatario);
  432.         }
  433.         else{
  434.             if(this.busta.getDestinatario()!=null){
  435.                 this.busta.getDestinatario().setIdentificativoPorta(null);
  436.                 if(this.busta.getDestinatario().getIdentificativo()==null &&
  437.                         this.busta.getDestinatario().getIdentificativoPorta()==null &&
  438.                         this.busta.getDestinatario().getIndirizzo()==null){
  439.                     this.busta.setDestinatario(null);
  440.                 }
  441.             }
  442.         }
  443.     }
  444.    
  445.     public String getIndirizzoDestinatario() {
  446.         if(this.busta.getDestinatario()!=null)
  447.             return this.busta.getDestinatario().getIndirizzo();
  448.         else
  449.             return null;
  450.     }
  451.     public void setIndirizzoDestinatario(String value) {
  452.         if(value!=null){
  453.             if(this.busta.getDestinatario()==null){
  454.                 this.busta.setDestinatario(new Soggetto());
  455.             }
  456.             this.busta.getDestinatario().setIndirizzo(value);
  457.         }else{
  458.             if(this.busta.getDestinatario()!=null){
  459.                 this.busta.getDestinatario().setIndirizzo(null);
  460.                 if(this.busta.getDestinatario().getIdentificativo()==null &&
  461.                         this.busta.getDestinatario().getIdentificativoPorta()==null &&
  462.                         this.busta.getDestinatario().getIndirizzo()==null){
  463.                     this.busta.setDestinatario(null);
  464.                 }
  465.             }
  466.         }
  467.     }

  468.    
  469.    
  470.     // profilo di collaborazione [Wrapper]
  471.    
  472.     public ProfiloDiCollaborazione getProfiloDiCollaborazione() {
  473.         if(this.busta.getProfiloCollaborazione()!=null && this.busta.getProfiloCollaborazione().getTipo()!=null){
  474.             switch (this.busta.getProfiloCollaborazione().getTipo()) {
  475.             case ONEWAY:
  476.                 return ProfiloDiCollaborazione.ONEWAY;
  477.             case SINCRONO:
  478.                 return ProfiloDiCollaborazione.SINCRONO;
  479.             case ASINCRONO_ASIMMETRICO:
  480.                 return ProfiloDiCollaborazione.ASINCRONO_ASIMMETRICO;
  481.             case ASINCRONO_SIMMETRICO:
  482.                 return ProfiloDiCollaborazione.ASINCRONO_SIMMETRICO;
  483.             case SCONOSCIUTO:
  484.                 return ProfiloDiCollaborazione.UNKNOWN;
  485.             }
  486.         }
  487.         return null;
  488.     }
  489.     public void setProfiloDiCollaborazione(ProfiloDiCollaborazione value) {
  490.         if(value!=null){
  491.             if(this.busta.getProfiloCollaborazione()==null){
  492.                 this.busta.setProfiloCollaborazione(new ProfiloCollaborazione());
  493.             }
  494.             switch (value) {
  495.             case ONEWAY:
  496.                 this.busta.getProfiloCollaborazione().setTipo(TipoProfiloCollaborazione.ONEWAY);
  497.                 break;
  498.             case SINCRONO:
  499.                 this.busta.getProfiloCollaborazione().setTipo(TipoProfiloCollaborazione.SINCRONO);
  500.                 break;
  501.             case ASINCRONO_ASIMMETRICO:
  502.                 this.busta.getProfiloCollaborazione().setTipo(TipoProfiloCollaborazione.ASINCRONO_ASIMMETRICO);
  503.                 break;
  504.             case ASINCRONO_SIMMETRICO:
  505.                 this.busta.getProfiloCollaborazione().setTipo(TipoProfiloCollaborazione.ASINCRONO_SIMMETRICO);
  506.                 break;
  507.             case UNKNOWN:
  508.                 this.busta.getProfiloCollaborazione().setTipo(TipoProfiloCollaborazione.SCONOSCIUTO);
  509.                 break;
  510.             }
  511.         }
  512.         else{
  513.             if(this.busta.getProfiloCollaborazione()!=null){
  514.                 if(this.busta.getProfiloCollaborazione().getBase()==null){
  515.                     this.busta.setProfiloCollaborazione(null);
  516.                 }
  517.                 else{
  518.                     this.busta.getProfiloCollaborazione().setTipo(null);
  519.                 }
  520.             }
  521.         }
  522.        
  523.     }
  524.    
  525.     public void setProfiloDiCollaborazione(ProfiloDiCollaborazione profiloDiCollaborazione, String value) {
  526.         this.setProfiloDiCollaborazione(profiloDiCollaborazione);
  527.         this.setProfiloDiCollaborazioneValue(value);
  528.     }
  529.    
  530.     public String getProfiloDiCollaborazioneValue() {
  531.         if(this.busta.getProfiloCollaborazione()!=null){
  532.             return this.busta.getProfiloCollaborazione().getBase();
  533.         }
  534.         return null;
  535.     }
  536.     public void setProfiloDiCollaborazioneValue(String profiloDiCollaborazioneValue) {
  537.         if(profiloDiCollaborazioneValue!=null){
  538.             if(this.busta.getProfiloCollaborazione()==null){
  539.                 this.busta.setProfiloCollaborazione(new ProfiloCollaborazione());
  540.             }
  541.             this.busta.getProfiloCollaborazione().setBase(profiloDiCollaborazioneValue);
  542.         }else{
  543.             if(this.busta.getProfiloCollaborazione()!=null){
  544.                 if(this.busta.getProfiloCollaborazione().getTipo()==null){
  545.                     this.busta.setProfiloCollaborazione(null);
  546.                 }
  547.                 else{
  548.                     this.busta.getProfiloCollaborazione().setBase(null);
  549.                 }
  550.             }
  551.         }
  552.     }
  553.    
  554.     public String getServizioCorrelato() {
  555.         if(this.busta.getServizioCorrelato()!=null){
  556.             return this.busta.getServizioCorrelato().getBase();
  557.         }
  558.         return null;
  559.     }
  560.     public void setServizioCorrelato(String value) {
  561.         if(value!=null){
  562.             if(this.busta.getServizioCorrelato()==null){
  563.                 this.busta.setServizioCorrelato(new org.openspcoop2.core.tracciamento.Servizio());
  564.             }
  565.             this.busta.getServizioCorrelato().setBase(value);
  566.         }else{
  567.             if(this.busta.getServizioCorrelato()!=null){
  568.                 this.busta.getServizioCorrelato().setBase(null);
  569.                 if(this.busta.getServizioCorrelato().getTipo()==null &&
  570.                         (this.busta.getServizioCorrelato().getVersione()==null || this.busta.getServizioCorrelato().getVersione()==1)){
  571.                     this.busta.setServizioCorrelato(null);
  572.                 }
  573.             }
  574.         }
  575.     }
  576.    
  577.     public String getTipoServizioCorrelato() {
  578.         if(this.busta.getServizioCorrelato()!=null){
  579.             return this.busta.getServizioCorrelato().getTipo();
  580.         }
  581.         return null;
  582.     }
  583.     public void setTipoServizioCorrelato(String value) {
  584.         if(value!=null){
  585.             if(this.busta.getServizioCorrelato()==null){
  586.                 this.busta.setServizioCorrelato(new org.openspcoop2.core.tracciamento.Servizio());
  587.             }
  588.             this.busta.getServizioCorrelato().setTipo(value);
  589.         }else{
  590.             if(this.busta.getServizioCorrelato()!=null){
  591.                 this.busta.getServizioCorrelato().setTipo(null);
  592.                 if(this.busta.getServizioCorrelato().getBase()==null &&
  593.                         (this.busta.getServizioCorrelato().getVersione()==null || this.busta.getServizioCorrelato().getVersione()==1)){
  594.                     this.busta.setServizioCorrelato(null);
  595.                 }
  596.             }
  597.         }
  598.     }
  599.    
  600.     public Integer getVersioneServizioCorrelato() {
  601.         if(this.busta.getServizioCorrelato()!=null){
  602.             return this.busta.getServizioCorrelato().getVersione();
  603.         }
  604.         return null;
  605.     }
  606.     public void setVersioneServizioCorrelato(Integer value) {
  607.         if(value!=null){
  608.             if(this.busta.getServizioCorrelato()==null){
  609.                 this.busta.setServizioCorrelato(new org.openspcoop2.core.tracciamento.Servizio());
  610.             }
  611.             this.busta.getServizioCorrelato().setVersione(value);
  612.         }else{
  613.             if(this.busta.getServizioCorrelato()!=null){
  614.                 this.busta.getServizioCorrelato().setVersione(null);
  615.                 if(this.busta.getServizioCorrelato().getBase()==null &&
  616.                         this.busta.getServizioCorrelato().getTipo()==null){
  617.                     this.busta.setServizioCorrelato(null);
  618.                 }
  619.             }
  620.         }
  621.     }
  622.    

  623.    
  624.    
  625.     // collaborazione [Wrapper]
  626.    
  627.     public String getCollaborazione() {
  628.         return this.busta.getCollaborazione();
  629.     }
  630.     public void setCollaborazione(String value) {
  631.         this.busta.setCollaborazione(value);
  632.     }
  633.    
  634.    
  635.        
  636.     // servizio
  637.    
  638.     public String getServizio() {
  639.         if(this.busta.getServizio()!=null){
  640.             return this.busta.getServizio().getBase();
  641.         }
  642.         return null;
  643.     }
  644.     public void setServizio(String value) {
  645.         if(value!=null){
  646.             if(this.busta.getServizio()==null){
  647.                 this.busta.setServizio(new org.openspcoop2.core.tracciamento.Servizio());
  648.             }
  649.             this.busta.getServizio().setBase(value);
  650.         }else{
  651.             if(this.busta.getServizio()!=null){
  652.                 this.busta.getServizio().setBase(null);
  653.                 if(this.busta.getServizio().getTipo()==null &&
  654.                         (this.busta.getServizio().getVersione()==null || this.busta.getServizio().getVersione()==1)){
  655.                     this.busta.setServizio(null);
  656.                 }
  657.             }
  658.         }
  659.     }

  660.     public String getTipoServizio() {
  661.         if(this.busta.getServizio()!=null){
  662.             return this.busta.getServizio().getTipo();
  663.         }
  664.         return null;
  665.     }
  666.     public void setTipoServizio(String value) {
  667.         if(value!=null){
  668.             if(this.busta.getServizio()==null){
  669.                 this.busta.setServizio(new org.openspcoop2.core.tracciamento.Servizio());
  670.             }
  671.             this.busta.getServizio().setTipo(value);
  672.         }else{
  673.             if(this.busta.getServizio()!=null){
  674.                 this.busta.getServizio().setTipo(null);
  675.                 if(this.busta.getServizio().getBase()==null &&
  676.                         (this.busta.getServizio().getVersione()==null || this.busta.getServizio().getVersione()==1)){
  677.                     this.busta.setServizio(null);
  678.                 }
  679.             }
  680.         }
  681.     }

  682.     public Integer getVersioneServizio() {
  683.         if(this.busta.getServizio()!=null && this.busta.getServizio().getVersione()!=null){
  684.             return this.busta.getServizio().getVersione();
  685.         }
  686.         return 1;
  687.     }
  688.     public void setVersioneServizio(Integer versioneServizio) {
  689.         if(this.busta.getServizio()==null){
  690.             this.busta.setServizio(new org.openspcoop2.core.tracciamento.Servizio());
  691.         }
  692.         this.busta.getServizio().setVersione(versioneServizio);
  693.     }
  694.    
  695.    
  696.    
  697.     // servizio [info-richiedente]
  698.    
  699.     public String getTipoServizioRichiedenteBustaDiServizio() {
  700.         return this.tipoServizioRichiedenteBustaDiServizio;
  701.     }
  702.     public void setTipoServizioRichiedenteBustaDiServizio(String value) {
  703.         this.tipoServizioRichiedenteBustaDiServizio = value;
  704.     }
  705.    
  706.     public String getServizioRichiedenteBustaDiServizio() {
  707.         return this.servizioRichiedenteBustaDiServizio;
  708.     }
  709.     public void setServizioRichiedenteBustaDiServizio(String value) {
  710.         this.servizioRichiedenteBustaDiServizio = value;
  711.     }
  712.    
  713.     public Integer getVersioneServizioRichiedenteBustaDiServizio() {
  714.         return this.versioneServizioRichiedenteBustaDiServizio;
  715.     }

  716.     public void setVersioneServizioRichiedenteBustaDiServizio(Integer versioneServizioRichiedenteBustaDiServizio) {
  717.         this.versioneServizioRichiedenteBustaDiServizio = versioneServizioRichiedenteBustaDiServizio;
  718.     }
  719.    
  720.    
  721.    
  722.     // azione [wrapped]
  723.        
  724.     public String getAzione() {
  725.         return this.busta.getAzione();
  726.     }
  727.     public void setAzione(String value) {
  728.         this.busta.setAzione(value);
  729.     }
  730.    
  731.    
  732.    
  733.     // azione [info-richiedente]
  734.    
  735.     public String getAzioneRichiedenteBustaDiServizio() {
  736.         return this.azioneRichiedenteBustaDiServizio;
  737.     }
  738.     public void setAzioneRichiedenteBustaDiServizio(String value) {
  739.         this.azioneRichiedenteBustaDiServizio = value;
  740.     }
  741.    
  742.    
  743.    
  744.    
  745.     // identificativi [wrapped]
  746.    
  747.     public String getID() {
  748.         return this.busta.getIdentificativo();
  749.     }
  750.     public void setID(String value) {
  751.         this.busta.setIdentificativo(value);
  752.     }
  753.    
  754.     public String getRiferimentoMessaggio() {
  755.         return this.busta.getRiferimentoMessaggio();
  756.     }
  757.     public void setRiferimentoMessaggio(String value) {
  758.         this.busta.setRiferimentoMessaggio(value);
  759.     }

  760.    
  761.    
  762.     // identificativi [info-richiedente]
  763.    
  764.     public String getRiferimentoMsgBustaRichiedenteServizio() {
  765.         return this.riferimentoMsgBustaRichiedenteServizio;
  766.     }
  767.     public void setRiferimentoMsgBustaRichiedenteServizio(String value) {
  768.         this.riferimentoMsgBustaRichiedenteServizio = value;
  769.     }
  770.    

  771.    
  772.     // date [wrapped]
  773.    
  774.     public TipoOraRegistrazione getTipoOraRegistrazione() {
  775.         if(this.busta.getOraRegistrazione()!=null &&
  776.                 this.busta.getOraRegistrazione().getSorgente()!=null &&
  777.                 this.busta.getOraRegistrazione().getSorgente().getTipo()!=null){
  778.             switch (this.busta.getOraRegistrazione().getSorgente().getTipo()) {
  779.             case LOCALE:
  780.                 return TipoOraRegistrazione.LOCALE;
  781.             case SINCRONIZZATO:
  782.                 return TipoOraRegistrazione.SINCRONIZZATO;
  783.             case SCONOSCIUTO:
  784.                 return TipoOraRegistrazione.UNKNOWN;
  785.             }
  786.         }
  787.         return null;
  788.     }
  789.     protected void setTipoOraRegistrazione(TipoOraRegistrazione tipoOraRegistrazione) {
  790.         if(tipoOraRegistrazione!=null){
  791.             if(this.busta.getOraRegistrazione()==null){
  792.                 this.busta.setOraRegistrazione(new Data());
  793.             }
  794.             if(this.busta.getOraRegistrazione().getSorgente()==null){
  795.                 this.busta.getOraRegistrazione().setSorgente(new TipoData());
  796.             }
  797.             switch (tipoOraRegistrazione) {
  798.             case LOCALE:
  799.                 this.busta.getOraRegistrazione().getSorgente().setTipo(TipoTempo.LOCALE);
  800.                 break;
  801.             case SINCRONIZZATO:
  802.                 this.busta.getOraRegistrazione().getSorgente().setTipo(TipoTempo.SINCRONIZZATO);
  803.                 break;
  804.             case UNKNOWN:
  805.                 this.busta.getOraRegistrazione().getSorgente().setTipo(TipoTempo.SCONOSCIUTO);
  806.                 break;
  807.             }
  808.         }
  809.         else {
  810.             if(this.busta.getOraRegistrazione()!=null){
  811.                 if(this.busta.getOraRegistrazione().getSorgente()!=null){
  812.                     if(this.busta.getOraRegistrazione().getSorgente().getBase()==null){
  813.                         this.busta.getOraRegistrazione().setSorgente(null);
  814.                     }
  815.                     else{
  816.                         this.busta.getOraRegistrazione().getSorgente().setTipo(null);
  817.                     }  
  818.                 }
  819.                 if(this.busta.getOraRegistrazione().getSorgente()==null && this.busta.getOraRegistrazione().getDateTime()==null){
  820.                     this.busta.setOraRegistrazione(null);
  821.                 }
  822.             }
  823.         }
  824.     }
  825.    
  826.     public void setTipoOraRegistrazione(TipoOraRegistrazione tipo, String value) {
  827.         this.setTipoOraRegistrazione(tipo);
  828.         this.setTipoOraRegistrazioneValue(value);
  829.     }

  830.     public String getTipoOraRegistrazioneValue() {
  831.         if(this.busta.getOraRegistrazione()!=null &&
  832.                 this.busta.getOraRegistrazione().getSorgente()!=null){
  833.             return this.busta.getOraRegistrazione().getSorgente().getBase();
  834.         }
  835.         return null;
  836.     }
  837.     public void setTipoOraRegistrazioneValue(String tipoOraRegistrazioneValue) {
  838.         if(tipoOraRegistrazioneValue!=null){
  839.             if(this.busta.getOraRegistrazione()==null){
  840.                 this.busta.setOraRegistrazione(new Data());
  841.             }
  842.             if(this.busta.getOraRegistrazione().getSorgente()==null){
  843.                 this.busta.getOraRegistrazione().setSorgente(new TipoData());
  844.             }
  845.             this.busta.getOraRegistrazione().getSorgente().setBase(tipoOraRegistrazioneValue);
  846.         }
  847.         else {
  848.             if(this.busta.getOraRegistrazione()!=null){
  849.                 if(this.busta.getOraRegistrazione().getSorgente()!=null){
  850.                     if(this.busta.getOraRegistrazione().getSorgente().getTipo()==null){
  851.                         this.busta.getOraRegistrazione().setSorgente(null);
  852.                     }
  853.                     else{
  854.                         this.busta.getOraRegistrazione().getSorgente().setBase(null);
  855.                     }  
  856.                 }
  857.                 if(this.busta.getOraRegistrazione().getSorgente()==null && this.busta.getOraRegistrazione().getDateTime()==null){
  858.                     this.busta.setOraRegistrazione(null);
  859.                 }
  860.             }
  861.         }
  862.     }
  863.        
  864.     public Date getOraRegistrazione() {
  865.         if(this.busta.getOraRegistrazione()!=null){
  866.             return this.busta.getOraRegistrazione().getDateTime();
  867.         }
  868.         return null;
  869.     }
  870.     public void setOraRegistrazione(Date value) {
  871.         if(value!=null){
  872.             if(this.busta.getOraRegistrazione()==null){
  873.                 this.busta.setOraRegistrazione(new Data());
  874.             }
  875.             this.busta.getOraRegistrazione().setDateTime(value);
  876.         }
  877.         else {
  878.             if(this.busta.getOraRegistrazione()!=null){
  879.                 if(this.busta.getOraRegistrazione().getSorgente()==null){
  880.                     this.busta.setOraRegistrazione(null);
  881.                 }
  882.                 else{
  883.                     this.busta.getOraRegistrazione().setDateTime(null);
  884.                 }
  885.             }
  886.         }
  887.     }

  888.     public Date getScadenza() {
  889.         return this.busta.getScadenza();
  890.     }
  891.     public void setScadenza(Date value) {
  892.         this.busta.setScadenza(value);
  893.     }
  894.    
  895.        
  896.    
  897.    
  898.    
  899.     // profilo di trasmissione [wrapped]

  900.     public boolean isConfermaRicezione() {
  901.         if(this.busta.getProfiloTrasmissione()!=null){
  902.             return this.busta.getProfiloTrasmissione().getConfermaRicezione();
  903.         }
  904.         return false;
  905.     }
  906.     public void setConfermaRicezione(boolean value) {
  907.         if(this.busta.getProfiloTrasmissione()==null){
  908.             this.busta.setProfiloTrasmissione(new ProfiloTrasmissione());
  909.         }
  910.         this.busta.getProfiloTrasmissione().setConfermaRicezione(value);
  911.     }

  912.     public Inoltro getInoltro() {
  913.         if(this.busta.getProfiloTrasmissione()!=null &&
  914.                 this.busta.getProfiloTrasmissione().getInoltro()!=null &&
  915.                 this.busta.getProfiloTrasmissione().getInoltro().getTipo()!=null){
  916.             switch (this.busta.getProfiloTrasmissione().getInoltro().getTipo()) {
  917.             case INOLTRO_CON_DUPLICATI:
  918.                 return Inoltro.CON_DUPLICATI;
  919.             case INOLTRO_SENZA_DUPLICATI:
  920.                 return Inoltro.SENZA_DUPLICATI;
  921.             case SCONOSCIUTO:
  922.                 return Inoltro.UNKNOWN;
  923.             }
  924.         }
  925.         return null;
  926.     }
  927.     protected void setInoltro(Inoltro inoltro) {
  928.         if(inoltro!=null){
  929.             if(this.busta.getProfiloTrasmissione()==null){
  930.                 this.busta.setProfiloTrasmissione(new ProfiloTrasmissione());
  931.             }
  932.             if(this.busta.getProfiloTrasmissione().getInoltro()==null){
  933.                 this.busta.getProfiloTrasmissione().setInoltro(new org.openspcoop2.core.tracciamento.Inoltro());
  934.             }
  935.             switch (inoltro) {
  936.             case CON_DUPLICATI:
  937.                 this.busta.getProfiloTrasmissione().getInoltro().setTipo(TipoInoltro.INOLTRO_CON_DUPLICATI);
  938.                 break;
  939.             case SENZA_DUPLICATI:
  940.                 this.busta.getProfiloTrasmissione().getInoltro().setTipo(TipoInoltro.INOLTRO_SENZA_DUPLICATI);
  941.                 break;
  942.             case UNKNOWN:
  943.                 this.busta.getProfiloTrasmissione().getInoltro().setTipo(TipoInoltro.SCONOSCIUTO);
  944.                 break;
  945.             }
  946.         }
  947.         else{
  948.             if(this.busta.getProfiloTrasmissione()!=null){
  949.                 if(this.busta.getProfiloTrasmissione().getInoltro()!=null){
  950.                     if(this.getBusta().getProfiloTrasmissione().getInoltro().getBase()!=null){
  951.                         this.busta.getProfiloTrasmissione().getInoltro().setTipo(null);
  952.                     }
  953.                     else{
  954.                         this.busta.getProfiloTrasmissione().setInoltro(null);
  955.                     }      
  956.                 }
  957.             }
  958.         }
  959.     }
  960.    
  961.     public void setInoltro(Inoltro inoltro, String value) {
  962.         this.setInoltro(inoltro);
  963.         this.setInoltroValue(value);
  964.     }
  965.    
  966.     public String getInoltroValue() {
  967.         if(this.busta.getProfiloTrasmissione()!=null &&
  968.                 this.busta.getProfiloTrasmissione().getInoltro()!=null){
  969.             return this.busta.getProfiloTrasmissione().getInoltro().getBase();
  970.         }
  971.         return null;
  972.     }
  973.     public void setInoltroValue(String inoltroValue) {
  974.         if(inoltroValue!=null){
  975.             if(this.busta.getProfiloTrasmissione()==null){
  976.                 this.busta.setProfiloTrasmissione(new ProfiloTrasmissione());
  977.             }
  978.             if(this.busta.getProfiloTrasmissione().getInoltro()==null){
  979.                 this.busta.getProfiloTrasmissione().setInoltro(new org.openspcoop2.core.tracciamento.Inoltro());
  980.             }
  981.             this.busta.getProfiloTrasmissione().getInoltro().setBase(inoltroValue);
  982.         }
  983.         else{
  984.             if(this.busta.getProfiloTrasmissione()!=null){
  985.                 if(this.busta.getProfiloTrasmissione().getInoltro()!=null){
  986.                     if(this.getBusta().getProfiloTrasmissione().getInoltro().getTipo()!=null){
  987.                         this.busta.getProfiloTrasmissione().getInoltro().setBase(null);
  988.                     }
  989.                     else{
  990.                         this.busta.getProfiloTrasmissione().setInoltro(null);
  991.                     }      
  992.                 }
  993.             }
  994.         }
  995.     }
  996.    
  997.    
  998.    
  999.    
  1000.     // sequenza [wrapped]
  1001.    
  1002.     public long getSequenza() {
  1003.         if(this.busta.getProfiloTrasmissione()!=null &&
  1004.                 this.busta.getProfiloTrasmissione().getSequenza()!=null){
  1005.             return this.busta.getProfiloTrasmissione().getSequenza();
  1006.         }
  1007.         return -1;
  1008.     }
  1009.     public void setSequenza(long value) {
  1010.         if(value>=0){
  1011.             if(this.busta.getProfiloTrasmissione()==null){
  1012.                 this.busta.setProfiloTrasmissione(new ProfiloTrasmissione());
  1013.             }
  1014.             this.busta.getProfiloTrasmissione().setSequenza(Long.valueOf(value+"").intValue());
  1015.         }
  1016.         else{
  1017.             if(this.busta.getProfiloTrasmissione()!=null){
  1018.                 this.busta.getProfiloTrasmissione().setSequenza(null);
  1019.             }
  1020.         }
  1021.     }




  1022.    
  1023.     // servizi applicativi
  1024.    
  1025.     public String getServizioApplicativoFruitore() {
  1026.         return this.busta.getServizioApplicativoFruitore();
  1027.     }
  1028.     public void setServizioApplicativoFruitore(String servizioApplicativoFruitore) {
  1029.         this.busta.setServizioApplicativoFruitore(servizioApplicativoFruitore);
  1030.     }

  1031.     public String getServizioApplicativoErogatore() {
  1032.         return this.busta.getServizioApplicativoErogatore();
  1033.     }
  1034.     public void setServizioApplicativoErogatore(String servizioApplicativoErogatore) {
  1035.         this.busta.setServizioApplicativoErogatore(servizioApplicativoErogatore);
  1036.     }
  1037.    

  1038.    
  1039.    
  1040.     // protocollo [wrapped]
  1041.    
  1042.     public String getProtocollo() {
  1043.         if(this.busta.getProtocollo()!=null){
  1044.             return this.busta.getProtocollo().getIdentificativo();
  1045.         }
  1046.         return null;
  1047.     }
  1048.     public void setProtocollo(String protocollo) {
  1049.         if(protocollo!=null){
  1050.             if(this.busta.getProtocollo()==null){
  1051.                 this.busta.setProtocollo(new Protocollo());
  1052.             }
  1053.             this.busta.getProtocollo().setIdentificativo(protocollo);
  1054.         }
  1055.         else{
  1056.             if(this.busta.getProtocollo()!=null){
  1057.                 if(this.busta.getProtocollo().sizeProprietaList()<=0){
  1058.                     this.busta.setProtocollo(null);
  1059.                 }
  1060.                 else{
  1061.                     this.busta.getProtocollo().setIdentificativo(null);
  1062.                 }
  1063.             }
  1064.         }
  1065.     }


  1066.    
  1067.    
  1068.     // digest [wrapped]
  1069.    
  1070.     public String getDigest() {
  1071.         return this.busta.getDigest();
  1072.     }
  1073.     public void setDigest(String digest) {
  1074.         this.busta.setDigest(digest);
  1075.     }
  1076.    

  1077.        
  1078.     // properties [wrapped]
  1079.    
  1080.     public void addProperty(String key,String value){
  1081.         // Per evitare nullPointer durante la serializzazione
  1082.         // Non deve essere inserito nemmeno il valore ""
  1083.         if(value!=null && !"".equals(value)){
  1084.             if(this.busta.getProtocollo()==null){
  1085.                 this.busta.setProtocollo(new Protocollo());
  1086.             }
  1087.             Proprieta proprieta = new Proprieta();
  1088.             proprieta.setNome(key);
  1089.             proprieta.setValore(value);
  1090.             this.removeProperty(key); // per evitare doppioni
  1091.             this.busta.getProtocollo().addProprieta(proprieta);
  1092.         }
  1093.     }

  1094.     public int sizeProperties(){
  1095.         if(this.busta.getProtocollo()!=null){
  1096.             return this.busta.getProtocollo().sizeProprietaList();
  1097.         }
  1098.         return 0;
  1099.     }

  1100.     public boolean existsProperty(String key){
  1101.         if(this.busta.getProtocollo()!=null){
  1102.             for (int i = 0; i < this.busta.getProtocollo().sizeProprietaList(); i++) {
  1103.                 Proprieta proprieta = this.busta.getProtocollo().getProprieta(i);
  1104.                 if(proprieta.getNome().equals(key)){
  1105.                     return true;
  1106.                 }
  1107.             }
  1108.         }
  1109.         return false;
  1110.     }
  1111.    
  1112.     public String getProperty(String key){
  1113.         if(this.busta.getProtocollo()!=null){
  1114.             for (int i = 0; i < this.busta.getProtocollo().sizeProprietaList(); i++) {
  1115.                 Proprieta proprieta = this.busta.getProtocollo().getProprieta(i);
  1116.                 if(proprieta.getNome().equals(key)){
  1117.                     return proprieta.getValore();
  1118.                 }
  1119.             }
  1120.         }
  1121.         return null;
  1122.     }

  1123.     public String removeProperty(String key){
  1124.         if(this.busta.getProtocollo()!=null){
  1125.             for (int i = 0; i < this.busta.getProtocollo().sizeProprietaList(); i++) {
  1126.                 Proprieta proprieta = this.busta.getProtocollo().getProprieta(i);
  1127.                 if(proprieta.getNome().equals(key)){
  1128.                     this.busta.getProtocollo().removeProprieta(i);
  1129.                     return proprieta.getValore();
  1130.                 }
  1131.             }
  1132.         }
  1133.         return null;
  1134.     }

  1135.     public String[] getPropertiesValues() {
  1136.         List<String> propertiesValues = new ArrayList<>();
  1137.         if(this.busta.getProtocollo()!=null){
  1138.             for (int i = 0; i < this.busta.getProtocollo().sizeProprietaList(); i++) {
  1139.                 Proprieta proprieta = this.busta.getProtocollo().getProprieta(i);
  1140.                 propertiesValues.add(proprieta.getValore());
  1141.             }
  1142.         }
  1143.         if(propertiesValues.size()>0){
  1144.             return propertiesValues.toArray(new String[1]);
  1145.         }
  1146.         else{
  1147.             return null;
  1148.         }
  1149.     }

  1150.     public String[] getPropertiesNames() {
  1151.         List<String> propertiesValues = new ArrayList<>();
  1152.         if(this.busta.getProtocollo()!=null){
  1153.             for (int i = 0; i < this.busta.getProtocollo().sizeProprietaList(); i++) {
  1154.                 Proprieta proprieta = this.busta.getProtocollo().getProprieta(i);
  1155.                 propertiesValues.add(proprieta.getNome());
  1156.             }
  1157.         }
  1158.         if(propertiesValues.size()>0){
  1159.             return propertiesValues.toArray(new String[1]);
  1160.         }
  1161.         else{
  1162.             return null;
  1163.         }
  1164.     }

  1165.     // Non devono essere usati.
  1166.     // Altrimenti poi se viene effettuato una add o remove sulla lista o hashtable ritornata, la modifica non ha effetto
  1167. //  public void setProperties(Map<String, String> params) {
  1168. //      Enumeration<String> keys = params.keys();
  1169. //      while (keys.hasMoreElements()) {
  1170. //          String key = (String) keys.nextElement();
  1171. //          this.addProperty(key, params.get(key));
  1172. //      }
  1173. //  }
  1174. //
  1175. //  public Map<String, String> getProperties() {
  1176. //      Map<String, String> map = new HashMap<>();
  1177. //      if(this.busta.getProtocollo()!=null){
  1178. //          for (int i = 0; i < this.busta.getProtocollo().sizeProprietaList(); i++) {
  1179. //              Proprieta proprieta = this.busta.getProtocollo().getProprieta(i);
  1180. //              map.put(proprieta.getNome(), proprieta.getValore());
  1181. //          }
  1182. //      }
  1183. //      return map;
  1184. //  }
  1185. //  
  1186. //  public List<Map.Entry<String, String>> getPropertiesAsList(){
  1187. //      List <Map.Entry<String, String>> toRet = new ArrayList<Map.Entry<String, String>>();
  1188. //      toRet.addAll(this.getProperties().entrySet());
  1189. //      return toRet;
  1190. //  }





  1191.    
  1192.     // ListaEccezioni
  1193.        
  1194.     public List<Eccezione> getListaEccezioni() {
  1195.         return this.listaEccezioni;
  1196.     }

  1197.     public int sizeListaEccezioni() {
  1198.         return this.listaEccezioni.size();
  1199.     }

  1200.     public List<Eccezione> cloneListaEccezioni() {
  1201.         if(this.listaEccezioni!=null){
  1202.             List<Eccezione> eccs = new ArrayList<>();
  1203.             for(int i=0; i<this.sizeListaEccezioni(); i++){
  1204.                 eccs.add(this.getEccezione(i).newInstance());
  1205.             }
  1206.             return eccs;
  1207.         }else{
  1208.             return null;
  1209.         }
  1210.     }

  1211.     public Eccezione getEccezione(int index) {
  1212.         return this.listaEccezioni.get( index );
  1213.     }

  1214.     public void addEccezione(Eccezione e) {
  1215.         this.addEccezione(e, true);
  1216.     }
  1217.     private void addEccezione(Eccezione e, boolean addCore) {
  1218.         this.listaEccezioni.add(e);
  1219.         if(addCore){
  1220.             if(this.busta.getEccezioni()==null){
  1221.                 this.busta.setEccezioni(new Eccezioni());
  1222.             }
  1223.             this.busta.getEccezioni().addEccezione(e.getEccezione());
  1224.         }
  1225.     }

  1226.     public Eccezione removeEccezione(int index) {
  1227.         this.busta.getEccezioni().removeEccezione(index);
  1228.         return this.listaEccezioni.remove(index);
  1229.     }

  1230.     public String toStringListaEccezioni(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  1231.         if(this.sizeListaEccezioni()>0){
  1232.             StringBuilder bf = new StringBuilder();
  1233.             for(int i=0; i<this.sizeListaEccezioni(); i++){
  1234.                 if(i>0)
  1235.                     bf.append("\n");
  1236.                 bf.append(this.getEccezione(i).toString(protocolFactory));
  1237.             }
  1238.             return bf.toString();
  1239.         }else{
  1240.             return null;
  1241.         }
  1242.     }

  1243.     public String toStringListaEccezioni_erroriNonGravi(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  1244.         if(this.sizeListaEccezioni()>0){
  1245.             StringBuilder bf = new StringBuilder();
  1246.             for(int i=0; i<this.sizeListaEccezioni(); i++){
  1247.                 if(LivelloRilevanza.isEccezioneLivelloGrave(this.getEccezione(i).getRilevanza()) == false){
  1248.                     if(i>0)
  1249.                         bf.append("\n");
  1250.                     bf.append(this.getEccezione(i).toString(protocolFactory));
  1251.                 }
  1252.             }
  1253.             return bf.toString();
  1254.         }else{
  1255.             return null;
  1256.         }
  1257.     }

  1258.     public String toStringListaEccezioni_erroriGravi(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  1259.         if(this.sizeListaEccezioni()>0){
  1260.             StringBuilder bf = new StringBuilder();
  1261.             for(int i=0; i<this.sizeListaEccezioni(); i++){
  1262.                 if(LivelloRilevanza.isEccezioneLivelloGrave(this.getEccezione(i).getRilevanza())){
  1263.                     if(i>0)
  1264.                         bf.append("\n");
  1265.                     bf.append(this.getEccezione(i).toString(protocolFactory));
  1266.                 }
  1267.             }
  1268.             return bf.toString();
  1269.         }else{
  1270.             return null;
  1271.         }
  1272.     }

  1273.     public boolean containsEccezioniGravi(){
  1274.         for(int i=0; i<this.sizeListaEccezioni(); i++){
  1275.             if(LivelloRilevanza.isEccezioneLivelloGrave(this.getEccezione(i).getRilevanza())){
  1276.                 return true;
  1277.             }
  1278.         }
  1279.         return false;
  1280.     }

  1281.     public static String toStringListaEccezioni(java.util.List<Eccezione> errors, IProtocolFactory<?> protocolFactory) throws ProtocolException{
  1282.         if(errors.size()>0){
  1283.             StringBuilder bf = new StringBuilder();
  1284.             for(int i=0; i<errors.size(); i++){
  1285.                 if(i>0)
  1286.                     bf.append("\n");
  1287.                 bf.append(errors.get(i).toString(protocolFactory));
  1288.             }
  1289.             return bf.toString();
  1290.         }else{
  1291.             return null;
  1292.         }
  1293.     }

  1294.     public static String toStringListaEccezioni_erroriNonGravi(java.util.List<Eccezione> errors, IProtocolFactory<?> protocolFactory) throws ProtocolException{
  1295.         if(errors.size()>0){
  1296.             StringBuilder bf = new StringBuilder();
  1297.             for(int i=0; i<errors.size(); i++){
  1298.                 if(LivelloRilevanza.isEccezioneLivelloGrave(errors.get(i).getRilevanza()) == false){
  1299.                     if(i>0)
  1300.                         bf.append("\n");
  1301.                     bf.append(errors.get(i).toString(protocolFactory));
  1302.                 }
  1303.             }
  1304.             return bf.toString();
  1305.         }else{
  1306.             return null;
  1307.         }
  1308.     }

  1309.     public static String toStringListaEccezioni_erroriGravi(java.util.List<Eccezione> errors, IProtocolFactory<?> protocolFactory) throws ProtocolException{
  1310.         if(errors.size()>0){
  1311.             StringBuilder bf = new StringBuilder();
  1312.             for(int i=0; i<errors.size(); i++){
  1313.                 if(LivelloRilevanza.isEccezioneLivelloGrave(errors.get(i).getRilevanza())){
  1314.                     if(i>0)
  1315.                         bf.append("\n");
  1316.                     bf.append(errors.get(i).toString(protocolFactory));
  1317.                 }
  1318.             }
  1319.             return bf.toString();
  1320.         }else{
  1321.             return null;
  1322.         }
  1323.     }

  1324.     public static boolean containsEccezioniGravi(java.util.List<Eccezione> errors){
  1325.         for(int i=0; i<errors.size(); i++){
  1326.             if(LivelloRilevanza.isEccezioneLivelloGrave(errors.get(i).getRilevanza())){
  1327.                 return true;
  1328.             }
  1329.         }
  1330.         return false;

  1331.     }
  1332.    
  1333.    
  1334.    
  1335.    
  1336.    
  1337.     // ListaRiscontri

  1338.     public List<Riscontro> getListaRiscontri() {
  1339.         if (this.listaRiscontri == null) {
  1340.             this.listaRiscontri = new ArrayList<>();
  1341.         }
  1342.         return this.listaRiscontri;
  1343.     }
  1344.    
  1345.     public int sizeListaRiscontri() {
  1346.         return this.listaRiscontri.size();
  1347.     }  

  1348.     public Riscontro getRiscontro(int index) {
  1349.         return this.listaRiscontri.get( index );
  1350.     }
  1351.    
  1352.     public void addRiscontro(Riscontro r) {
  1353.         this.addRiscontro(r, true);
  1354.     }
  1355.     private void addRiscontro(Riscontro r, boolean addCore) {
  1356.         this.listaRiscontri.add(r);
  1357.         if(addCore){
  1358.             if(this.busta.getRiscontri()==null){
  1359.                 this.busta.setRiscontri(new Riscontri());
  1360.             }
  1361.             this.busta.getRiscontri().addRiscontro(r.getRiscontro());
  1362.         }
  1363.     }
  1364.    
  1365.     public Riscontro removeRiscontro(int index) {
  1366.         this.busta.getRiscontri().removeRiscontro(index);
  1367.         return this.listaRiscontri.remove(index);
  1368.     }
  1369.    
  1370.    
  1371.    
  1372.    
  1373.     // ListaTrasmissioni
  1374.    
  1375.     public List<Trasmissione> getListaTrasmissioni() {
  1376.         if (this.listaTrasmissioni == null) {
  1377.             this.listaTrasmissioni = new ArrayList<>();
  1378.         }
  1379.         return this.listaTrasmissioni;
  1380.     }
  1381.    
  1382.     public int sizeListaTrasmissioni() {
  1383.         return this.listaTrasmissioni.size();
  1384.     }
  1385.    
  1386.     public Trasmissione getTrasmissione(int index) {
  1387.         return this.listaTrasmissioni.get( index );
  1388.     }

  1389.     public void addTrasmissione(Trasmissione t) {
  1390.         this.addTrasmissione(t, true);
  1391.     }
  1392.     private void addTrasmissione(Trasmissione t, boolean addCore) {
  1393.         this.listaTrasmissioni.add(t);
  1394.         if(addCore){
  1395.             if(this.busta.getTrasmissioni()==null){
  1396.                 this.busta.setTrasmissioni(new Trasmissioni());
  1397.             }
  1398.             this.busta.getTrasmissioni().addTrasmissione(t.getTrasmissione());
  1399.         }
  1400.     }

  1401.     public Trasmissione removeTrasmissione(int index) {
  1402.         this.busta.getTrasmissioni().removeTrasmissione(index);
  1403.         return this.listaTrasmissioni.remove(index);
  1404.     }














  1405.     /**
  1406.      * Data una busta, genera la corrispondente busta di risposta
  1407.      * Inverte mittente con destinatario.
  1408.      * Setta una nuova ora di registrazione
  1409.      *
  1410.      * @return una busta utilizzabile come risposta
  1411.      *
  1412.      */
  1413.     public Busta invertiBusta(TipoOraRegistrazione tipoOraRegistrazione, String tipoTempo){
  1414.         Busta bustaHTTPReply = null;
  1415.         bustaHTTPReply = new Busta(this.getProtocollo());

  1416.         bustaHTTPReply.setTipoDestinatario(this.getTipoMittente());
  1417.         bustaHTTPReply.setDestinatario(this.getMittente());
  1418.         bustaHTTPReply.setIdentificativoPortaDestinatario(this.getIdentificativoPortaMittente());
  1419.         bustaHTTPReply.setIndirizzoDestinatario(this.getIndirizzoMittente());

  1420.         bustaHTTPReply.setTipoMittente(this.getTipoDestinatario());
  1421.         bustaHTTPReply.setMittente(this.getDestinatario());
  1422.         bustaHTTPReply.setIndirizzoMittente(this.getIndirizzoDestinatario());
  1423.         bustaHTTPReply.setIdentificativoPortaMittente(this.getIdentificativoPortaDestinatario());

  1424.         bustaHTTPReply.setServizioApplicativoFruitore(this.getServizioApplicativoFruitore()); // lo mantengo, non deve essere invertito

  1425.         Date oraRegistrazione = DateManager.getDate();
  1426.         bustaHTTPReply.setOraRegistrazione(oraRegistrazione);
  1427.         bustaHTTPReply.setTipoOraRegistrazione(tipoOraRegistrazione,tipoTempo);
  1428.         return bustaHTTPReply;
  1429.     }

  1430.     /**
  1431.      * Data una busta, ne ritorna una copia
  1432.      *
  1433.      * @return una busta
  1434.      *
  1435.      */
  1436.     public Busta newInstance(){
  1437.        
  1438.         // Non uso il base clone per far si che venga usato il costruttore new String()
  1439.        
  1440.         Busta clone = null;
  1441.         if(this.getProtocollo()!=null){
  1442.             clone = new Busta(new String(this.getProtocollo()));
  1443.         }else{
  1444.             String pNull = null;
  1445.             clone = new Busta(pNull);
  1446.         }

  1447.         // id
  1448.         clone.setId(this.getId()!=null ? Long.valueOf(this.getId()+"") : null);
  1449.        
  1450.         // mittente
  1451.         clone.setTipoMittente(this.getTipoMittente()!=null ? new String(this.getTipoMittente()) : null);
  1452.         clone.setIndirizzoMittente(this.getIndirizzoMittente()!=null ? new String(this.getIndirizzoMittente()) : null);
  1453.         clone.setMittente(this.getMittente()!=null ? new String(this.getMittente()) : null);
  1454.         clone.setIdentificativoPortaMittente(this.getIdentificativoPortaMittente()!=null ? new String(this.getIdentificativoPortaMittente()) : null);

  1455.         // destinatario
  1456.         clone.setTipoDestinatario(this.getTipoDestinatario()!=null ? new String(this.getTipoDestinatario()) : null);
  1457.         clone.setIndirizzoDestinatario(this.getIndirizzoDestinatario()!=null ? new String(this.getIndirizzoDestinatario()) : null);
  1458.         clone.setDestinatario(this.getDestinatario()!=null ? new String(this.getDestinatario()) : null);
  1459.         clone.setIdentificativoPortaDestinatario(this.getIdentificativoPortaDestinatario()!=null ? new String(this.getIdentificativoPortaDestinatario()) : null);
  1460.        
  1461.         // profilo di collaborazione
  1462.         clone.setProfiloDiCollaborazione(this.getProfiloDiCollaborazione());
  1463.         clone.setProfiloDiCollaborazioneValue(this.getProfiloDiCollaborazioneValue()!=null ? new String(this.getProfiloDiCollaborazioneValue()) : null);
  1464.         clone.setServizioCorrelato(this.getServizioCorrelato()!=null ? new String(this.getServizioCorrelato()) : null);
  1465.         clone.setTipoServizioCorrelato(this.getTipoServizioCorrelato()!=null ? new String(this.getTipoServizioCorrelato()) : null);
  1466.        
  1467.         // collaborazione
  1468.         clone.setCollaborazione(this.getCollaborazione()!=null ? new String(this.getCollaborazione()) : null);
  1469.        
  1470.         // servizio
  1471.         clone.setServizio(this.getServizio()!=null ? new String(this.getServizio()) : null);
  1472.         clone.setTipoServizio(this.getTipoServizio()!=null ? new String(this.getTipoServizio()) : null);
  1473.         if(this.getVersioneServizio()!=null) {
  1474.             clone.setVersioneServizio(Integer.valueOf(this.getVersioneServizio()+""));
  1475.         }
  1476.        
  1477.         // servizio [info-richiedente]
  1478.         clone.setServizioRichiedenteBustaDiServizio(this.servizioRichiedenteBustaDiServizio!=null ? new String(this.servizioRichiedenteBustaDiServizio) : null);
  1479.         clone.setTipoServizioRichiedenteBustaDiServizio(this.tipoServizioRichiedenteBustaDiServizio!=null ? new String(this.tipoServizioRichiedenteBustaDiServizio) : null);
  1480.         clone.setVersioneServizioRichiedenteBustaDiServizio(this.versioneServizioRichiedenteBustaDiServizio!=null ? Integer.valueOf(this.versioneServizioRichiedenteBustaDiServizio.intValue()+"") : null);
  1481.        
  1482.         // azione
  1483.         clone.setAzione(this.getAzione()!=null ? new String(this.getAzione()) : null);
  1484.        
  1485.         // azione [info-richiedente]
  1486.         clone.setAzioneRichiedenteBustaDiServizio(this.azioneRichiedenteBustaDiServizio!=null ? new String(this.azioneRichiedenteBustaDiServizio) : null);
  1487.        
  1488.         // identificativi
  1489.         clone.setID(this.getID()!=null ? new String(this.getID()) : null);
  1490.         clone.setRiferimentoMessaggio(this.getRiferimentoMessaggio()!=null ? new String(this.getRiferimentoMessaggio()) : null);
  1491.        
  1492.         // identificativi [info-richiedente]
  1493.         clone.setRiferimentoMsgBustaRichiedenteServizio(this.riferimentoMsgBustaRichiedenteServizio!=null ? new String(this.riferimentoMsgBustaRichiedenteServizio) : null);
  1494.        
  1495.         // date
  1496.         clone.setOraRegistrazione(this.getOraRegistrazione()!=null ? new Date(this.getOraRegistrazione().getTime()) : null);
  1497.         clone.setTipoOraRegistrazione(this.getTipoOraRegistrazione(),
  1498.                 this.getTipoOraRegistrazioneValue()!=null ? new String(this.getTipoOraRegistrazioneValue()) : null);
  1499.         clone.setTipoOraRegistrazioneValue(this.getTipoOraRegistrazioneValue()!=null ? new String(this.getTipoOraRegistrazioneValue()) : null);
  1500.         clone.setScadenza(this.getScadenza()!=null ? new Date(this.getScadenza().getTime()) : null);

  1501.         // profilo di trasmissione
  1502.         clone.setInoltro(this.getInoltro(),
  1503.                 this.getInoltroValue()!=null ? new String(this.getInoltroValue()) : null);
  1504.         clone.setInoltroValue(this.getInoltroValue()!=null ? new String(this.getInoltroValue()) : null);
  1505.         clone.setConfermaRicezione(Boolean.valueOf(this.isConfermaRicezione()+""));
  1506.        
  1507.         // sequenza
  1508.         clone.setSequenza(Long.valueOf(this.getSequenza()+""));
  1509.        
  1510.         // servizi applicativi
  1511.         clone.setServizioApplicativoFruitore(this.getServizioApplicativoFruitore()!=null ? new String(this.getServizioApplicativoFruitore()) : null);
  1512.         clone.setServizioApplicativoErogatore(this.getServizioApplicativoErogatore()!=null ? new String(this.getServizioApplicativoErogatore()) : null);

  1513.         // protocollo
  1514.         clone.setProtocollo(this.getProtocollo()!=null ? new String(this.getProtocollo()) : null);

  1515.         // digest
  1516.         clone.setDigest(this.getDigest()!=null ? new String(this.getDigest()) : null);

  1517.         // properties
  1518.         String[]propertiesNames = this.getPropertiesNames();
  1519.         if(propertiesNames!=null){
  1520.             for (int i = 0; i < propertiesNames.length; i++) {
  1521.                 String key = propertiesNames[i];
  1522.                 String value = this.getProperty(key);
  1523.                 if(key!=null && value!=null){
  1524.                     clone.addProperty(new String(key), new String(value));
  1525.                 }
  1526.             }
  1527.         }

  1528.         // ListaEccezioni
  1529.         for(int i=0; i<this.sizeListaEccezioni(); i++){
  1530.             clone.addEccezione(this.getEccezione(i).newInstance());
  1531.         }
  1532.        
  1533.         // ListaRiscontri
  1534.         for(int i=0; i<this.sizeListaRiscontri(); i++){
  1535.             clone.addRiscontro(this.getRiscontro(i).newInstance());
  1536.         }
  1537.        
  1538.         // ListaTrasmissioni
  1539.         for(int i=0; i<this.sizeListaTrasmissioni(); i++){
  1540.             clone.addTrasmissione(this.getTrasmissione(i).newInstance());
  1541.         }



  1542.         return clone;
  1543.     }

  1544. }