ErroreCooperazione.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.constants;

  21. import java.io.Serializable;

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

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

  31.     private static final long serialVersionUID = 1L;
  32.    
  33.     private String descrizione;
  34.     private CodiceErroreCooperazione codiceErrore;
  35.    
  36.     public ErroreCooperazione(String descrizione,CodiceErroreCooperazione codiceErrore){
  37.         this.descrizione = descrizione;
  38.         this.codiceErrore = codiceErrore;
  39.     }
  40.        
  41.     // metodo senza protocol factory utilizzato dai traduttori
  42.     public String getDescrizioneRawValue() {
  43.         return this.descrizione;
  44.     }
  45.     public String getDescrizione(IProtocolFactory<?> protocolFactory) throws ProtocolException {
  46.         return protocolFactory.createTraduttore().toString(this);
  47.     }
  48.     protected void setDescrizione(String descrizione) {
  49.         this.descrizione = descrizione;
  50.     }

  51.     public CodiceErroreCooperazione getCodiceErrore() {
  52.         return this.codiceErrore;
  53.     }
  54.     protected void setCodiceErrore(CodiceErroreCooperazione codiceErrore) {
  55.         this.codiceErrore = codiceErrore;
  56.     }
  57.    
  58.     @Override
  59.     public String toString(){
  60.         try{
  61.             return toString(null);
  62.         }catch(Exception e){
  63.             throw new RuntimeException(e.getMessage(),e);
  64.         }
  65.     }
  66.     public String toString(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  67.         StringBuilder bf = new StringBuilder();
  68.        
  69.         if(this.descrizione!=null){
  70.             bf.append(" descrizione errore: ");
  71.             if(protocolFactory==null)
  72.                 bf.append(this.getDescrizioneRawValue());
  73.             else
  74.                 bf.append(this.getDescrizione(protocolFactory));
  75.         }
  76.        
  77.         if(this.codiceErrore!=null){
  78.             bf.append(" codice errore: ");
  79.             if(protocolFactory==null)
  80.                 bf.append(this.codiceErrore.toString());
  81.             else
  82.                 bf.append(protocolFactory.createTraduttore().toString(this.codiceErrore));
  83.         }
  84.        
  85.         if(bf.length()>0)
  86.             return bf.toString().substring(1);
  87.         else
  88.             return null;
  89.     }
  90.    
  91.     @Override
  92.     public ErroreCooperazione clone(){
  93.         ErroreCooperazione err =
  94.                 new ErroreCooperazione( (this.descrizione!=null ? new String(this.descrizione) : null) , this.codiceErrore);
  95.         return err;
  96.     }
  97. }