BlackListElement.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.utils.beans;

  21. import java.io.Serializable;


  22. /*****
  23.  *
  24.  * Oggetto che identifica un metodo setter da non richiamare durante la copia delle properties tra due bean.
  25.  *
  26.  * Le informazioni necessarie sono:
  27.  *
  28.  *
  29.  * Nome metodo setter da scartare;
  30.  *
  31.  * Elenco dei tipi dei parametri del metodo;
  32.  *
  33.  *
  34.  * @author Pintori Giuliano (pintori@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  *
  38.  */
  39. public class BlackListElement implements Serializable {

  40.     /**
  41.      *
  42.      */
  43.     private static final long serialVersionUID = 1L;

  44.     private String nomeMetodo;

  45.     private Class<?>[] classiParametri;

  46.     public BlackListElement(String nome, Class<?>... classes) {
  47.         this.nomeMetodo = nome;
  48.         this.classiParametri = classes;
  49.     }

  50.     public String getNomeMetodo() {
  51.         return this.nomeMetodo;
  52.     }

  53.     public void setNomeMetodo(String nomeMetodo) {
  54.         this.nomeMetodo = nomeMetodo;
  55.     }

  56.     public Class<?>[] getClassiParametri() {
  57.         return this.classiParametri;
  58.     }

  59.     public void setClassiParametri(Class<?>[] classiParametri) {
  60.         this.classiParametri = classiParametri;
  61.     }

  62.    
  63.     /****
  64.      *
  65.      * Override del metodo equals:
  66.      *
  67.      * Realizza il confronto tra due metodi.
  68.      *
  69.      *
  70.      *
  71.      *
  72.      */
  73.     @Override
  74.     public boolean equals(Object obj) {
  75.         if(obj == null){
  76.             return false;
  77.         }
  78.        
  79.         if(!(obj instanceof BlackListElement)){
  80.             return false;
  81.         }
  82.        
  83.         BlackListElement ble = (BlackListElement) obj;
  84.        
  85.         // controllo sul nome (Nome diverso = elemento non uguale)
  86.         if(!this.nomeMetodo.equals(ble.getNomeMetodo())){
  87.             return false;          
  88.         }
  89.        
  90.         // Stesso nome ma elenco dei parametri diverso: return false;
  91.         if(this.classiParametri == null && ble.getClassiParametri() != null){
  92.             return false;
  93.         }
  94.        
  95.         // Stesso nome ma elenco dei parametri diverso: return false;
  96.         if(this.classiParametri != null && ble.getClassiParametri() == null){
  97.             return false;
  98.         }
  99.        
  100.         // Stesso nome ed elenco dei parametri non presente: return true;
  101.         if(this.classiParametri == null && ble.getClassiParametri() == null){
  102.             return true;
  103.         }
  104.        
  105.         //stesso nome ed elenco dei parametri con un diverso numero di elementi: return false;
  106.         int this_length = -1;
  107.         if(this.classiParametri!=null) {
  108.             this_length = this.classiParametri.length;
  109.         }
  110.         int ble_length = -1;
  111.         if(ble.getClassiParametri()!=null) {
  112.             ble_length = ble.getClassiParametri().length;
  113.         }
  114.         if(this_length != ble_length){
  115.             return false;
  116.         }
  117.        
  118.         // assumo che se passa tutti i controlli precedenti i due oggetti abbiano lo stesso esatto numero di parametri.
  119.         if(this.classiParametri!=null) {
  120.             for (int i = 0; i < this.classiParametri.length; i++) {
  121.                 Class<?> _class = this.classiParametri[i];
  122.                 Class<?> bleClass = ble.getClassiParametri()[i];
  123.                
  124.                 // quando trovo la prima discordanza nell'elenco dei parametri mi fermo: return false;
  125.                 //if(!_class.getName().equals(bleClass.getName())){
  126.                 if(!_class.equals(bleClass)){
  127.                     return false;
  128.                 }
  129.             }
  130.         }
  131.        
  132.         return true;
  133.     }

  134.     @Override
  135.     public int hashCode() {
  136.         return super.hashCode();
  137.     }
  138. }