001/**
002 *
003 * Copyright 2003-2007 Jive Software, 2014 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.smackx.muc.packet;
018
019import java.io.Serializable;
020
021import org.jivesoftware.smack.packet.NamedElement;
022import org.jivesoftware.smack.util.XmlStringBuilder;
023
024import org.jxmpp.jid.EntityBareJid;
025
026/**
027 * Represents a request to the server to destroy a room. The sender of the request should be the
028 * room's owner. If the sender of the destroy request is not the room's owner then the server will
029 * answer a "Forbidden" error.
030 *
031 * @author Gaston Dombiak
032 */
033public class Destroy implements NamedElement, Serializable {
034    /**
035     *
036     */
037    private static final long serialVersionUID = 1L;
038
039    public static final String ELEMENT = "destroy";
040
041    private final String reason;
042    private final EntityBareJid jid;
043
044    public Destroy(Destroy other) {
045        this(other.jid, other.reason);
046    }
047
048    public Destroy(EntityBareJid alternativeJid, String reason) {
049        this.jid = alternativeJid;
050        this.reason = reason;
051    }
052
053    /**
054     * Returns the JID of an alternate location since the current room is being destroyed.
055     *
056     * @return the JID of an alternate location.
057     */
058    public EntityBareJid getJid() {
059        return jid;
060    }
061
062    /**
063     * Returns the reason for the room destruction.
064     *
065     * @return the reason for the room destruction.
066     */
067    public String getReason() {
068        return reason;
069    }
070
071    @Override
072    public XmlStringBuilder toXML(String enclosingNamespace) {
073        XmlStringBuilder xml = new XmlStringBuilder(this);
074        xml.optAttribute("jid", getJid());
075        xml.rightAngleBracket();
076        xml.optElement("reason", getReason());
077        xml.closeElement(this);
078        return xml;
079    }
080
081    @Override
082    public String getElementName() {
083        return ELEMENT;
084    }
085
086    @Override
087    public Destroy clone() {
088        return new Destroy(this);
089    }
090}