RestMediaTypeCollection.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.config;

  21. import java.io.Serializable;

  22. import org.openspcoop2.message.constants.MessageType;
  23. import org.openspcoop2.message.exception.MessageException;

  24. /**
  25.  * RestMediaTypeCollection
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class RestMediaTypeCollection extends AbstractMediaTypeCollection implements Serializable {

  32.     /**
  33.      *
  34.      */
  35.     private static final long serialVersionUID = 1L;
  36.    
  37.    
  38.     private RestBinding binding;
  39.    
  40.     public RestMediaTypeCollection(RestBinding binding){
  41.         this.binding = binding;
  42.     }
  43.    
  44.     private void checkVersion(MessageType version) throws MessageException{
  45.         if(MessageType.XML.equals(version)){
  46.             if(!this.binding.isBinding_xml()){
  47.                 throw new MessageException("MessageType ["+version+"] not supported in RestBinding; Xml disabled");
  48.             }
  49.         }
  50.         else if(MessageType.JSON.equals(version)){
  51.             if(!this.binding.isBinding_json()){
  52.                 throw new MessageException("MessageType ["+version+"] not supported in RestBinding; Json disabled");
  53.             }
  54.         }
  55.         else if(MessageType.BINARY.equals(version)){
  56.             if(!this.binding.isBinding_binary()){
  57.                 throw new MessageException("MessageType ["+version+"] not supported in RestBinding; Binary disabled");
  58.             }
  59.         }
  60.         else if(MessageType.MIME_MULTIPART.equals(version)){
  61.             if(!this.binding.isBinding_mimeMultipart()){
  62.                 throw new MessageException("MessageType ["+version+"] not supported in RestBinding; MimeMultipart disabled");
  63.             }
  64.         }
  65.         else{
  66.             throw new MessageException("MessageType ["+version+"] not supported in RestBinding");
  67.         }
  68.     }
  69.    
  70.     @Override
  71.     public void addDefaultMediaType(MessageType version) throws MessageException{
  72.         this.checkVersion(version);
  73.         super.addDefaultMediaType(version);
  74.     }
  75.     @Override
  76.     public void addUndefinedMediaType(MessageType version) throws MessageException{
  77.         this.checkVersion(version);
  78.         super.addUndefinedMediaType(version);
  79.     }
  80.     @Override
  81.     public void addMediaType(String mediaType,MessageType version,boolean regExpr) throws MessageException{
  82.         this.checkVersion(version);
  83.         super.addMediaType(mediaType, version, regExpr);
  84.     }
  85.    
  86. }