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    private final String password;
044
045    public Destroy(Destroy other) {
046        this(other.jid, other.password, other.reason);
047    }
048
049    public Destroy(EntityBareJid alternativeJid, String reason) {
050        this.jid = alternativeJid;
051        this.reason = reason;
052        this.password = null;
053    }
054
055    public Destroy(EntityBareJid alternativeJid, String password, String reason) {
056        this.jid = alternativeJid;
057        this.password = password;
058        this.reason = reason;
059    }
060
061    /**
062     * Returns the JID of an alternate location since the current room is being destroyed.
063     *
064     * @return the JID of an alternate location.
065     */
066    public EntityBareJid getJid() {
067        return jid;
068    }
069
070    /**
071     * Returns the password of the alternate location.
072     *
073     * @return the password of the alternate location.
074     */
075    public String getPassword() {
076        return password;
077    }
078
079    /**
080     * Returns the reason for the room destruction.
081     *
082     * @return the reason for the room destruction.
083     */
084    public String getReason() {
085        return reason;
086    }
087
088    @Override
089    public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
090        XmlStringBuilder xml = new XmlStringBuilder(this);
091        xml.optAttribute("jid", getJid());
092        xml.rightAngleBracket();
093        xml.optElement("password", getPassword());
094        xml.optElement("reason", getReason());
095        xml.closeElement(this);
096        return xml;
097    }
098
099    @Override
100    public String getElementName() {
101        return ELEMENT;
102    }
103
104    @Override
105    public Destroy clone() {
106        return new Destroy(this);
107    }
108}