package eu.osci;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPConstants;

import eu.osci.messagetypes.OSCIMessage;


/**
 * This class represents the defined SOAP faults in the OSCI 2 context. For the details of each OSCI SOAP
 * fault see the OSCI 2 specification.<br>
 * Copyright © 2010 Freie Hansestadt Bremen. <br>
 * Created by bremen online services Entwicklungs- und Betriebsgesellschaft mbH & Co. KG. <br>
 * This library (Starter Kit) can be used by anybody according to the Bremer Lizenz für freie
 * Softwarebibliotheken. The license terms can be viewed at www.osci.de or can be ordered at the
 * OSCI-Leitstelle (Die Senatorin für Finanzen, Freie Hansestadt Bremen, Postfach 10 15 40, 28015 Bremen).
 * 
 * @author R. Lindemann
 */

public enum OSCIFault
{
  PROCESSING_EXCEPTION(true, "ProcessingException"),
  ADDR_WRONG_TYPE_OF_BUSINESS_SCENARIO(false, "AddrWrongTypeOfBusinessScenario"),
  ADDR_WRONG_ACTION_URI(false, "AddrWrongActionURI"),
  AUTHN_CERT_NOT_VALID(false, "AuthnCertNotValid"),
  AUTHN_CERT_INVALID_KEY_USAGE(false, "AuthnCertInvalidKeyUsage"),
  AUTHN_SECURITY_LEVEL_INSUFFICIENT(false, "AuthnSecurityLevelInsufficient"),
  AUTHN_TOKEN_FORMAL_MISMATCH(false, "AuthnTokenFormalMismatch"),
  MSGBOX_REQUEST_WRONG_REFERENCE(false, "MsgBoxRequestWrongReference"),
  QUAL_TSP_SERVICE_NOT_AVAILABLE(false, "QualTSPServiceNotAvailable"),
  MSG_BODY_DECRYPTION_ERROR(false, "MsgBodyDecryptionError"),
  SIGNATURE_OF_RECEIPT_INVALID(false, "SignatureOfReceiptInvalid"),
  SIGNATURE_OF_VALIDATE_RESULT_INVALID(false, "SignatureOfValidateResultInvalid"),
  MSG_HEADER_STRUCTURE_SCHEMA_VIOLATION(false, "MsgHeaderStructureSchemaViolation"),
  MSG_SIZE_LIMIT_EXCEEDED(false, "MsgSizeLimitExceeded"),
  MSG_FREQUENCY_LIMIT_EXCEEDED(false, "MsgFrequencyLimitExceeded,"),
  ENCRYPTION_CERT_NOT_VALID(false, "EncryptionCertNotValid"),
  INVALID_RESPONSE_MESSAGE(true, "InvalidResponseMessage"),
  DELIVERY_RECEIPT_CHECKSUM_WRONG(true, "DeliveryReceiptChecksumInvalid");

  private OSCIFault(boolean isReceiverFault, String _subCode)
  {
    if (isReceiverFault)
    {
      code = SOAPConstants.SOAP_RECEIVER_FAULT;
    }
    else
    {
      code = SOAPConstants.SOAP_SENDER_FAULT;
    }
    subCode = new QName("osci", _subCode);

  }

  private QName code;

  private QName subCode;


  /**
   * Returns the code of the OSCI SOAP fault.
   */
  public QName getCode()
  {
    return code;
  }

  /**
   * Returns the subcode of the OSCI SOAP fault.
   */
  public QName getSubcode()
  {
    return subCode;
  }

  /**
   * Returns the detailed reason of the OSCI SOAP fault.
   */
  public String getReason()
  {
    return OSCIMessage.text.getString(getSubcode().getLocalPart());
  }

}
