MessageType.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.message.constants;

  21. import java.io.Serializable;

  22. /**
  23.  * MessageType
  24.  *
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public enum MessageType implements Serializable {
  31.    
  32.     SOAP_11, SOAP_12, XML, JSON, BINARY, MIME_MULTIPART;

  33.    
  34.     // Generic Utilities
  35.    
  36.     private static final String LABEL_SOAP_11 = "Soap-1.1";
  37.     private static final String LABEL_SOAP_12 = "Soap-1.2";
  38.     private static final String LABEL_XML = "Xml";
  39.     private static final String LABEL_JSON = "Json";
  40.     private static final String LABEL_BINARY = "Binary";
  41.     private static final String LABEL_MIME_MULTIPART = "MIME-Multipart";
  42.    
  43.     public String getMessageVersionAsString(){
  44.         switch (this) {
  45.             case SOAP_11:
  46.                 return LABEL_SOAP_11;
  47.             case SOAP_12:
  48.                 return LABEL_SOAP_12;
  49.             case XML:
  50.                 return LABEL_XML;
  51.             case JSON:
  52.                 return LABEL_JSON;
  53.             case BINARY:
  54.                 return LABEL_BINARY;
  55.             case MIME_MULTIPART:
  56.                 return LABEL_MIME_MULTIPART;
  57.             default:
  58.                 throw new RuntimeException("Unsupported-Type");
  59.         }
  60.     }
  61.     public String getLabelMessageVersion(){
  62.         return this.getMessageVersionAsString();
  63.     }
  64.    
  65.     public static MessageType getMessageTypeFromLabel(String v) {
  66.         if(v==null) {
  67.             return null;
  68.         }
  69.         if(LABEL_SOAP_11.equals(v)) {
  70.             return MessageType.SOAP_11;
  71.         }
  72.         else if(LABEL_SOAP_12.equals(v)) {
  73.             return MessageType.SOAP_12;
  74.         }
  75.         else if(LABEL_XML.equals(v)) {
  76.             return MessageType.XML;
  77.         }
  78.         else if(LABEL_JSON.equals(v)) {
  79.             return MessageType.JSON;
  80.         }
  81.         else if(LABEL_BINARY.equals(v)) {
  82.             return MessageType.BINARY;
  83.         }
  84.         else if(LABEL_MIME_MULTIPART.equals(v)) {
  85.             return MessageType.MIME_MULTIPART;
  86.         }
  87.         return null;
  88.     }
  89.    
  90. }