SOAPFaultCode.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.soap;

  21. import java.io.Serializable;

  22. import javax.xml.namespace.QName;

  23. import org.openspcoop2.message.constants.Costanti;
  24. import org.openspcoop2.message.constants.MessageType;
  25. import org.openspcoop2.message.exception.MessageException;
  26. import org.openspcoop2.message.exception.MessageNotSupportedException;

  27. /**
  28.  * SOAPFaultCode
  29.  *
  30.  *
  31.  * @author Nardi Lorenzo (nardi@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */

  35. public enum SOAPFaultCode implements Serializable {
  36.     DataEncodingUnknown, MustUnderstand, Receiver, Sender, VersionMismatch;
  37.    
  38.     public QName toQName(MessageType messageType,String prefix) throws MessageException,MessageNotSupportedException{
  39.         String namespace = SoapUtils.getSoapEnvelopeNS(messageType);
  40.         if(prefix!=null)
  41.             return new QName(namespace, this.toString(messageType), prefix);
  42.         else
  43.             return new QName(namespace, this.toString(messageType));
  44.     }

  45.     public String toString(MessageType messageType) throws MessageException {
  46.        
  47.         if(!MessageType.SOAP_11.equals(messageType) && !MessageType.SOAP_12.equals(messageType)){
  48.             throw new MessageException("Require SOAP Message Type, found "+messageType+" Type");
  49.         }
  50.        
  51.         switch (this) {
  52.         case DataEncodingUnknown:
  53.             return "DataEncodingUnknown";
  54.         case MustUnderstand:
  55.             return "MustUnderstand";
  56.         case Receiver:
  57.             return messageType.equals(MessageType.SOAP_11) ? Costanti.SOAP11_FAULT_CODE_SERVER : Costanti.SOAP12_FAULT_CODE_SERVER;
  58.         case Sender:
  59.             return messageType.equals(MessageType.SOAP_11) ? Costanti.SOAP11_FAULT_CODE_CLIENT : Costanti.SOAP12_FAULT_CODE_CLIENT;
  60.         case VersionMismatch:
  61.             return "VersionMismatch";
  62.         default:
  63.             return messageType.equals(MessageType.SOAP_11) ? Costanti.SOAP11_FAULT_CODE_SERVER : Costanti.SOAP12_FAULT_CODE_SERVER;
  64.         }
  65.     }
  66. }