IDServizioApplicativo.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.core.id;

  21. import java.io.Serializable;

  22. import org.openspcoop2.utils.Utilities;

  23. /**
  24.  * Classe utilizzata per rappresentare un identificatore di un Servizio Applicativo nella configurazione
  25.  *
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author Nardi Lorenzo (nardi@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */

  32. public class IDServizioApplicativo implements Serializable, Cloneable {

  33.     /**
  34.      *
  35.      */
  36.     private static final long serialVersionUID = 1L;

  37.     protected IDSoggetto idSoggettoProprietario;

  38.     protected String nome;
  39.    
  40.    
  41.     public IDSoggetto getIdSoggettoProprietario() {
  42.         return this.idSoggettoProprietario;
  43.     }
  44.     public void setIdSoggettoProprietario(IDSoggetto idSoggettoProprietario) {
  45.         this.idSoggettoProprietario = idSoggettoProprietario;
  46.     }
  47.     public String getNome() {
  48.         return this.nome;
  49.     }
  50.     public void setNome(String nome) {
  51.         this.nome = nome;
  52.     }

  53.     @Override
  54.     public String toString(){
  55.         StringBuilder bf = new StringBuilder();
  56.         if(this.nome!=null)
  57.             bf.append("Nome:"+this.nome);
  58.         else
  59.             bf.append("Nome:NonDefinito");
  60.         bf.append(" ");
  61.         if(this.idSoggettoProprietario!=null)
  62.             bf.append("Soggetto:"+this.idSoggettoProprietario.toString());
  63.         else
  64.             bf.append("Soggetto:NonDefinito");
  65.         return bf.toString();
  66.     }
  67.    
  68.     @Override
  69.     public boolean equals(Object object){
  70.         if(object == null)
  71.             return false;
  72.         if(!Utilities.equalsClass(object,this))
  73.             return false;
  74.         IDServizioApplicativo id = (IDServizioApplicativo) object;
  75.        
  76.         if(this.nome==null){
  77.             if(id.nome!=null)
  78.                 return false;
  79.         }else{
  80.             if(this.nome.equals(id.nome)==false)
  81.                 return false;
  82.         }

  83.         if(this.idSoggettoProprietario==null){
  84.             if(id.idSoggettoProprietario!=null)
  85.                 return false;
  86.         }else{
  87.             if(this.idSoggettoProprietario.equals(id.idSoggettoProprietario)==false)
  88.                 return false;
  89.         }
  90.        
  91.         return true;
  92.     }
  93.    
  94.     // Utile per usare l'oggetto in hashtable come chiave
  95.     @Override
  96.     public int hashCode(){
  97.         return this.toString().hashCode();
  98.     }
  99.    
  100.     @Override
  101.     public IDServizioApplicativo clone(){
  102.        
  103.         IDServizioApplicativo clone = null;
  104.         try {
  105.             clone = (IDServizioApplicativo) super.clone();
  106.         }catch(Throwable t) {
  107.             clone = new IDServizioApplicativo();
  108.         }
  109.         if(this.nome!=null){
  110.             clone.nome = new String(this.nome);
  111.         }
  112.         if(this.idSoggettoProprietario!=null){
  113.             clone.idSoggettoProprietario = this.idSoggettoProprietario.clone();
  114.         }
  115.         return clone;
  116.     }  
  117.    
  118.     public String toFormatString(){
  119.         StringBuilder sb = new StringBuilder();
  120.         sb.append(this.idSoggettoProprietario.getTipo());
  121.         sb.append("/");
  122.         sb.append(this.idSoggettoProprietario.getNome());
  123.         sb.append("/");
  124.         sb.append(this.nome);
  125.         return sb.toString();
  126.     }
  127.    
  128.     public static IDServizioApplicativo toIDServizioApplicativo(String formatString) throws Exception {
  129.         String [] tmp = formatString.split("/");
  130.         if(tmp.length!=3) {
  131.             throw new Exception("Formato non supportato, attesi 3 valori, trovati "+tmp.length);
  132.         }
  133.         String tipoSoggettoErogatore = tmp[0];
  134.         String nomeSoggettoErogatore = tmp[1];
  135.         String nome = tmp[2];
  136.         IDServizioApplicativo idServizioApplicativo = new IDServizioApplicativo();
  137.         idServizioApplicativo.idSoggettoProprietario = new IDSoggetto(tipoSoggettoErogatore, nomeSoggettoErogatore);
  138.         idServizioApplicativo.nome=nome;
  139.         return idServizioApplicativo;
  140.     }
  141. }