Message.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.logger.beans;

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

  25. import org.openspcoop2.utils.logger.constants.MessageType;

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

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

  38.     private MessageType type;
  39.    
  40.     private String contentType;
  41.    
  42.     private byte[] content;
  43.    
  44.     private String idTransaction;
  45.    
  46.     private String idMessage;
  47.    
  48.     private String idOperation;
  49.    
  50.     private String idServer;
  51.    
  52.     private List<Attachment> attachments = new ArrayList<Attachment>();
  53.    
  54.     private List<String> _headers_position = new ArrayList<>();
  55.     private Map<String,Property> headers = new java.util.HashMap<String,Property>();
  56.    
  57.     private List<String> _resources_position = new ArrayList<>();
  58.     private Map<String,Property> resources = new java.util.HashMap<String,Property>();
  59.    
  60.    
  61.     public String getContentType() {
  62.         return this.contentType;
  63.     }

  64.     public void setContentType(String contentType) {
  65.         this.contentType = contentType;
  66.     }

  67.     public byte[] getContent() {
  68.         return this.content;
  69.     }

  70.     public void setContent(byte[] content) {
  71.         this.content = content;
  72.     }
  73.    
  74.     public List<Attachment> getAttachments() {
  75.         return this.attachments;
  76.     }
  77.    
  78.     public void addAttachment(Attachment attachment){
  79.         this.attachments.add(attachment);
  80.     }
  81.    
  82.     public Attachment getAttachment(int index){
  83.         return this.attachments.get(index);
  84.     }
  85.    
  86.     public Attachment removeAttachment(int index){
  87.         return this.attachments.remove(index);
  88.     }
  89.    
  90.     public int sizeAttachments(){
  91.         return this.attachments.size();
  92.     }
  93.    
  94.     public void clearAttachments(){
  95.         this.attachments.clear();
  96.     }
  97.    
  98.    
  99.     public Map<String,Property> getHeaders() {
  100.         return this.headers;
  101.     }
  102.     public List<Property> getHeadersAsList() {
  103.         List<Property> l = new ArrayList<Property>();
  104.         for (String key : this._headers_position) {
  105.             l.add(this.headers.get(key));
  106.         }
  107.         return l;
  108.     }
  109.    
  110.     public void addHeader(Property property){
  111.         this.headers.put(property.getName(),property);
  112.         this._headers_position.add(property.getName());
  113.     }
  114.    
  115.     public Property getHeader(String key){
  116.         return this.headers.get(key);
  117.     }
  118.    
  119.     public Property removeHeader(String key){
  120.         int index = -1;
  121.         for (int i = 0; i < this._headers_position.size(); i++) {
  122.             if(key.equals(this._headers_position.get(i))){
  123.                 index = i;
  124.                 break;
  125.             }
  126.         }
  127.         this._headers_position.remove(index);
  128.         return this.headers.remove(key);
  129.     }
  130.    
  131.     public Property getHeader(int index){
  132.         return this.getHeadersAsList().get(index);
  133.     }
  134.    
  135.     public Property removeHeader(int index){
  136.         Property p = this.getHeadersAsList().get(index);
  137.         this.headers.remove(p.getName());
  138.         return p;
  139.     }
  140.    
  141.     public int sizeHeaders(){
  142.         return this.headers.size();
  143.     }
  144.    
  145.     public void clearHeaders(){
  146.         this.headers.clear();
  147.     }
  148.    
  149.    
  150.    
  151.    
  152.    
  153.     public Map<String,Property> getResources() {
  154.         return this.resources;
  155.     }
  156.     public List<Property> getResourcesAsList() {
  157.         List<Property> l = new ArrayList<Property>();
  158.         for (String key : this._resources_position) {
  159.             l.add(this.resources.get(key));
  160.         }
  161.         return l;
  162.     }
  163.    
  164.     public void addResource(Property property){
  165.         this.resources.put(property.getName(),property);
  166.         this._resources_position.add(property.getName());
  167.     }
  168.    
  169.     public Property getResource(String key){
  170.         return this.resources.get(key);
  171.     }
  172.    
  173.     public Property removeResource(String key){
  174.         int index = -1;
  175.         for (int i = 0; i < this._resources_position.size(); i++) {
  176.             if(key.equals(this._resources_position.get(i))){
  177.                 index = i;
  178.                 break;
  179.             }
  180.         }
  181.         this._resources_position.remove(index);
  182.         return this.resources.remove(key);
  183.     }
  184.    
  185.     public Property getResource(int index){
  186.         return this.getResourcesAsList().get(index);
  187.     }
  188.    
  189.     public Property removeResource(int index){
  190.         Property p = this.getResourcesAsList().get(index);
  191.         this.resources.remove(p.getName());
  192.         return p;
  193.     }
  194.    
  195.     public int sizeResources(){
  196.         return this.resources.size();
  197.     }
  198.    
  199.     public void clearResources(){
  200.         this.resources.clear();
  201.     }
  202.    
  203.    
  204.     public MessageType getType() {
  205.         return this.type;
  206.     }

  207.     public void setType(MessageType type) {
  208.         this.type = type;
  209.     }
  210.    
  211.     public String getIdTransaction() {
  212.         return this.idTransaction;
  213.     }

  214.     public void setIdTransaction(String idTransaction) {
  215.         this.idTransaction = idTransaction;
  216.     }
  217.    
  218.     public String getIdMessage() {
  219.         return this.idMessage;
  220.     }

  221.     public void setIdMessage(String idMessage) {
  222.         this.idMessage = idMessage;
  223.     }

  224.     public String getIdServer() {
  225.         return this.idServer;
  226.     }

  227.     public void setIdServer(String idServer) {
  228.         this.idServer = idServer;
  229.     }
  230.    
  231.     public String getIdOperation() {
  232.         return this.idOperation;
  233.     }

  234.     public void setIdOperation(String idOperation) {
  235.         this.idOperation = idOperation;
  236.     }
  237. }