001/**
002 *
003 * Copyright 2018 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.compress.packet;
018
019import java.util.Objects;
020
021import org.jivesoftware.smack.packet.Nonza;
022import org.jivesoftware.smack.packet.StanzaError;
023import org.jivesoftware.smack.util.XmlStringBuilder;
024
025public class Failure implements Nonza {
026
027    public static final String ELEMENT = "failure";
028    public static final String NAMESPACE = Compress.NAMESPACE;
029
030    public enum CompressFailureError {
031        setup_failed,
032        processing_failed,
033        unsupported_method,
034        ;
035
036        private final String compressFailureError;
037
038        CompressFailureError() {
039            compressFailureError = name().replace('_', '-');
040        }
041
042        @Override
043        public String toString() {
044            return compressFailureError;
045        }
046    }
047
048    private final CompressFailureError compressFailureError;
049    private final StanzaError stanzaError;
050
051    public Failure(CompressFailureError compressFailureError, StanzaError stanzaError) {
052        this.compressFailureError = Objects.requireNonNull(compressFailureError);
053        this.stanzaError = stanzaError;
054    }
055
056    @Override
057    public String getElementName() {
058        return ELEMENT;
059    }
060
061    @Override
062    public String getNamespace() {
063        return NAMESPACE;
064    }
065
066    @Override
067    public XmlStringBuilder toXML(String enclosingNamespace) {
068        XmlStringBuilder xml = new XmlStringBuilder(this);
069
070        return xml;
071    }
072}