ExtendedTransactionInfo.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.pdd.core.handlers;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;

  26. /**
  27.  * ExtendedTransactionInfo
  28.  *
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class ExtendedTransactionInfo implements Serializable {

  35.     /**
  36.      *
  37.      */
  38.     private static final long serialVersionUID = 1L;
  39.     private List<String> keys = new ArrayList<>();
  40.     private Map<String, String> mapKeyToValue = new HashMap<>();
  41.    
  42.     public void addCustomKey(String key,String value){
  43.         this.keys.add(key);
  44.         this.mapKeyToValue.put(key, value);
  45.     }
  46.    
  47.     public String getValue(String key) throws Exception{
  48.         if(this.mapKeyToValue.containsKey(key)==false){
  49.             throw new Exception("Key ["+key+"] not exists");
  50.         }
  51.         return this.mapKeyToValue.get(key);
  52.     }
  53.    
  54.     public List<String> keys(){
  55.         return this.keys;
  56.     }
  57.    
  58.     public void deleteKey(String key){
  59.         int delete = -1;
  60.         for (int i = 0; i < this.keys.size(); i++) {
  61.             String keyCheck = this.keys.get(i);
  62.             if(keyCheck.equals(key)){
  63.                 delete = i;
  64.                 break;
  65.             }
  66.         }
  67.         if(delete>=0){
  68.             this.keys.remove(delete);
  69.         }
  70.         this.mapKeyToValue.remove(key);
  71.     }
  72.    
  73. }